473,574 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

logging data truncated

32 New Member
Hi,

I have to below script,
and everything seems to work except
that if I entered the Primary IP and Secondaries IP, with such
number; 10.100.1.11 or 10.10.10.245 the last numbers of my IP are missing
in my logs file (c:/tmp/myprimarylogs.x ls) Here is the result, you see, '10.100.1.1 should be 10.100.1.11
and 10.10.10.2 should be 10.10.10.224 how can I resolve this issue ?

and I need to know How to add the time : time.asctime() beside my IP on below logs ?

is this possible to put every result with a proper column in Excel file (myprimarylogs. xls) as these result are not properly separate all the purcentage will be on column A, all the IP in column B and time in column C.

Expand|Select|Wrap|Line Numbers
  1.  
  2. 10 %'10.10.1.1'
  3. 10 %'10.10.1.1'
  4. 20% '10.10.10.2'
  5.  
  6.  
Here is my code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import re
  3. import time 
  4. import thread 
  5. import os
  6. import sys
  7.  
  8. f=open('c:/tmp/primaryip.xls','w')
  9. f.close()
  10.  
  11. g=open('c:/tmp/workfile.txt','w')
  12. g.close()
  13.  
  14. h=open('c:/tmp/myprimarylogs.txt','w')
  15. h.close()
  16.  
  17. j=open('c:/tmp/secip.xls','w')
  18. j.close()
  19.  
  20. def validIP(ipAdd): 
  21.     ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" 
  22.     re_ip = re.compile(ipRegex) 
  23.     return re_ip.match(ipAdd)
  24.  
  25. def validIP1(ipAdd1): 
  26.     ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" 
  27.     re_ip = re.compile(ipRegex) 
  28.     return re_ip.match(ipAdd1)
  29.  
  30. def fil(data):
  31.     patt = re.compile(r'\((\d+)% loss\)')
  32.     patt1 = re.compile(r'(\d+.\d+.\d+.\d)')
  33.     line = str(loss_num) + tab + str(ip) + tab + str(out_time) + '\n' 
  34.     for line in data.split('\n'):
  35.  
  36.         if line.startswith("Ping statistics for"):
  37.             ip = patt1.search(line).group(1)
  38.  
  39.         if patt.search(line):
  40.             loss_num = int(patt.search(line).group(1))
  41.  
  42.             if loss_num >= 2 :
  43.                 s = open('c:/tmp/myprimarylogs.txt', 'a+')
  44.                 s.write("%s '%s'\n" % (loss_num, ip))
  45.                 #s.write("%s '%s'\n" % (loss_num, ip) + time.asctime())
  46.                 s.close()
  47.                 # if loss >= 2, return False - then secondary IPs are pinged
  48.                 print 'loss_num is >= 2 ', loss_num , ip , time.asctime()
  49.                 return False
  50.             else:
  51.                 print 'loss_num is < 2,', loss_num , ip , time.asctime()
  52.                 return True
  53.  
  54. def ping(*fnames):
  55.     g = open(fnames[0], 'w')
  56.     for fn in fnames[1:]:
  57.         f=open(fn, 'r')
  58.         ipList = [line.strip() for line in f.readlines()]
  59.         f.close()
  60.         resList = []
  61.         for ipAdd in ipList:
  62.             pingaling =os.popen("ping %s -n 10" %(ipAdd),"r")
  63.             data = pingaling.read()
  64.             resList.append(data)
  65.             # if loss > 2, ping secondary IPs
  66.             proceed = fil(data)
  67.             if proceed:
  68.                 break       
  69.         g.write('/n'.join(resList))
  70.         if proceed:
  71.             break
  72.     g.close()
  73.  
  74. def get_IPs(fnP, fnS):
  75.     while True:
  76.         ipAddP = raw_input("# Enter Primary IP: ")
  77.         if validIP(ipAddP):
  78.             f = open(fnP, 'w')
  79.             f.write(ipAddP.strip() + "\n")
  80.             f.close()
  81.             break
  82.         else:
  83.             print "Invalid IP."
  84.     ipList = []
  85.     while True:
  86.         while True:
  87.             ipAddS = raw_input("# Enter Secondary IP: ")
  88.             if validIP(ipAddS):
  89.                 ipList.append(ipAddS.strip())
  90.                 break
  91.             else:
  92.                 print "Invalid IP"
  93.         s = raw_input("# Enter another IP? Y/N: " )
  94.         if s.upper() == "N":
  95.             f = open(fnS, 'w')
  96.             f.write('\n'.join(ipList))
  97.             f.close()
  98.             break
  99.  
  100. fnP = 'c:/tmp/primaryip.xls'
  101. fnS = 'c:/tmp/secip.xls'
  102. fnW = 'c:/tmp/workfile.txt'
  103.  
  104. #get_IPs(fnP, fnS)
  105. #ping(fnW, fnP, fnS)
  106.  
  107. def main():
  108.     the_time = time.time()
  109.     start_time = the_time
  110.     end_time = the_time + (60*60)  # 1 hr
  111.     #end_time = the_time + (60*60*24)  # 24 hrs
  112.     get_IPs(fnP, fnS)
  113.     while the_time < end_time:
  114.         ping(fnW, fnP, fnS)
  115.         time.sleep(10)    # wait 60 seconds
  116.         the_time = time.time() # get the new time
  117.  
  118.  
  119. if __name__ == "__main__":
  120.     main()
  121.  
Oct 30 '07 #1
10 2441
bartonc
6,596 Recognized Expert Expert
It's the regex that you are using in the logging routine:
Expand|Select|Wrap|Line Numbers
  1. >>> patt1 = re.compile(r'(\d+.\d+.\d+.\d)')
  2. >>> m = patt1.match('2.192.100.100')
  3. >>> m.group(1)
  4. '2.192.100.1'
  5. >>> 
Oct 31 '07 #2
Charlie of Bolton
32 New Member
Hi Bartonc,

thanks did changed the syntaxe now it is ok.

a)I would like to add the time to my logs( SEE line 15 and 16), I did tried
several combinaisons but does not seems to work

b)And how can I add the different type of data within a different column, in this case all my data goes into column A but I want it : A = purcentage, B=IPss, C = time within Excel spreadsheet ?


Expand|Select|Wrap|Line Numbers
  1.  
  2. def fil(data):
  3.     patt = re.compile(r'\((\d+)% loss\)')
  4.     patt1 = re.compile(r'(\d+.\d+.\d+.\d+)')
  5.     #line = str(loss_num) + tab + str(ip) + tab + str(out_time) + '\n' 
  6.     for line in data.split('\n'):
  7.  
  8.         if line.startswith("Ping statistics for"):
  9.             ip = patt1.search(line).group(1)
  10.  
  11.         if patt.search(line):
  12.             loss_num = int(patt.search(line).group(1))
  13.  
  14.             if loss_num >= 2 :
  15.                 s = open('c:/tmp/myprimarylogs.txt', 'a+')
  16.                 t = time.asctime()
  17.                 s.write("%s '%s'\n" % (loss_num, ip)), t
  18.                 #s.write("%s '%s'\n" % (loss_num, ip) + time.asctime())
  19.                 s.close()
  20.                 # if loss >= 2, return False - then secondary IPs are pinged
  21.                 print 'Packets loss are >= 2 ', loss_num , ip , time.asctime()
  22.                 return False
  23.             else:
  24.                 print 'Packets loss are < 2,', loss_num , ip , time.asctime()
  25.                 return True
  26.  
  27.  
Nov 2 '07 #3
Charlie of Bolton
32 New Member
Hi,

Is someone can help me ?

Brgds/Charlie
Nov 2 '07 #4
Charlie of Bolton
32 New Member
Hi Bartonc,

forget my last question regarding the time,
I found it too.

But need to know, how can I separte my data to different column in Excel
ei: column A = purcentage, B= IP address, C= Time ?
Nov 2 '07 #5
bartonc
6,596 Recognized Expert Expert
I think the answer to both the time question and the columns in Excel can be found here, in a tab separated values string:
Expand|Select|Wrap|Line Numbers
  1. s.write("%s\t'%s'\t%s\n" % (loss_num, ip, t)) # move the ,t inside the string format parens
Nov 2 '07 #6
Charlie of Bolton
32 New Member
Hi, I will try your suggestion later.

Bartonc,

According the my script provide to you on this page,
Do you have any idea on why the script does not provide
The ping from my 5th IP below.

the script only ping 4 IPs instead of 5, the
last ip entered: 2.3.6.8 is not pinged at all.

Expand|Select|Wrap|Line Numbers
  1. # Enter Primary IP: 11.11.11.11
  2. # Enter Secondary IP: 10.20.0.246
  3. # Enter another IP? Y/N: y
  4. # Enter Secondary IP: 1.2.3.4
  5. # Enter another IP? Y/N: y
  6. # Enter Secondary IP: 10.20.3.173
  7. # Enter another IP? Y/N: y
  8. # Enter Secondary IP: 2.3.6.8
  9. # Enter another IP? Y/N: n
  10. Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:02:12 2007
  11. Packets loss are > 2: 12 10.20.0.246 Tue Nov 06 13:03:13 2007
  12. Packets loss are > 2: 100 1.2.3.4 Tue Nov 06 13:06:52 2007
  13. Packets loss are < 2 0 10.20.3.173 Tue Nov 06 13:07:32 2007
  14. Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:11:21 2007
  15. Packets loss are > 2: 10 10.20.0.246 Tue Nov 06 13:12:18 2007
  16. Packets loss are > 2: 100 1.2.3.4 Tue Nov 06 13:15:57 2007
  17. Packets loss are < 2 0 10.20.3.173 Tue Nov 06 13:16:36 2007
  18. Packets loss are > 2: 100 11.11.11.11 Tue Nov 06 13:20:25 2007
  19.  
Nov 6 '07 #7
bartonc
6,596 Recognized Expert Expert
Are this your current validators?
Expand|Select|Wrap|Line Numbers
  1. def validIP(ipAdd): 
  2.     ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" 
  3.     re_ip = re.compile(ipRegex) 
  4.     return re_ip.match(ipAdd)
  5.  
  6. def validIP1(ipAdd1): 
  7.     ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" 
  8.     re_ip = re.compile(ipRegex) 
  9.     return re_ip.match(ipAdd1)
Which one are you using?
Nov 7 '07 #8
Charlie of Bolton
32 New Member
Hi Bartonc,

I use only the first one:

Expand|Select|Wrap|Line Numbers
  1. def validIP(ipAdd):
  2.     ipRegex = r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?  \d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$" 
  3.     re_ip = re.compile(ipRegex)
  4.     return re_ip.match(ipAdd)
  5.  
but I think the problem is located more at the filter level:

what I want, is the primary ip to be ping and if the packet lost are more than 2%, I want ALL my secondaries IP to be ping even if they are under 2% packet lost. (but I want all the secondaries IP over 2% packet lost to go to my file: myprimarylogs.t xt). Actually the present script stop pinging as soon as one of the secondaries IP are over 2 % packet lost and go back to ping my primary, it does not ping all the way down all the secondaries IPs. What do you suggest ?
Nov 7 '07 #9
Charlie of Bolton
32 New Member
Hi,

any suggestion ?

Brgds/Charlie
Nov 8 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1294
by: john.livermore | last post by:
Quick question about deleting data from SQL Server. We have a table that gets quite a bit of activity with an attribute of type text (inserts that store new text entries of 50-200k apiece). Older rows aren't needed so we have a process that deletes rows more than 30 days old (using delete statements). When these rows are deleted, is the...
6
10264
by: Burkhard Schultheis | last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is what is in db2diag.log during online backup: Starting a full database backup. 2004-04-01-02.33.54.760164 Instance:lzgneu Node:000 PID:1293(db2loggw (TELEMATX)) TID:1024 Appid:none data protection sqlpgwlp Probe:909 TailPage 0 does not match pagelsn...
5
7296
by: uthuras | last post by:
Machine : AIX 5.2 Product : UDB DB2 Release 8.1 FP4a I have problem loading data into destination table. The data file is huge with more than 6 Million records. This what i have done 1. Export the data into flat file (del format) 2. use the load command to load the data At step 2, i found that there are some errors registered in the...
2
2031
by: bil.shah | last post by:
Hi, I am listening to a port for data but I am not able to recieve whole data, I only get truncated data. Client sends me data that exceeds 40K and the data I recieve in my callback function is always 8K to 9K. I dont get the rest of the data. I think the data size is too big to come in one go and hence it comes in 2-3 sub-packages but my...
0
1077
by: David A. Schramm | last post by:
I am using OLE DB in .NET 2 to insert a row into an Access database. The source is a RTF control and the column is a Memo field. The data is being truncated along the way. The control's rtf length is truncated to 1033 and the field length in Access is truncated to 1024. This seemed to be working fine in .NET 1.0 since rows before my...
0
14409
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may be greater than 255 characters. 2. I have an access database. I link (not import) to the contents of the excel spreadsheet. In the design view in...
7
17698
Coldfire
by: Coldfire | last post by:
i am having error ....details are ASP.Net application...in which I have a textbox <asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server" MaxLength="1000" /></asp:TextBox> and this textbox is in a <asp:Repeater > which has the count of 35. The textbox value is stored in the SQL DB And...
7
2149
by: Kenevel | last post by:
Hi there, I'm trying to track down the log file into which the following failure will be written. --- SQL4302N Procedure or user-defined function "SRCPROD.PRO_GENERATE_GROUP_EVENTS", specific name "JDBC_GEN_GROUP_EVENTS" aborted with an exception "[CLI Driv".
6
7572
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I REALLY need to be able to monitor LOTS of running programs/processes and thought it would be nice to have them use SocketHandler logging and then I...
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7817
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6454
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2245
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1060
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.