Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions cmk/plugins/netapp/agent_based/netapp_ontap_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
# }


def format_alert(alert):
s = alert["name"]
if alert.get("acknowledge"):
s += f", acknowledged by {alert['acknowledger']}"
if alert.get("suppress"):
s += f", suppressed by {alert['suppressor']}"
return s


def parse_netapp_api_status(string_table: StringTable) -> Section:
return [
alert for line in string_table for alert in [models.AlertModel.model_validate_json(line[0])]
Expand All @@ -51,9 +60,26 @@ def check_netapp_ontap_status(section: Section) -> CheckResult:
"""

if not section:
yield Result(state=State.OK, summary="Status: OK")
yield Result(state=State.OK, summary="No alerts present")
else:
yield Result(state=State.CRIT, summary="Status: Alerts present")
alerts = [dict(alert) for alert in section]
unhandled_alerts = [
alert for alert in alerts if not (alert.get("acknowledge") or alert.get("suppress"))
]
handled_alerts = [
alert for alert in alerts if alert.get("acknowledge") or alert.get("suppress")
]
details = "\n".join(format_alert(alert) for alert in unhandled_alerts + handled_alerts)
if unhandled_alerts:
yield Result(
state=State.CRIT, summary="Unhandled alerts present, see details", details=details
)
else:
yield Result(
state=State.OK,
summary="Alerts present, but all acknowledged or suppressed, see details",
details=details,
)


check_plugin_netapp_ontap_status = CheckPlugin(
Expand Down
4 changes: 4 additions & 0 deletions cmk/plugins/netapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ class AlertModel(BaseModel):
"""

name: str
acknowledge: bool
acknowledger: str = ""
suppress: bool
suppressor: str = ""


class SvmTrafficCountersModel(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,42 @@ class AlertModelFactory(ModelFactory):
"alerts_models, expected_result",
[
pytest.param(
[AlertModelFactory.build(name="alert1"), AlertModelFactory.build(name="alert2")],
[Result(state=State.CRIT, summary="Status: Alerts present")],
[
AlertModelFactory.build(name="alert1", acknowledge=False, suppress=False),
AlertModelFactory.build(name="alert2", acknowledge=False, suppress=False),
],
[
Result(
state=State.CRIT,
summary="Unhandled alerts present, see details",
details="alert1\nalert2",
)
],
id="alerts present",
),
pytest.param(
[],
[Result(state=State.OK, summary="Status: OK")],
[Result(state=State.OK, summary="No alerts present")],
id="no alerts present",
),
pytest.param(
[
AlertModelFactory.build(
name="alert1", acknowledge=True, acknowledger="hhirsch", suppress=False
),
AlertModelFactory.build(
name="alert2", acknowledge=False, suppress=True, suppressor="hhirsch"
),
],
[
Result(
state=State.OK,
summary="Alerts present, but all acknowledged or suppressed, see details",
details="alert1, acknowledged by hhirsch\nalert2, suppressed by hhirsch",
)
],
id="alerts suppressed",
),
],
)
def test_check_netapp_ontap_status(
Expand Down