diff --git a/CHANGELOG b/CHANGELOG index 81936ee7..c3f088b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ jc changelog 20211104 v1.17.2 (in progress) - Fix ping parser to add Alpine linux support +- Fix netstat parser for older versions of netstat on linux 20211030 v1.17.1 - Fix file parser for gzip files diff --git a/tests/fixtures/generic/netstat-old.json b/tests/fixtures/generic/netstat-old.json new file mode 100644 index 00000000..41f48034 --- /dev/null +++ b/tests/fixtures/generic/netstat-old.json @@ -0,0 +1 @@ +[{"proto":"tcp","recv_q":0,"send_q":0,"local_address":"0.0.0.0","foreign_address":"0.0.0.0","state":"LISTEN","program_name":"systemd","kind":"network","pid":1,"local_port":"111","foreign_port":"*","transport_protocol":"tcp","network_protocol":"ipv4","local_port_num":111},{"proto":"udp","recv_q":0,"send_q":0,"local_address":"200.4.30.128","foreign_address":"0.0.0.0","state":null,"program_name":"NetworkManager","kind":"network","pid":903,"local_port":"68","foreign_port":"*","transport_protocol":"udp","network_protocol":"ipv4","local_port_num":68},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":18438,"program_name":"systemd","path":"/run/lvm/lvmpolld.socket","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":null,"type":"DGRAM","state":null,"inode":23569,"program_name":"chronyd","path":"/var/run/chrony/chronyd.sock","kind":"socket","pid":871},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":23584,"program_name":"gssproxy","path":"/run/gssproxy.sock","kind":"socket","pid":872},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":18511,"program_name":"systemd","path":"/run/rpcbind.sock","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":"ACC","type":"SEQPACKET","state":"LISTENING","inode":18521,"program_name":"systemd","path":"/run/udev/control","kind":"socket","pid":1},{"proto":"unix","refcnt":3,"flags":null,"type":"DGRAM","state":null,"inode":11098,"program_name":"systemd","path":"/run/systemd/notify","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":null,"type":"DGRAM","state":null,"inode":11100,"program_name":"systemd","path":"/run/systemd/cgroups-agent","kind":"socket","pid":1},{"proto":"unix","refcnt":2,"flags":"ACC","type":"STREAM","state":"LISTENING","inode":24236,"program_name":"sssd","path":"/var/lib/sss/pipes/private/sbus-monitor","kind":"socket","pid":863}] diff --git a/tests/fixtures/generic/netstat-old.out b/tests/fixtures/generic/netstat-old.out new file mode 100644 index 00000000..6606dbd1 --- /dev/null +++ b/tests/fixtures/generic/netstat-old.out @@ -0,0 +1,14 @@ +Active Internet connections (servers and established) +Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name +tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd +udp 0 0 200.4.30.128:68 0.0.0.0:* 903/NetworkManager +Active UNIX domain sockets (servers and established) +Proto RefCnt Flags Type State I-Node PID/Program name Path +unix 2 [ ACC ] STREAM LISTENING 18438 1/systemd /run/lvm/lvmpolld.socket +unix 2 [ ] DGRAM 23569 871/chronyd /var/run/chrony/chronyd.sock +unix 2 [ ACC ] STREAM LISTENING 23584 872/gssproxy /run/gssproxy.sock +unix 2 [ ACC ] STREAM LISTENING 18511 1/systemd /run/rpcbind.sock +unix 2 [ ACC ] SEQPACKET LISTENING 18521 1/systemd /run/udev/control +unix 3 [ ] DGRAM 11098 1/systemd /run/systemd/notify +unix 2 [ ] DGRAM 11100 1/systemd /run/systemd/cgroups-agent +unix 2 [ ACC ] STREAM LISTENING 24236 863/sssd /var/lib/sss/pipes/private/sbus-monitor diff --git a/tests/test_netstat.py b/tests/test_netstat.py index 8e6da0b1..5e1a6af6 100644 --- a/tests/test_netstat.py +++ b/tests/test_netstat.py @@ -74,6 +74,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-aT.out'), 'r', encoding='utf-8') as f: self.freebsd12_netstat_aT = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.out'), 'r', encoding='utf-8') as f: + self.generic_netstat_old = f.read() + # netstat -r with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f: self.centos_7_7_netstat_r = f.read() @@ -183,6 +186,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-an.json'), 'r', encoding='utf-8') as f: self.freebsd12_netstat_an_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.json'), 'r', encoding='utf-8') as f: + self.generic_netstat_old_json = json.loads(f.read()) + # netsat -r with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f: self.centos_7_7_netstat_r_json = json.loads(f.read()) @@ -353,6 +359,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_an, quiet=True), self.freebsd12_netstat_an_json) + def test_netstat_old_generic(self): + """ + Test 'netstat' with older version of netstat on linux + """ + self.assertEqual(jc.parsers.netstat.parse(self.generic_netstat_old, quiet=True), self.generic_netstat_old_json) + def test_netstat_r_centos_7_7(self): """ Test 'netstat -r' on Centos 7.7