Skip to content

Commit

Permalink
16746 FIX infoblox_service: Add support for NIOS 9.X
Browse files Browse the repository at this point in the history
Change-Id: I9bd0cd030af895d630f791f37326d47e00755b26
  • Loading branch information
si-23 committed Jul 9, 2024
1 parent 2789858 commit 481484a
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 27 deletions.
16 changes: 16 additions & 0 deletions .werks/16746.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[//]: # (werk v2)
# infoblox_service: Add support for NIOS 9.X

key | value
---------- | ---
date | 2024-06-18T08:00:25+00:00
version | 2.4.0b1
class | fix
edition | cre
component | checks
level | 1
compatible | no

With newer infoblox NIOS devices the `IB-PLATFORMONE-MIB::IBServiceName` have
changed. We use these name as service items. Please run a re-discovery on the
affected hosts.
130 changes: 109 additions & 21 deletions cmk/plugins/collection/agent_based/infoblox_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"""Infoblox services and node services
"""

from collections.abc import Sequence
from collections.abc import Mapping, Sequence
from dataclasses import dataclass

from cmk.agent_based.v2 import (
any_of,
Expand All @@ -29,7 +30,7 @@
startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.7779.1."),
)

SERVICE_ID = {
SERVICE_ID_lower_v9 = {
"1": "dhcp",
"2": "dns",
"3": "ntp",
Expand Down Expand Up @@ -92,6 +93,67 @@
"60": "bfd",
"61": "outbound",
}
SERVICE_ID_v9 = {
"1": "dhcp",
"2": "dns",
"3": "ntp",
"4": "tftp",
"5": "http-file-dist",
"6": "ftp",
"7": "node-status",
"8": "disk-usage",
"9": "enet-lan",
"10": "enet-lan2",
"11": "enet-ha",
"12": "enet-mgmt",
"13": "lcd",
"14": "memory",
"15": "replication",
"16": "db-object",
"17": "raid-summary",
"18": "raid-disk1",
"19": "raid-disk2",
"20": "raid-disk3",
"21": "raid-disk4",
"22": "raid-disk5",
"23": "raid-disk6",
"24": "raid-disk7",
"25": "raid-disk8",
"26": "fan1",
"27": "fan2",
"28": "fan3",
"29": "fan4",
"30": "fan5",
"31": "fan6",
"32": "fan7",
"33": "fan8",
"34": "power-supply1",
"35": "power-supply2",
"36": "ntp-sync",
"37": "cpu1-temp",
"38": "cpu2-temp",
"39": "sys-temp",
"40": "raid-battery",
"41": "cpu-usage",
"42": "ospf",
"43": "bgp",
"44": "mgm-service",
"45": "subgrid-conn",
"46": "network-capacity",
"47": "reporting",
"48": "dns-cache-acceleration",
"49": "ospf6",
"50": "swap-usage",
"51": "discovery-consolidator",
"52": "discovery-collector",
"53": "discovery-capacity",
"54": "threat-protection",
"55": "cloud-api",
"56": "threat-analytics",
"57": "taxii",
"58": "bfd",
"59": "outbound",
}
STATUS_ID = {
"1": "working",
"2": "warning",
Expand All @@ -107,27 +169,40 @@
}


@dataclass(frozen=True)
class _Version:
major: int
minor: int
patch: int


def _parse_version(raw_version: Sequence[Sequence[str]]) -> _Version | None:
try:
version = raw_version[0][0]
except IndexError:
return None
parts = version.split("-")[0].split(".")
try:
return _Version(int(parts[0]), int(parts[1]), int(parts[2]))
except (IndexError, ValueError):
return None


def _find_service_id_map(version: _Version | None) -> Mapping[str, str]:
# See:
# - https://docs.infoblox.com/space/nios85/35418019/SNMP+MIB+Hierarchy ff.
# - https://docs.infoblox.com/space/nios90/280760493/SNMP+MIB+Hierarchy
if not version:
return SERVICE_ID_lower_v9
return SERVICE_ID_v9 if version.major >= 9 else SERVICE_ID_lower_v9


def parse_infoblox_services(string_table: Sequence[StringTable]) -> Section:
"""
>>> for item, status in parse_infoblox_services([[
... ['9', '1', 'Running'],
... ['10', '1', '2% - Primary drive usage is OK.'],
... ['11', '1', '11.112.133.14'],
... ['27', '5', ''],
... ['28', '1', 'FAN 1: 8725 RPM'],
... ['43', '1', 'CPU Usage: 5%'],
... ['57', '5', 'Cloud API service is inactive.'],
... ]]).items():
... print(item, status)
node-status ('working', 'Running')
disk-usage ('working', '2% - Primary drive usage is OK.')
enet-lan ('working', '11.112.133.14')
fan1 ('working', 'FAN 1: 8725 RPM')
cpu-usage ('working', 'CPU Usage: 5%')
"""
raw_version, table = string_table
service_id_map = _find_service_id_map(_parse_version(raw_version))
return {
SERVICE_ID[service_id]: (status, description)
for service_id, status_id, description in string_table[0]
service_id_map[service_id]: (status, description)
for service_id, status_id, description in table
for status in (STATUS_ID.get(status_id, "unexpected"),)
if status not in {"inactive", "unknown"}
}
Expand Down Expand Up @@ -170,6 +245,12 @@ def check_infoblox_services(item: str, section: Section) -> CheckResult:
detect=DETECT_INFOBLOX,
parse_function=parse_infoblox_services,
fetch=[
SNMPTree(
base=".1.3.6.1.4.1.7779.3.1.1.2.1",
oids=[
"7", # IB-PLATFORMONE-MIB::ibNiosVersion
],
),
SNMPTree(
base=".1.3.6.1.4.1.7779.3.1.1.2.1.9.1",
oids=[
Expand All @@ -188,11 +269,18 @@ def check_infoblox_services(item: str, section: Section) -> CheckResult:
check_function=check_infoblox_services,
)


snmp_section_infoblox_node_services = SNMPSection(
name="infoblox_node_services",
detect=DETECT_INFOBLOX,
parse_function=parse_infoblox_services,
fetch=[
SNMPTree(
base=".1.3.6.1.4.1.7779.3.1.1.2.1",
oids=[
"7", # IB-PLATFORMONE-MIB::ibNiosVersion
],
),
SNMPTree(
base=".1.3.6.1.4.1.7779.3.1.1.2.1.10.1",
oids=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
Section,
)

example_snmp_string_table = [
example_snmp_string_table_lower_v9 = [
[["8.0.0"]],
[
["9", "1", "Running"],
["10", "1", "2% - Primary drive usage is OK."],
Expand Down Expand Up @@ -66,10 +67,85 @@
["55", "1", "0% - Discovery capacity usage is OK."],
["56", "5", "Threat Protection Service is inactive"],
["57", "5", "Cloud API service is inactive."],
]
],
]

example_parsed_data = {
example_snmp_string_table_v9 = [
[["9.0.0"]],
[
["7", "1", "Running"],
["8", "1", "2% - Primary drive usage is OK."],
["9", "1", "11.112.133.14"],
["10", "5", ""],
["11", "5", ""],
["12", "1", "11.112.133.204"],
["13", "5", ""],
["14", "1", "14% - System memory usage is OK."],
["15", "1", "Online"],
["16", "1", "16% - Database capacity usage is OK."],
["17", "5", ""],
["18", "5", ""],
["19", "5", ""],
["20", "5", ""],
["21", "5", ""],
["22", "5", ""],
["23", "5", ""],
["24", "5", ""],
["25", "5", ""],
["26", "1", "FAN 1: 8725 RPM"],
["27", "1", "FAN 2: 8725 RPM"],
["28", "1", "FAN 3: 8725 RPM"],
["29", "5", "Fan does not exist"],
["30", "5", "Fan does not exist"],
["31", "5", "Fan does not exist"],
["32", "5", "Fan does not exist"],
["33", "5", "Fan does not exist"],
["34", "1", "Power1 OK"],
["35", "5", "No power information available."],
["36", "1", "The NTP service resumed synchronization."],
["37", "1", "CPU_TEMP: +36.00 C"],
["38", "5", "No temperature information available."],
["39", "1", "SYS_TEMP: +34.00 C"],
["40", "5", ""],
["41", "1", "CPU Usage: 5%"],
["42", "4", ""],
["43", "4", ""],
["44", "5", ""],
["45", "5", ""],
["46", "5", ""],
["47", "5", "Reporting Service is inactive"],
["48", "5", ""],
["49", "4", ""],
["50", "1", "0% - System swap space usage is OK."],
["51", "5", "Discovery Consolidator Service is inactive"],
["52", "5", "Discovery Collector Service is inactive"],
["53", "1", "0% - Discovery capacity usage is OK."],
["54", "5", "Threat Protection Service is inactive"],
["55", "5", "Cloud API service is inactive."],
],
]

example_parsed_data_lower_v9 = {
"node-status": ("working", "Running"),
"disk-usage": ("working", "2% - Primary drive usage is OK."),
"enet-lan": ("working", "11.112.133.14"),
"enet-mgmt": ("working", "11.112.133.204"),
"memory": ("working", "14% - System memory usage is OK."),
"replication": ("working", "Online"),
"db-object": ("working", "16% - Database capacity usage is OK."),
"fan1": ("working", "FAN 1: 8725 RPM"),
"fan2": ("working", "FAN 2: 8725 RPM"),
"fan3": ("working", "FAN 3: 8725 RPM"),
"power-supply1": ("working", "Power1 OK"),
"ntp-sync": ("working", "The NTP service resumed synchronization."),
"cpu1-temp": ("working", "CPU_TEMP: +36.00 C"),
"sys-temp": ("working", "SYS_TEMP: +34.00 C"),
"cpu-usage": ("working", "CPU Usage: 5%"),
"swap-usage": ("working", "0% - System swap space usage is OK."),
"discovery-capacity": ("working", "0% - Discovery capacity usage is OK."),
}

example_parsed_data_v9 = {
"node-status": ("working", "Running"),
"disk-usage": ("working", "2% - Primary drive usage is OK."),
"enet-lan": ("working", "11.112.133.14"),
Expand All @@ -93,7 +169,8 @@
@pytest.mark.parametrize(
"string_table,expected_parsed_data",
[
(example_snmp_string_table, example_parsed_data),
(example_snmp_string_table_lower_v9, example_parsed_data_lower_v9),
(example_snmp_string_table_v9, example_parsed_data_v9),
],
)
def test_parse_infoblox_services(
Expand All @@ -105,7 +182,8 @@ def test_parse_infoblox_services(
@pytest.mark.parametrize(
"section,result",
[
(example_parsed_data, [Service(item=key) for key in example_parsed_data]),
(example_parsed_data_lower_v9, [Service(item=key) for key in example_parsed_data_lower_v9]),
(example_parsed_data_v9, [Service(item=key) for key in example_parsed_data_v9]),
],
)
def test_discovery_infoblox_services(section: Section, result: DiscoveryResult) -> None:
Expand All @@ -117,7 +195,12 @@ def test_discovery_infoblox_services(section: Section, result: DiscoveryResult)
[
(
"memory",
example_parsed_data,
example_parsed_data_lower_v9,
[Result(state=State.OK, summary="Status: working (14% - System memory usage is OK.)")],
),
(
"memory",
example_parsed_data_v9,
[Result(state=State.OK, summary="Status: working (14% - System memory usage is OK.)")],
),
],
Expand Down

0 comments on commit 481484a

Please sign in to comment.