Skip to content

Commit 0634611

Browse files
nightwatcher74mo-ki
authored andcommitted
17522 New check plugin: Cisco UCS: Fault summary
Closes #756 CMK-20279 Change-Id: Ic526fc7069148c08980f09aed785c453a0c0a619
1 parent cb2059c commit 0634611

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

.werks/17522.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[//]: # (werk v2)
2+
# New check plugin: Cisco UCS: Fault summary
3+
4+
key | value
5+
---------- | ---
6+
date | 2025-02-11T07:32:03+00:00
7+
version | 2.4.0b1
8+
class | feature
9+
edition | cre
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
This adds a new check plugin monitoring all faults reported by the device.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
from cmk.agent_based.v2 import (
7+
CheckPlugin,
8+
CheckResult,
9+
DiscoveryResult,
10+
Result,
11+
Service,
12+
State,
13+
)
14+
from cmk.plugins.collection.agent_based.cisco_ucs_fault_section import Section
15+
from cmk.plugins.lib.cisco_ucs import check_cisco_fault
16+
17+
18+
def discover_cisco_ucs_faults(section: Section) -> DiscoveryResult:
19+
yield Service()
20+
21+
22+
def check_cisco_ucs_faults(section: Section) -> CheckResult:
23+
if not section:
24+
yield Result(state=State.OK, summary="No faults")
25+
return
26+
27+
for fault in section.values():
28+
yield from check_cisco_fault(fault)
29+
30+
31+
check_plugin_cisco_ucs_faults = CheckPlugin(
32+
name="cisco_ucs_faults",
33+
sections=["cisco_ucs_fault"],
34+
service_name="Cisco UCS Faults",
35+
discovery_function=discover_cisco_ucs_faults,
36+
check_function=check_cisco_ucs_faults,
37+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: Cisco UCS: Fault summary
2+
agents: snmp
3+
catalog: hw/network/cisco
4+
license: GPLv2
5+
distribution: check_mk
6+
7+
description:
8+
This check allows to monitor all faults reported by the device.
9+
The check will report {OK} as long as no faults are reported.
10+
In other cases, the check will report a status determined by the severity of the most severe issue:
11+
"major" and "critical" are reported as {CRITICAL}, "warning" and "minor" as {WARNING} and "cleared" and "info" as {OK}.
12+
13+
discovery:
14+
One service is created.

cmk/plugins/collection/agent_based/cisco_ucs_fault_section.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from cmk.agent_based.v2 import SimpleSNMPSection, SNMPTree, StringTable
1010
from cmk.plugins.lib.cisco_ucs import DETECT, Fault, FaultSeverity
1111

12+
type Section = dict[str, list[Fault]] # FIXME
1213

13-
def parse_cisco_ucs_fault(string_table: StringTable) -> dict[str, list[Fault]]:
14+
15+
def parse_cisco_ucs_fault(string_table: StringTable) -> Section:
1416
faults = defaultdict(list)
1517
for fault_object_id, fault_ack, fault_code, fault_description, fault_severity in string_table:
1618
faults[fault_object_id].append(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
from cmk.agent_based.v2 import Result, Service, State
7+
from cmk.plugins.cisco.agent_based.cisco_ucs_faults import (
8+
check_cisco_ucs_faults,
9+
discover_cisco_ucs_faults,
10+
)
11+
from cmk.plugins.collection.agent_based.cisco_ucs_fault_section import (
12+
parse_cisco_ucs_fault,
13+
Section,
14+
)
15+
16+
17+
def _section() -> Section:
18+
return parse_cisco_ucs_fault(
19+
[
20+
[
21+
"sys/rack-unit-1/psu-2",
22+
"1",
23+
"374",
24+
"PSU2_STATUS: Power Supply 2 has lost input or input is out of range : Check input to PS or replace PS 2",
25+
"5",
26+
]
27+
]
28+
)
29+
30+
31+
def test_discover_cisco_ucs_faults_empty() -> None:
32+
assert list(discover_cisco_ucs_faults({})) == [Service()]
33+
34+
35+
def test_discover_cisco_ucs_faults() -> None:
36+
assert list(discover_cisco_ucs_faults(_section())) == [Service()]
37+
38+
39+
def test_check_cisco_ucs_faults_empty() -> None:
40+
assert list(check_cisco_ucs_faults({})) == [Result(state=State.OK, summary="No faults")]
41+
42+
43+
def test_check_cisco_ucs_faults() -> None:
44+
assert list(check_cisco_ucs_faults(_section())) == [
45+
Result(
46+
state=State.CRIT,
47+
summary="Fault: 374 - PSU2_STATUS: Power Supply 2 has lost input or input is out of range : Check input to PS or replace PS 2",
48+
),
49+
]

0 commit comments

Comments
 (0)