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 146d9d1d authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

added drop broadcast IPs

parent d6124162
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/inv_win_if_ip-0.0.4-20241212.mkp "inv_win_if_ip-0.0.4-20241212.mkp"
[PACKAGE]: ../../raw/master/mkp/inv_win_if_ip-0.0.5-20250124.mkp "inv_win_if_ip-0.0.5-20250124.mkp"
# IP-Address inventory for Windows hosts
The plugin adds IP-address information to the inventory. The plugin supports IPv4 and IPv6, more than one IP-address per interface is supported.
......
File added
......@@ -20,6 +20,8 @@
# 2024-12-09: rewritten for CMK checkAPI 2.0
# 2024-12-10: added host label nvdct/l3v6_topology:host and nvdct/l3v6_topology:router
# 2014-12-12: fix crash in host label function if interface has no ip-address
# 2025-01-21: added drop broadcast IPs
# 2025-01-24: fixed crash on bad prefix-length (to long for the ip version i.e. 33 for ipv4)
from collections.abc import Mapping, Sequence
from ipaddress import AddressValueError, IPv4Interface, IPv6Interface, NetmaskValueError, ip_interface
......@@ -86,6 +88,16 @@ def clean_str(v: str) -> str:
CleanStr = Annotated[str, AfterValidator(clean_str)]
def is_broadcast(interface_ip: ip_interface) -> bool:
if interface_ip.version == 4 and interface_ip.network.prefixlen != 32:
if interface_ip.ip.compressed == interface_ip.network.broadcast_address.compressed:
return True
elif interface_ip.version == 6 and interface_ip.network.prefixlen != 128:
if interface_ip.ip.compressed == interface_ip.network.broadcast_address.compressed:
return True
return False
class Adapter(BaseModel):
name: CleanStr
......@@ -102,10 +114,15 @@ class Adapter(BaseModel):
for i in range(0, len(raw_address)):
try:
_ip_data.append(ip_interface(f'{raw_address[i]}/{raw_networks[i]}'))
except (AddressValueError, NetmaskValueError):
interface_ip = ip_interface(f'{raw_address[i]}/{raw_networks[i]}')
except (AddressValueError, NetmaskValueError, ValueError):
continue
if is_broadcast(interface_ip):
continue # drop broadcast IPs
_ip_data.append(interface_ip)
return _ip_data
@computed_field
......
......@@ -17,7 +17,7 @@
'cmk_addons_plugins': ['inv_ip_address/agent_based/inv_win_ip_address.py']},
'name': 'inv_win_if_ip',
'title': 'Inventory for IP-addresses of Windows hosts',
'version': '0.0.4-20241212',
'version': '0.0.5-20250124',
'version.min_required': '2.3.0b1',
'version.packaged': 'cmk-mkp-tool 0.2.0',
'version.usable_until': '2.4.0b1'}
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