1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add more bsd fields to ifconfig

This commit is contained in:
Kelly Brazil
2022-11-05 18:47:44 -07:00
parent 0a71caf9cd
commit a6b56519a2
5 changed files with 72 additions and 3 deletions

View File

@ -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.

View File

@ -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<mac_addr>[0-9A-Fa-f:?]+)
''', re.IGNORECASE | re.VERBOSE
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_status = re.compile(r'''
status:\s(?P<status>\w+)
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_hwaddr = re.compile(r'''
hwaddr\s(?P<hw_address>[0-9A-Fa-f:?]+)
(?:\s+media:\s(?P<media>.+)\s
<(?P<media_flags>.+)>)?
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_media = re.compile(r'''
media:\s(?P<media>.+)
(?:\s+?<(?P<media_flags>.+)>)
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_nd6_options = re.compile(r'''
nd6\soptions=(?P<nd6_options>\d+)
<(?P<nd6_flags>\S+)>
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_plugged = re.compile(r'''
plugged:\s(?P<plugged>.+)
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_vendor_pn_sn_date = re.compile(r'''
vendor:\s(?P<vendor>.+)\s
PN:\s(?P<vendor_pn>.+)\s
SN:\s(?P<vendor_sn>.+)\s
DATE:\s(?P<vendor_date>.+)
''', re.IGNORECASE | re.VERBOSE
)
re_freebsd_temp_volts = re.compile(r'''
module\stemperature:\s(?P<module_temperature>.+)\s
voltage:\s(?P<module_voltage>.+)
''', 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]

View File

@ -0,0 +1,11 @@
ix0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 9000
options=e53fbb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,WOL_UCAST,WOL_MCAST,WOL_MAGIC,VLAN_HWFILTER,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
ether 00:1b:21:8b:f8:2c
inet 10.10.2.101/24 broadcast 10.10.2.255
media: Ethernet autoselect (10Gbase-SR <full-duplex,rxpause,txpause>)
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
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)

View File

@ -0,0 +1,10 @@
cxl3: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=6ec07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6,HWRXTSTMP,NOMAP>
ether 00:07:43:3d:b7:70
hwaddr 00:07:43:3d:b7:88
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
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

View File

@ -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()