mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
move int/float conversions to _process
This commit is contained in:
@ -45,8 +45,8 @@ Schema:
|
|||||||
"ttl": integer,
|
"ttl": integer,
|
||||||
"time_ms": float,
|
"time_ms": float,
|
||||||
"duplicate": boolean,
|
"duplicate": boolean,
|
||||||
"packets_transmitted": integer, # null if not set
|
"packets_transmitted": integer,
|
||||||
"packets_received": integer, # null if not set
|
"packets_received": integer,
|
||||||
"packet_loss_percent": float,
|
"packet_loss_percent": float,
|
||||||
"duplicates": integer,
|
"duplicates": integer,
|
||||||
"errors": integer, # null if not set
|
"errors": integer, # null if not set
|
||||||
|
@ -326,45 +326,45 @@ def _linux_parse(data):
|
|||||||
if footer:
|
if footer:
|
||||||
# Init in zero, to keep compatibility with previous behaviour
|
# Init in zero, to keep compatibility with previous behaviour
|
||||||
if 'duplicates' not in raw_output:
|
if 'duplicates' not in raw_output:
|
||||||
raw_output['duplicates'] = 0
|
raw_output['duplicates'] = '0'
|
||||||
|
|
||||||
#
|
#
|
||||||
# See: https://github.com/dgibson/iputils/blob/master/ping_common.c#L995
|
# See: https://github.com/dgibson/iputils/blob/master/ping_common.c#L995
|
||||||
#
|
#
|
||||||
m = re.search(r'(\d+) packets transmitted', line)
|
m = re.search(r'(\d+) packets transmitted', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['packets_transmitted'] = int(m.group(1))
|
raw_output['packets_transmitted'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'(\d+) received,', line)
|
m = re.search(r'(\d+) received,', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['packets_received'] = int(m.group(1))
|
raw_output['packets_received'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) duplicates', line)
|
m = re.search(r'[+](\d+) duplicates', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['duplicates'] = int(m.group(1))
|
raw_output['duplicates'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) corrupted', line)
|
m = re.search(r'[+](\d+) corrupted', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['corrupted'] = int(m.group(1))
|
raw_output['corrupted'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) errors', line)
|
m = re.search(r'[+](\d+) errors', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['errors'] = int(m.group(1))
|
raw_output['errors'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'([\d\.]+)% packet loss', line)
|
m = re.search(r'([\d\.]+)% packet loss', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['packet_loss_percent'] = float(m.group(1))
|
raw_output['packet_loss_percent'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'time (\d+)ms', line)
|
m = re.search(r'time (\d+)ms', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['time_ms'] = int(m.group(1))
|
raw_output['time_ms'] = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'rtt min\/avg\/max\/mdev += +([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) ms', line)
|
m = re.search(r'rtt min\/avg\/max\/mdev += +([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) ms', line)
|
||||||
if m:
|
if m:
|
||||||
raw_output['round_trip_ms_min'] = float(m.group(1))
|
raw_output['round_trip_ms_min'] = m.group(1)
|
||||||
raw_output['round_trip_ms_avg'] = float(m.group(2))
|
raw_output['round_trip_ms_avg'] = m.group(2)
|
||||||
raw_output['round_trip_ms_max'] = float(m.group(3))
|
raw_output['round_trip_ms_max'] = m.group(3)
|
||||||
raw_output['round_trip_ms_stddev'] = float(m.group(4))
|
raw_output['round_trip_ms_stddev'] = m.group(4)
|
||||||
|
|
||||||
# ping response lines
|
# ping response lines
|
||||||
else:
|
else:
|
||||||
|
@ -40,8 +40,8 @@ Schema:
|
|||||||
"ttl": integer,
|
"ttl": integer,
|
||||||
"time_ms": float,
|
"time_ms": float,
|
||||||
"duplicate": boolean,
|
"duplicate": boolean,
|
||||||
"packets_transmitted": integer, # null if not set
|
"packets_transmitted": integer,
|
||||||
"packets_received": integer, # null if not set
|
"packets_received": integer,
|
||||||
"packet_loss_percent": float,
|
"packet_loss_percent": float,
|
||||||
"duplicates": integer,
|
"duplicates": integer,
|
||||||
"errors": integer, # null if not set
|
"errors": integer, # null if not set
|
||||||
@ -384,38 +384,38 @@ def _linux_parse(line, s):
|
|||||||
#
|
#
|
||||||
m = re.search(r'(\d+) packets transmitted', line)
|
m = re.search(r'(\d+) packets transmitted', line)
|
||||||
if m:
|
if m:
|
||||||
s.packets_transmitted = int(m.group(1))
|
s.packets_transmitted = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'(\d+) received,', line)
|
m = re.search(r'(\d+) received,', line)
|
||||||
if m:
|
if m:
|
||||||
s.packets_received = int(m.group(1))
|
s.packets_received = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) duplicates', line)
|
m = re.search(r'[+](\d+) duplicates', line)
|
||||||
if m:
|
if m:
|
||||||
s.duplicates = int(m.group(1))
|
s.duplicates = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) corrupted', line)
|
m = re.search(r'[+](\d+) corrupted', line)
|
||||||
if m:
|
if m:
|
||||||
s.corrupted = int(m.group(1))
|
s.corrupted = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'[+](\d+) errors', line)
|
m = re.search(r'[+](\d+) errors', line)
|
||||||
if m:
|
if m:
|
||||||
s.errors = int(m.group(1))
|
s.errors = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'([\d\.]+)% packet loss', line)
|
m = re.search(r'([\d\.]+)% packet loss', line)
|
||||||
if m:
|
if m:
|
||||||
s.packet_loss_percent = float(m.group(1))
|
s.packet_loss_percent = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'time (\d+)ms', line)
|
m = re.search(r'time (\d+)ms', line)
|
||||||
if m:
|
if m:
|
||||||
s.time_ms = int(m.group(1))
|
s.time_ms = m.group(1)
|
||||||
|
|
||||||
m = re.search(r'rtt min\/avg\/max\/mdev += +([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) ms', line)
|
m = re.search(r'rtt min\/avg\/max\/mdev += +([\d\.]+)\/([\d\.]+)\/([\d\.]+)\/([\d\.]+) ms', line)
|
||||||
if m:
|
if m:
|
||||||
s.round_trip_ms_min = float(m.group(1))
|
s.round_trip_ms_min = m.group(1)
|
||||||
s.round_trip_ms_avg = float(m.group(2))
|
s.round_trip_ms_avg = m.group(2)
|
||||||
s.round_trip_ms_max = float(m.group(3))
|
s.round_trip_ms_max = m.group(3)
|
||||||
s.round_trip_ms_stddev = float(m.group(4))
|
s.round_trip_ms_stddev = m.group(4)
|
||||||
|
|
||||||
output_line = {
|
output_line = {
|
||||||
'type': 'summary',
|
'type': 'summary',
|
||||||
|
2
tests/fixtures/pi/ping-ip-O-D-streaming.json
vendored
2
tests/fixtures/pi/ping-ip-O-D-streaming.json
vendored
@ -1 +1 @@
|
|||||||
[{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585008.591169,"icmp_seq":1},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585009.631169,"icmp_seq":2},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585010.671173,"icmp_seq":3},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585011.711167,"icmp_seq":4},{"type":"summary","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"packets_transmitted":5,"packets_received":null,"packet_loss_percent":100.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":4154.0,"round_trip_ms_min":null,"round_trip_ms_avg":null,"round_trip_ms_max":null,"round_trip_ms_stddev":null}]
|
[{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585008.591169,"icmp_seq":1},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585009.631169,"icmp_seq":2},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585010.671173,"icmp_seq":3},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":1596585011.711167,"icmp_seq":4},{"type":"summary","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"packets_transmitted":5,"packets_received":0,"packet_loss_percent":100.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":4154.0,"round_trip_ms_min":null,"round_trip_ms_avg":null,"round_trip_ms_max":null,"round_trip_ms_stddev":null}]
|
||||||
|
2
tests/fixtures/pi/ping-ip-O-streaming.json
vendored
2
tests/fixtures/pi/ping-ip-O-streaming.json
vendored
@ -1 +1 @@
|
|||||||
[{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":1},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":2},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":3},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":4},{"type":"summary","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"packets_transmitted":5,"packets_received":null,"packet_loss_percent":100.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":4149.0,"round_trip_ms_min":null,"round_trip_ms_avg":null,"round_trip_ms_max":null,"round_trip_ms_stddev":null}]
|
[{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":1},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":2},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":3},{"type":"timeout","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"timestamp":null,"icmp_seq":4},{"type":"summary","destination_ip":"192.168.120.164","sent_bytes":56,"pattern":null,"packets_transmitted":5,"packets_received":0,"packet_loss_percent":100.0,"duplicates":0,"errors":null,"corrupted":null,"time_ms":4149.0,"round_trip_ms_min":null,"round_trip_ms_avg":null,"round_trip_ms_max":null,"round_trip_ms_stddev":null}]
|
||||||
|
Reference in New Issue
Block a user