473,287 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

logging data truncated

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.xls) 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 2406
bartonc
6,596 Expert 4TB
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
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
Hi,

Is someone can help me ?

Brgds/Charlie
Nov 2 '07 #4
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 Expert 4TB
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
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 Expert 4TB
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
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.txt). 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
Hi,

any suggestion ?

Brgds/Charlie
Nov 8 '07 #10
bvdet
2,851 Expert Mod 2GB
Hi,

any suggestion ?

Brgds/Charlie
Your problem can be corrected by modifying the code in function ping(). When fil() returns True, the 'break' statement breaks out of the for loop. You will need a way of continuing the for loop even though fil() returns True for the secondary IPs. HTH
Nov 8 '07 #11

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

Similar topics

2
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)....
6
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 ...
5
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....
2
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...
0
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...
0
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...
7
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"...
7
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",...
6
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.