From a6b56519a2465144e279d444df18d85703bebfb1 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sat, 5 Nov 2022 18:47:44 -0700 Subject: [PATCH] add more bsd fields to ifconfig --- CHANGELOG | 4 +- jc/parsers/ifconfig.py | 45 ++++++++++++++++++- .../freebsd12/ifconfig-extra-fields2.out | 11 +++++ .../freebsd12/ifconfig-extra-fields3.out | 10 +++++ tests/test_ifconfig.py | 5 +++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/freebsd12/ifconfig-extra-fields2.out create mode 100644 tests/fixtures/freebsd12/ifconfig-extra-fields3.out diff --git a/CHANGELOG b/CHANGELOG index 927f9981..3aace429 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,10 @@ jc changelog -20221102 v1.22.2 +20221105 v1.22.2 - add `sshd_conf` parser - add `findmnt` parser +- enhance the `ifconfig` parser so it can output multiple IPv4 and IPv6 addresses +- enhance the `ifconfig` parser so it can output additional fields common on BSD - enhance `xml` parser with optional `_` prefix for attributes instead of `@` by using the `--raw` option. This can make it easier to filter the JSON output in some tools. diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 7eb2f07b..6b43730e 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -51,6 +51,7 @@ Schema: "tx_overruns": integer, "tx_carrier": integer, "tx_collisions": integer, + "status": string, "ipv4": [ { "address": string, @@ -482,7 +483,43 @@ def parse( ) re_freebsd_details = re.compile(r''' ether\s+(?P[0-9A-Fa-f:?]+) - ''', re.IGNORECASE | re.VERBOSE + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_status = re.compile(r''' + status:\s(?P\w+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_hwaddr = re.compile(r''' + hwaddr\s(?P[0-9A-Fa-f:?]+) + (?:\s+media:\s(?P.+)\s + <(?P.+)>)? + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_media = re.compile(r''' + media:\s(?P.+) + (?:\s+?<(?P.+)>) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_nd6_options = re.compile(r''' + nd6\soptions=(?P\d+) + <(?P\S+)> + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_plugged = re.compile(r''' + plugged:\s(?P.+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_vendor_pn_sn_date = re.compile(r''' + vendor:\s(?P.+)\s + PN:\s(?P.+)\s + SN:\s(?P.+)\s + DATE:\s(?P.+) + ''', re.IGNORECASE | re.VERBOSE + ) + re_freebsd_temp_volts = re.compile(r''' + module\stemperature:\s(?P.+)\s + voltage:\s(?P.+) + ''', re.IGNORECASE | re.VERBOSE ) re_linux = [ @@ -493,7 +530,11 @@ def parse( re_openbsd_interface, re_openbsd_ipv4, re_openbsd_ipv6, re_openbsd_details, re_openbsd_rx, re_openbsd_rx_stats, re_openbsd_tx, re_openbsd_tx_stats ] - re_freebsd = [re_freebsd_interface, re_freebsd_ipv4, re_freebsd_ipv6, re_freebsd_details] + re_freebsd = [ + re_freebsd_interface, re_freebsd_ipv4, re_freebsd_ipv6, re_freebsd_details, re_freebsd_status, + re_freebsd_nd6_options, re_freebsd_plugged, re_freebsd_vendor_pn_sn_date, re_freebsd_temp_volts, + re_freebsd_hwaddr, re_freebsd_media + ] interface_patterns = [re_linux_interface, re_openbsd_interface, re_freebsd_interface] ipv4_patterns = [re_linux_ipv4, re_openbsd_ipv4, re_freebsd_ipv4] diff --git a/tests/fixtures/freebsd12/ifconfig-extra-fields2.out b/tests/fixtures/freebsd12/ifconfig-extra-fields2.out new file mode 100644 index 00000000..4690168a --- /dev/null +++ b/tests/fixtures/freebsd12/ifconfig-extra-fields2.out @@ -0,0 +1,11 @@ +ix0: flags=8843 metric 0 mtu 9000 + options=e53fbb + ether 00:1b:21:8b:f8:2c + inet 10.10.2.101/24 broadcast 10.10.2.255 + media: Ethernet autoselect (10Gbase-SR ) + status: active + nd6 options=29 + plugged: SFP/SFP+/SFP28 10G Base-SR (LC) + vendor: Intel Corp PN: FTLX8571D3BCV-IT SN: ALH1AV9 DATE: 2011-10-27 + module temperature: 51.27 C Voltage: 3.31 Volts + RX: 0.49 mW (-3.02 dBm) TX: 0.66 mW (-1.74 dBm) diff --git a/tests/fixtures/freebsd12/ifconfig-extra-fields3.out b/tests/fixtures/freebsd12/ifconfig-extra-fields3.out new file mode 100644 index 00000000..55bde76a --- /dev/null +++ b/tests/fixtures/freebsd12/ifconfig-extra-fields3.out @@ -0,0 +1,10 @@ +cxl3: flags=8843 metric 0 mtu 1500 + options=6ec07bb + ether 00:07:43:3d:b7:70 + hwaddr 00:07:43:3d:b7:88 + status: active + nd6 options=29 + plugged: SFP/SFP+/SFP28 10G Base-LR (LC) + vendor: INNOLIGHT PN: TR-PX13L-N00 SN: INJBL0431986 DATE: 2020-01-04 + module temperature: 21.20 C voltage: 3.16 Volts + lane 1: RX power: 0.49 mW (-3.10 dBm) TX bias: 23.85 mA diff --git a/tests/test_ifconfig.py b/tests/test_ifconfig.py index 75d38d22..5b532865 100644 --- a/tests/test_ifconfig.py +++ b/tests/test_ifconfig.py @@ -94,6 +94,11 @@ class MyTests(unittest.TestCase): self.maxDiff = None self.assertEqual(jc.parsers.ifconfig.parse(self.osx_10_14_6_ifconfig2, quiet=True), self.osx_10_14_6_ifconfig2_json) + def test_ifconfig_freebsd_extra_fields(self): + pass + + def test_ifconfig_freebsd_extra_fields2(self): + pass if __name__ == '__main__': unittest.main()