From a5082d24b919e707d92cdfa58cb3192d11dc9b59 Mon Sep 17 00:00:00 2001 From: pskliarenko <“pskliarenko@bsh.ru”> Date: Sun, 10 Sep 2023 22:28:44 +0400 Subject: [PATCH 1/2] Template + test --- .../fortinet_fnsysctl_ifconfig.textfsm | 37 +++ ntc_templates/templates/index | 1 + .../fortinet_fnsysctl_ifconfig.raw | 84 ++++++ .../fortinet_fnsysctl_ifconfig.yml | 277 ++++++++++++++++++ 4 files changed, 399 insertions(+) create mode 100644 ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm create mode 100644 tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.raw create mode 100644 tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml diff --git a/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm b/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm new file mode 100644 index 0000000000..481db24cf4 --- /dev/null +++ b/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm @@ -0,0 +1,37 @@ +Value NIC (.*?) +Value LINK_ENCAP (.*?) +Value HW_ADDR ([a-zA-Z0-9]{2}(:[a-zA-Z0-9]{2}){5}) +Value INET_ADDR (\S+) +Value BCAST (\S+) +Value MASK (\S+) +Value LINK_LOCAL6 (\S+) +Value LINK_LOCAL6_PREFIXLEN (\d+) +Value MULTICAST (.*(? Record + ^\s*$$ + ^. -> Error diff --git a/ntc_templates/templates/index b/ntc_templates/templates/index index 3a5b516184..58b2621446 100644 --- a/ntc_templates/templates/index +++ b/ntc_templates/templates/index @@ -485,6 +485,7 @@ fortinet_get_system_interface_physical.textfsm, .*, fortinet, g[[et]] sy[[stem]] fortinet_get_router_info_bgp_summary.textfsm, .*, fortinet, g[[et]] r[[outer]] info bg[[p]] su[[mmary]] fortinet_get_system_ha_status.textfsm, .*, fortinet, g[[et]] sy[[stem]] ha s[[tatus]] fortinet_get_system_interface.textfsm, .*, fortinet, g[[et]] sy[[stem]] in[[terface]] +fortinet_fnsysctl_ifconfig.textfsm, .*, fortinet, fnsysctl ifconfig fortinet_get_system_status.textfsm, .*, fortinet, g[[et]] sy[[stem]] stat[[us]] fortinet_get_system_arp.textfsm, .*, fortinet, g[[et]] sy[[stem]] arp diff --git a/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.raw b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.raw new file mode 100644 index 0000000000..079240d015 --- /dev/null +++ b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.raw @@ -0,0 +1,84 @@ +nturbo_rx Link encap:Ethernet + UP BROADCAST MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:0 (0 Bytes) TX bytes:0 (0 Bytes) + +wan Link encap:Ethernet HWaddr 12:34:56:78:90:AA + inet addr:1.2.3.4 Bcast:1.2.3.5 Mask:255.255.255.252 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:7513822 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12533342 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:1116754241 (1.0 GB) TX bytes:2218288063 (2.1 GB) + +lan1 Link encap:Ethernet HWaddr 12:34:56:78:90:AB + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:3336406 errors:0 dropped:0 overruns:0 frame:0 + TX packets:3382703 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:258477533 (246.5 MB) TX bytes:365165072 (348.2 MB) + +ssl.root Link encap:Unknown + UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:2 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0 Bytes) TX bytes:0 (0 Bytes) + +Loopback772 Link encap:Unknown + inet addr:127.0.0.1 Bcast:0.0.0.0 Mask:255.0.0.0 + UP BROADCAST LOOPBACK RUNNING NOARP MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0 Bytes) TX bytes:152 (152 Bytes) + +lan Link encap:Ethernet HWaddr 12:34:56:78:90:AC + inet addr:10.152.1.230 Bcast:10.152.1.231 Mask:255.255.255.252 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:1695331 errors:0 dropped:0 overruns:0 frame:0 + TX packets:2829487 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:154509025 (147.4 MB) TX bytes:320990192 (306.1 MB) + +Tu-Hub01-Main Link encap:Unknown + inet addr:10.149.0.69 Mask:255.255.0.0 + UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1438 Metric:1 + RX packets:2669 errors:0 dropped:0 overruns:0 frame:0 + TX packets:64643 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:919078 (897.5 KB) TX bytes:5464602 (5.2 MB) + +Tu-Rsnnc-Main Link encap:Unknown HWaddr 12:34:56:78:90:AD + inet addr:192.168.64.10 Mask:255.255.255.252 + link-local6: fe80::200:aaaa:5f4f:54f4 prefixlen 64 + UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1476 Metric:1 + RX packets:121755 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:8018365 (7.6 MB) TX bytes:84 (84 Bytes) + +Vlan1 Link encap:Ethernet HWaddr 12:34:56:78:90:AE + inet addr:10.100.105.1 Bcast:10.100.105.31 Mask:255.255.255.224 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:69882 errors:0 dropped:0 overruns:0 frame:0 + TX packets:65 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:10988958 (10.5 MB) TX bytes:3128 (3.1 KB) + +port_ha Link encap:Ethernet HWaddr 12:34:56:78:90:AF + UP BROADCAST MULTICAST MTU:1496 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:1 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:0 (0 Bytes) TX bytes:0 (0 Bytes) + +vsys_fgfm Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0 Bytes) TX bytes:0 (0 Bytes) diff --git a/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml new file mode 100644 index 0000000000..551ff169fe --- /dev/null +++ b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml @@ -0,0 +1,277 @@ +--- +parsed_sample: + - bcast: "" + collisions: "0" + hw_addr: "" + inet_addr: "" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST MULTICAST" + nic: "nturbo_rx" + rx_bytes: "0" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "0" + tx_bytes: "0" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "0" + tx_queue_len: "1000" + - bcast: "1.2.3.5" + collisions: "0" + hw_addr: "12:34:56:78:90:AA" + inet_addr: "1.2.3.4" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.255.255.252" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST RUNNING MULTICAST" + nic: "wan" + rx_bytes: "1116754241" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "7513822" + tx_bytes: "2218288063" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "12533342" + tx_queue_len: "1000" + - bcast: "" + collisions: "0" + hw_addr: "12:34:56:78:90:AB" + inet_addr: "" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST RUNNING MULTICAST" + nic: "lan1" + rx_bytes: "258477533" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "3336406" + tx_bytes: "365165072" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "3382703" + tx_queue_len: "1000" + - bcast: "" + collisions: "0" + hw_addr: "" + inet_addr: "" + link_encap: "Unknown" + link_local6: "" + link_local6_prefixlen: "" + mask: "" + metric: "1" + mtu: "1500" + multicast: "UP POINTOPOINT RUNNING NOARP MULTICAST" + nic: "ssl.root" + rx_bytes: "0" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "0" + tx_bytes: "0" + tx_carrier: "0" + tx_dropped: "2" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "0" + tx_queue_len: "0" + - bcast: "0.0.0.0" + collisions: "0" + hw_addr: "" + inet_addr: "127.0.0.1" + link_encap: "Unknown" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.0.0.0" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST LOOPBACK RUNNING NOARP MULTICAST" + nic: "Loopback772" + rx_bytes: "0" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "0" + tx_bytes: "152" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "2" + tx_queue_len: "0" + - bcast: "10.152.1.231" + collisions: "0" + hw_addr: "12:34:56:78:90:AC" + inet_addr: "10.152.1.230" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.255.255.252" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST RUNNING MULTICAST" + nic: "lan" + rx_bytes: "154509025" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "1695331" + tx_bytes: "320990192" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "2829487" + tx_queue_len: "1000" + - bcast: "" + collisions: "0" + hw_addr: "" + inet_addr: "10.149.0.69" + link_encap: "Unknown" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.255.0.0" + metric: "1" + mtu: "1438" + multicast: "UP POINTOPOINT RUNNING NOARP MULTICAST" + nic: "Tu-Hub01-Main" + rx_bytes: "919078" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "2669" + tx_bytes: "5464602" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "64643" + tx_queue_len: "0" + - bcast: "" + collisions: "0" + hw_addr: "12:34:56:78:90:AD" + inet_addr: "192.168.64.10" + link_encap: "Unknown" + link_local6: "fe80::200:aaaa:5f4f:54f4" + link_local6_prefixlen: "64" + mask: "255.255.255.252" + metric: "1" + mtu: "1476" + multicast: "UP POINTOPOINT RUNNING NOARP MULTICAST" + nic: "Tu-Rsnnc-Main" + rx_bytes: "8018365" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "121755" + tx_bytes: "84" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "1" + tx_queue_len: "0" + - bcast: "10.100.105.31" + collisions: "0" + hw_addr: "12:34:56:78:90:AE" + inet_addr: "10.100.105.1" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.255.255.224" + metric: "1" + mtu: "1500" + multicast: "UP BROADCAST RUNNING MULTICAST" + nic: "Vlan1" + rx_bytes: "10988958" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "69882" + tx_bytes: "3128" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "65" + tx_queue_len: "0" + - bcast: "" + collisions: "0" + hw_addr: "12:34:56:78:90:AF" + inet_addr: "" + link_encap: "Ethernet" + link_local6: "" + link_local6_prefixlen: "" + mask: "" + metric: "1" + mtu: "1496" + multicast: "UP BROADCAST MULTICAST" + nic: "port_ha" + rx_bytes: "0" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "0" + tx_bytes: "0" + tx_carrier: "0" + tx_dropped: "1" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "0" + tx_queue_len: "1000" + - bcast: "" + collisions: "0" + hw_addr: "" + inet_addr: "127.0.0.1" + link_encap: "Local Loopback" + link_local6: "" + link_local6_prefixlen: "" + mask: "255.0.0.0" + metric: "1" + mtu: "16436" + multicast: "UP LOOPBACK RUNNING" + nic: "vsys_fgfm" + rx_bytes: "0" + rx_dropped: "0" + rx_errors: "0" + rx_frame: "0" + rx_overruns: "0" + rx_packets: "0" + tx_bytes: "0" + tx_carrier: "0" + tx_dropped: "0" + tx_errors: "0" + tx_overruns: "0" + tx_packets: "0" + tx_queue_len: "0" From 53867fd8640e7aed33022e0ee2596a91b5c5ce60 Mon Sep 17 00:00:00 2001 From: Jacob McGill <9847006+jmcgill298@users.noreply.github.com> Date: Mon, 22 Jul 2024 11:47:57 -0400 Subject: [PATCH 2/2] Apply suggestions from code review --- .../fortinet_fnsysctl_ifconfig.textfsm | 8 ++-- .../fortinet_fnsysctl_ifconfig.yml | 44 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm b/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm index 481db24cf4..c601476824 100644 --- a/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm +++ b/ntc_templates/templates/fortinet_fnsysctl_ifconfig.textfsm @@ -1,7 +1,7 @@ Value NIC (.*?) Value LINK_ENCAP (.*?) -Value HW_ADDR ([a-zA-Z0-9]{2}(:[a-zA-Z0-9]{2}){5}) -Value INET_ADDR (\S+) +Value HARDWARE_ADDRESS ([a-zA-Z0-9]{2}(:[a-zA-Z0-9]{2}){5}) +Value IP_ADDRESS (\S+) Value BCAST (\S+) Value MASK (\S+) Value LINK_LOCAL6 (\S+) @@ -25,8 +25,8 @@ Value RX_BYTES (\d+) Value TX_BYTES (\d+) Start - ^\s*${NIC}\s+Link\s+encap:${LINK_ENCAP}(?:\s+HWaddr\s+${HW_ADDR})?\s*$$ - ^\s*inet\s+addr:${INET_ADDR}(?:\s+Bcast:${BCAST})?\s+Mask:${MASK}\s*$$ + ^\s*${NIC}\s+Link\s+encap:${LINK_ENCAP}(?:\s+HWaddr\s+${HARDWARE_ADDRESS})?\s*$$ + ^\s*inet\s+addr:${IP_ADDRESS}(?:\s+Bcast:${BCAST})?\s+Mask:${MASK}\s*$$ ^\s*link-local6:\s+${LINK_LOCAL6}\s+prefixlen\s+${LINK_LOCAL6_PREFIXLEN}\s*$$ ^\s*${MULTICAST}\s+MTU:${MTU}\s+Metric:${METRIC}\s*$$ ^\s*RX\s+packets:${RX_PACKETS}\s+errors:${RX_ERRORS}\s+dropped:${RX_DROPPED}\s+overruns:${RX_OVERRUNS}\s+frame:${RX_FRAME}\s*$$ diff --git a/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml index 551ff169fe..3bc2fafb90 100644 --- a/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml +++ b/tests/fortinet/fnsysctl_ifconfig/fortinet_fnsysctl_ifconfig.yml @@ -2,8 +2,8 @@ parsed_sample: - bcast: "" collisions: "0" - hw_addr: "" - inet_addr: "" + hardware_address: "" + ip_address: "" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -27,8 +27,8 @@ parsed_sample: tx_queue_len: "1000" - bcast: "1.2.3.5" collisions: "0" - hw_addr: "12:34:56:78:90:AA" - inet_addr: "1.2.3.4" + hardware_address: "12:34:56:78:90:AA" + ip_address: "1.2.3.4" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -52,8 +52,8 @@ parsed_sample: tx_queue_len: "1000" - bcast: "" collisions: "0" - hw_addr: "12:34:56:78:90:AB" - inet_addr: "" + hardware_address: "12:34:56:78:90:AB" + ip_address: "" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -77,8 +77,8 @@ parsed_sample: tx_queue_len: "1000" - bcast: "" collisions: "0" - hw_addr: "" - inet_addr: "" + hardware_address: "" + ip_address: "" link_encap: "Unknown" link_local6: "" link_local6_prefixlen: "" @@ -102,8 +102,8 @@ parsed_sample: tx_queue_len: "0" - bcast: "0.0.0.0" collisions: "0" - hw_addr: "" - inet_addr: "127.0.0.1" + hardware_address: "" + ip_address: "127.0.0.1" link_encap: "Unknown" link_local6: "" link_local6_prefixlen: "" @@ -127,8 +127,8 @@ parsed_sample: tx_queue_len: "0" - bcast: "10.152.1.231" collisions: "0" - hw_addr: "12:34:56:78:90:AC" - inet_addr: "10.152.1.230" + hardware_address: "12:34:56:78:90:AC" + ip_address: "10.152.1.230" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -152,8 +152,8 @@ parsed_sample: tx_queue_len: "1000" - bcast: "" collisions: "0" - hw_addr: "" - inet_addr: "10.149.0.69" + hardware_address: "" + ip_address: "10.149.0.69" link_encap: "Unknown" link_local6: "" link_local6_prefixlen: "" @@ -177,8 +177,8 @@ parsed_sample: tx_queue_len: "0" - bcast: "" collisions: "0" - hw_addr: "12:34:56:78:90:AD" - inet_addr: "192.168.64.10" + hardware_address: "12:34:56:78:90:AD" + ip_address: "192.168.64.10" link_encap: "Unknown" link_local6: "fe80::200:aaaa:5f4f:54f4" link_local6_prefixlen: "64" @@ -202,8 +202,8 @@ parsed_sample: tx_queue_len: "0" - bcast: "10.100.105.31" collisions: "0" - hw_addr: "12:34:56:78:90:AE" - inet_addr: "10.100.105.1" + hardware_address: "12:34:56:78:90:AE" + ip_address: "10.100.105.1" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -227,8 +227,8 @@ parsed_sample: tx_queue_len: "0" - bcast: "" collisions: "0" - hw_addr: "12:34:56:78:90:AF" - inet_addr: "" + hardware_address: "12:34:56:78:90:AF" + ip_address: "" link_encap: "Ethernet" link_local6: "" link_local6_prefixlen: "" @@ -252,8 +252,8 @@ parsed_sample: tx_queue_len: "1000" - bcast: "" collisions: "0" - hw_addr: "" - inet_addr: "127.0.0.1" + hardware_address: "" + ip_address: "127.0.0.1" link_encap: "Local Loopback" link_local6: "" link_local6_prefixlen: ""