git://git.onelab.eu
/
nepi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Adding validations to CCND and PING log parser in nepi data
[nepi.git]
/
src
/
nepi
/
data
/
processing
/
ping
/
parser.py
diff --git
a/src/nepi/data/processing/ping/parser.py
b/src/nepi/data/processing/ping/parser.py
index
3396207
..
c5745a1
100644
(file)
--- a/
src/nepi/data/processing/ping/parser.py
+++ b/
src/nepi/data/processing/ping/parser.py
@@
-27,7
+27,9
@@
# This library contains functions to parse log files generated using ping.
#
# This library contains functions to parse log files generated using ping.
#
+import collections
import re
import re
+import os
# RE to match line starting "traceroute to"
_rre = re.compile("\d+ bytes from ((?P<hostname>[^\s]+) )?\(?(?P<ip>[^\s]+)\)??: icmp_.eq=\d+ ttl=\d+ time=(?P<time>[^\s]+) ms")
# RE to match line starting "traceroute to"
_rre = re.compile("\d+ bytes from ((?P<hostname>[^\s]+) )?\(?(?P<ip>[^\s]+)\)??: icmp_.eq=\d+ ttl=\d+ time=(?P<time>[^\s]+) ms")
@@
-64,7
+66,7
@@
def parse_file(filename):
return data
return data
-def annotate_cn_node(graph, nid1, ips2nid
s
, data):
+def annotate_cn_node(graph, nid1, ips2nid, data):
for (target_ip, target_hostname, time) in data:
nid2 = ips2nid[target_ip]
for (target_ip, target_hostname, time) in data:
nid2 = ips2nid[target_ip]
@@
-80,14
+82,16
@@
def annotate_cn_graph(logs_dir, graph):
ping.
"""
ping.
"""
- ips2nid
s
= dict()
+ ips2nid = dict()
for nid in graph.nodes():
ips = graph.node[nid]["ips"]
for ip in ips:
for nid in graph.nodes():
ips = graph.node[nid]["ips"]
for ip in ips:
- ips2nid
s
[ip] = nid
+ ips2nid[ip] = nid
# Walk through the ping logs...
# Walk through the ping logs...
+ found_files = False
+
for dirpath, dnames, fnames in os.walk(logs_dir):
# continue if we are not at the leaf level (if there are subdirectories)
if dnames:
for dirpath, dnames, fnames in os.walk(logs_dir):
# continue if we are not at the leaf level (if there are subdirectories)
if dnames:
@@
-98,9
+102,14
@@
def annotate_cn_graph(logs_dir, graph):
for fname in fnames:
if fname.endswith(".ping"):
for fname in fnames:
if fname.endswith(".ping"):
+ found_files = True
filename = os.path.join(dirpath, fname)
data = parse_file(filename)
filename = os.path.join(dirpath, fname)
data = parse_file(filename)
- annotate_cn_node(graph, nid, ips2nids, data)
+ annotate_cn_node(graph, nid, ips2nid, data)
+
+ if not found_files:
+ msg = "No PING output files were found to parse at %s " % logs_dir
+ raise RuntimeError, msg
# Take as weight the most frequent value
for nid1, nid2 in graph.edges():
# Take as weight the most frequent value
for nid1, nid2 in graph.edges():