Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 55664273 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

better handling of raw_address length

parent 58acdfe9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -23,7 +23,9 @@
# added support for ipv6z address type
# fixed duplicate ip information in section
# added host label nvdct/l3v6_topology:host and nvdct/l3v6_topology:router
# 2024-12-14: fixed crash if raw_ip_address is longer than raw_length (fortinet_2), ends with interface index
# 2024-12-14: fixed crash if raw_address is longer than raw_length (fortinet_2), ends with interface index
# better handling of raw_address length
# fixed crash in IBM raw_address format (dec_ip_address index out of range)
from collections.abc import Mapping, MutableSequence, Sequence
from ipaddress import AddressValueError, NetmaskValueError, ip_interface
......@@ -151,22 +153,22 @@ def parse_inv_ip_addresses(string_table: List[StringByteTable]) -> Section:
raw_type, raw_length, raw_address = raw_ip.groups()
if dec_ip_address:
raw_address = '.'.join(str(dec_ip_address[x]) for x in range(0, int(raw_length) - 1))
raw_address = '.'.join(str(x) for x in dec_ip_address)
raw_length = str(len(dec_ip_address))
match raw_type:
case '1': # IPv4 address
if raw_length == '4':
raw_address = '.'.join(x for x in raw_address.split('.')[0: int(raw_length)])
raw_address = '.'.join(x for x in raw_address.split('.')[0:4])
if raw_length == '15':
raw_address = ''.join([chr(int(x)) for x in raw_address.split('.')])
raw_address = '.'.join([str(int(x)) for x in raw_address.split('.')])
case '2': # IPv6 address
match raw_length:
case '16':
raw_address = [f'{int(x):02x}' for x in raw_address.split('.')[0: int(raw_length)]]
raw_address = [f'{int(x):02x}' for x in raw_address.split('.')[0:16]]
raw_address = ':'.join(
[''.join([raw_address[i], raw_address[i + 1]]) for i in range(0, len(raw_address), 2)]
[''.join([raw_address[i], raw_address[i + 1]]) for i in range(0, 16, 2)]
)
case '39':
raw_address = ''.join([chr(int(x)) for x in raw_address.split('.')])
......@@ -182,7 +184,7 @@ def parse_inv_ip_addresses(string_table: List[StringByteTable]) -> Section:
raw_address = [f'{int(x):02x}' for x in raw_address.split('.')]
scope_id = '.'.join(raw_address[16:])
raw_address = ':'.join(
[''.join([raw_address[i], raw_address[i + 1]]) for i in range(0, len(raw_address) - 4, 2)]
[''.join([raw_address[i], raw_address[i + 1]]) for i in range(0, 16, 2)]
)
raw_address += f'%{scope_id}'
case _:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment