Skip to content

Commit 3fea373

Browse files
committed
netapp_ontap_status: Respect suppression and acknowledgements
Netapp allows to suppress and acknowledge alerts in its GUI. This change modifies netapp_ontap_status to consider all alerts that are either acknowledged or suppressed on the Netapp side as OK. If alerts are present, but all are suppressed, these will be listed in the details.
1 parent 8335bdb commit 3fea373

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

cmk/plugins/netapp/agent_based/netapp_ontap_status.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
# }
3030

3131

32+
def format_alert(alert):
33+
s = alert["name"]
34+
if alert.get("acknowledge"):
35+
s += f", acknowledged by {alert['acknowledger']}"
36+
if alert.get("suppress"):
37+
s += f", suppressed by {alert['suppressor']}"
38+
return s
39+
40+
3241
def parse_netapp_api_status(string_table: StringTable) -> Section:
3342
return [
3443
alert for line in string_table for alert in [models.AlertModel.model_validate_json(line[0])]
@@ -51,9 +60,26 @@ def check_netapp_ontap_status(section: Section) -> CheckResult:
5160
"""
5261

5362
if not section:
54-
yield Result(state=State.OK, summary="Status: OK")
63+
yield Result(state=State.OK, summary="No alerts present")
5564
else:
56-
yield Result(state=State.CRIT, summary="Status: Alerts present")
65+
alerts = [dict(alert) for alert in section]
66+
unhandled_alerts = [
67+
alert for alert in alerts if not (alert.get("acknowledge") or alert.get("suppress"))
68+
]
69+
handled_alerts = [
70+
alert for alert in alerts if alert.get("acknowledge") or alert.get("suppress")
71+
]
72+
details = "\n".join(format_alert(alert) for alert in unhandled_alerts + handled_alerts)
73+
if unhandled_alerts:
74+
yield Result(
75+
state=State.CRIT, summary="Unhandled alerts present, see details", details=details
76+
)
77+
else:
78+
yield Result(
79+
state=State.OK,
80+
summary="Alerts present, but all acknowledged or suppressed, see details",
81+
details=details,
82+
)
5783

5884

5985
check_plugin_netapp_ontap_status = CheckPlugin(

cmk/plugins/netapp/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ class AlertModel(BaseModel):
545545
"""
546546

547547
name: str
548+
acknowledge: bool
549+
acknowledger: str = ""
550+
suppress: bool
551+
suppressor: str = ""
548552

549553

550554
class SvmTrafficCountersModel(BaseModel):

tests/unit/cmk/plugins/netapp/agent_based/test_netapp_ontap_status.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,42 @@ class AlertModelFactory(ModelFactory):
2121
"alerts_models, expected_result",
2222
[
2323
pytest.param(
24-
[AlertModelFactory.build(name="alert1"), AlertModelFactory.build(name="alert2")],
25-
[Result(state=State.CRIT, summary="Status: Alerts present")],
24+
[
25+
AlertModelFactory.build(name="alert1", acknowledge=False, suppress=False),
26+
AlertModelFactory.build(name="alert2", acknowledge=False, suppress=False),
27+
],
28+
[
29+
Result(
30+
state=State.CRIT,
31+
summary="Unhandled alerts present, see details",
32+
details="alert1\nalert2",
33+
)
34+
],
2635
id="alerts present",
2736
),
2837
pytest.param(
2938
[],
30-
[Result(state=State.OK, summary="Status: OK")],
39+
[Result(state=State.OK, summary="No alerts present")],
3140
id="no alerts present",
3241
),
42+
pytest.param(
43+
[
44+
AlertModelFactory.build(
45+
name="alert1", acknowledge=True, acknowledger="hhirsch", suppress=False
46+
),
47+
AlertModelFactory.build(
48+
name="alert2", acknowledge=False, suppress=True, suppressor="hhirsch"
49+
),
50+
],
51+
[
52+
Result(
53+
state=State.OK,
54+
summary="Alerts present, but all acknowledged or suppressed, see details",
55+
details="alert1, acknowledged by hhirsch\nalert2, suppressed by hhirsch",
56+
)
57+
],
58+
id="alerts suppressed",
59+
),
3360
],
3461
)
3562
def test_check_netapp_ontap_status(

0 commit comments

Comments
 (0)