mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
ping parser fix for raspberry pi
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
jc changelog
|
||||
|
||||
20200804 v1.13.3
|
||||
- Updae ping parser for Raspberry Pi compatibility
|
||||
|
||||
20200803 v1.13.2
|
||||
- Add key/value file parser (wrapper for ini parser)
|
||||
- Add date command parser
|
||||
|
@ -21,7 +21,7 @@ import jc.appdirs as appdirs
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.13.2'
|
||||
version = '1.13.3'
|
||||
description = 'JSON CLI output utility'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
@ -108,7 +108,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
version = '1.1'
|
||||
description = 'ping command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -496,7 +496,7 @@ def parse(data, raw=False, quiet=False):
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
if 'time' in data.splitlines()[-2]:
|
||||
if 'time' in data.splitlines()[-2] or 'time' in data.splitlines()[-3]:
|
||||
raw_output = linux_parse(data)
|
||||
else:
|
||||
raw_output = bsd_parse(data)
|
||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
||||
|
||||
setuptools.setup(
|
||||
name='jc',
|
||||
version='1.13.2',
|
||||
version='1.13.3',
|
||||
author='Kelly Brazil',
|
||||
author_email='kellyjonbrazil@gmail.com',
|
||||
description='Converts the output of popular command-line tools and file-types to JSON.',
|
||||
|
1
tests/fixtures/pi/ping-ip-O-D.json
vendored
Normal file
1
tests/fixtures/pi/ping-ip-O-D.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"destination_ip": "192.168.120.164", "data_bytes": 56, "pattern": null, "destination": "192.168.120.164", "packets_transmitted": 5, "packets_received": 0, "packet_loss_percent": 100.0, "duplicates": 0, "time_ms": 4154.0, "responses": [{"type": "timeout", "timestamp": 1596585008.591169, "icmp_seq": 1}, {"type": "timeout", "timestamp": 1596585009.631169, "icmp_seq": 2}, {"type": "timeout", "timestamp": 1596585010.671173, "icmp_seq": 3}, {"type": "timeout", "timestamp": 1596585011.711167, "icmp_seq": 4}]}
|
10
tests/fixtures/pi/ping-ip-O-D.out
vendored
Normal file
10
tests/fixtures/pi/ping-ip-O-D.out
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
PING 192.168.120.164 (192.168.120.164) 56(84) bytes of data.
|
||||
[1596585008.591169] no answer yet for icmp_seq=1
|
||||
[1596585009.631169] no answer yet for icmp_seq=2
|
||||
[1596585010.671173] no answer yet for icmp_seq=3
|
||||
[1596585011.711167] no answer yet for icmp_seq=4
|
||||
|
||||
--- 192.168.120.164 ping statistics ---
|
||||
5 packets transmitted, 0 received, 100% packet loss, time 4154ms
|
||||
|
||||
|
1
tests/fixtures/pi/ping-ip-O.json
vendored
Normal file
1
tests/fixtures/pi/ping-ip-O.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"destination_ip": "192.168.120.164", "data_bytes": 56, "pattern": null, "destination": "192.168.120.164", "packets_transmitted": 5, "packets_received": 0, "packet_loss_percent": 100.0, "duplicates": 0, "time_ms": 4149.0, "responses": [{"type": "timeout", "timestamp": null, "icmp_seq": 1}, {"type": "timeout", "timestamp": null, "icmp_seq": 2}, {"type": "timeout", "timestamp": null, "icmp_seq": 3}, {"type": "timeout", "timestamp": null, "icmp_seq": 4}]}
|
10
tests/fixtures/pi/ping-ip-O.out
vendored
Normal file
10
tests/fixtures/pi/ping-ip-O.out
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
PING 192.168.120.164 (192.168.120.164) 56(84) bytes of data.
|
||||
no answer yet for icmp_seq=1
|
||||
no answer yet for icmp_seq=2
|
||||
no answer yet for icmp_seq=3
|
||||
no answer yet for icmp_seq=4
|
||||
|
||||
--- 192.168.120.164 ping statistics ---
|
||||
5 packets transmitted, 0 received, 100% packet loss, time 4149ms
|
||||
|
||||
|
@ -181,6 +181,13 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-ip-dup.out'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_ip_dup = f.read()
|
||||
|
||||
# raspberry pi
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/pi/ping-ip-O.out'), 'r', encoding='utf-8') as f:
|
||||
self.pi_ping_ip_O = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/pi/ping-ip-O-D.out'), 'r', encoding='utf-8') as f:
|
||||
self.pi_ping_ip_O_D = f.read()
|
||||
|
||||
# output
|
||||
|
||||
# centos
|
||||
@ -353,6 +360,13 @@ class MyTests(unittest.TestCase):
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/ping6-ip-dup.json'), 'r', encoding='utf-8') as f:
|
||||
self.osx_10_14_6_ping6_ip_dup_json = json.loads(f.read())
|
||||
|
||||
# raspberry pi
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/pi/ping-ip-O.json'), 'r', encoding='utf-8') as f:
|
||||
self.pi_ping_ip_O_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/pi/ping-ip-O-D.json'), 'r', encoding='utf-8') as f:
|
||||
self.pi_ping_ip_O_D_json = json.loads(f.read())
|
||||
|
||||
def test_ping_nodata(self):
|
||||
"""
|
||||
Test 'ping' with no data
|
||||
@ -689,6 +703,18 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.osx_10_14_6_ping6_ip_dup, quiet=True), self.osx_10_14_6_ping6_ip_dup_json)
|
||||
|
||||
def test_ping_ip_O_pi(self):
|
||||
"""
|
||||
Test 'ping6 <ip> -O' on raspberry pi
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.pi_ping_ip_O, quiet=True), self.pi_ping_ip_O_json)
|
||||
|
||||
def test_ping_ip_O_D_pi(self):
|
||||
"""
|
||||
Test 'ping6 <ip> -O -D' on raspberry pi
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ping.parse(self.pi_ping_ip_O_D, quiet=True), self.pi_ping_ip_O_D_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user