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

Delete inv_ipv4_addresses.py

parent 80d634c0
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2023-12-27
# File : inv_ipv4_addresses.py
#
# inventory of IPv4 address information
import ipaddress
from dataclasses import dataclass
from typing import List
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
OIDEnd,
)
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
SNMPTree,
TableRow,
exists,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
StringTable,
InventoryResult,
)
@dataclass(frozen=True)
class Ipv4Info:
address: str
broadcast: str
cidr: int
if_index: int
if_name: str
max_re_assemble: int | None
netmask: str
network: str
def parse_inv_ipv4_addresses(string_table: List[StringTable]) -> List[Ipv4Info]:
ipv4_info, if_info = string_table
interface_by_index = {if_index: if_name for if_index, if_name in if_info}
ipv4_infos = []
for ipv4_address, if_index, ipv4_netmask, ipv4_bcast, max_re_assemble in ipv4_info:
ipv4 = ipaddress.IPv4Network(address=f'{ipv4_address}/{ipv4_netmask}', strict=False)
ipv4_infos.append(
Ipv4Info(
address=str(ipv4_address),
broadcast=str(ipv4.broadcast_address),
cidr=int(ipv4.prefixlen),
if_index=int(if_index),
if_name=str(interface_by_index.get(if_index, f'unknown ({if_index})')),
max_re_assemble=int(max_re_assemble) if max_re_assemble.isdigit() else None,
netmask=str(ipv4_netmask),
network=str(ipv4.network_address),
)
)
return ipv4_infos
def inventory_ipv4_addresses(section: List[Ipv4Info]) -> InventoryResult:
path = ['networking', 'addresses']
for ipv4_info in section:
key_columns = {
'address': ipv4_info.address,
'device': ipv4_info.if_name,
}
inventory_columns = {
'broadcast': ipv4_info.broadcast,
'cidr': ipv4_info.cidr,
# 'if_index': ipv4_info.if_index,
# 'max_re_assemble': ipv4_info.max_re_assemble,
'netmask': ipv4_info.netmask,
'network': ipv4_info.network,
'type': 'ipv4',
}
yield TableRow(
path=path,
key_columns=key_columns,
inventory_columns=inventory_columns
)
register.snmp_section(
name='inv_ipv4_addresses',
parse_function=parse_inv_ipv4_addresses,
fetch=[
SNMPTree(
base='.1.3.6.1.2.1.4.20.1', # IP-MIB::ipAddrEntry
oids=[
'1', # ipAdEntAddr
'2', # ipAdEntIfIndex
'3', # ipAdEntNetMask
'4', # ipAdEntBcastAddr
'5', # ipAdEntReasmMaxSize
]
),
SNMPTree(
base='.1.3.6.1.2.1.31.1.1.1', #
oids=[
OIDEnd(), # ifIndex
'1', # ifName
]),
],
detect=exists('.1.3.6.1.2.1.4.20.1.1.*'), #
)
register.inventory_plugin(
name='inv_ipv4_addresses',
inventory_function=inventory_ipv4_addresses,
)
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