Skip to content

Commit

Permalink
MSSQL Databases Recovery Model check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma7h1 committed Jun 7, 2024
1 parent 6d9e51b commit 587be51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 20 additions & 1 deletion cmk/gui/plugins/wato/check_parameters/mssql_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
rulespec_registry,
RulespecGroupCheckParametersApplications,
)
from cmk.gui.valuespec import Dictionary, MonitoringState, TextInput
from cmk.gui.valuespec import Dictionary, DropdownChoice, MonitoringState, TextInput


def _parameter_valuespec_mssql_databases():
Expand Down Expand Up @@ -56,7 +56,26 @@ def _parameter_valuespec_mssql_databases():
optional_keys=[],
),
),
(
"recovery_model",
DropdownChoice(
title=_("Setting a specific recovery model for the database"),
choices=[
("FULL", _("Full")),
("SIMPLE", _("Simple")),
("BULK-LOGGED", _("Bulk-logged")),
],
),
),
(
"if_not_reco_model",
MonitoringState(
title=_("Criticality if not choosen Recovery Model is not set"),
default_value=1,
),
),
],
optional_keys=["recovery_model", "if_not_reco_model"],
)


Expand Down
11 changes: 10 additions & 1 deletion cmk/plugins/mssql/agent_based/mssql_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def check_mssql_databases(
return
state_int = params.get("map_db_states", {}).get(db_state.replace(" ", "_").upper(), 0)
yield Result(state=State(state_int), summary="Status: %s" % db_state)
if should_be_reco_model := params.get("recovery_model"):
if should_be_reco_model == data["Recovery"]:
yield Result(state=State.OK, summary="Recovery: %s" % data["Recovery"])
else:
yield Result(
state=State(params["if_not_reco_model"]),
summary=f"Recovery: {data['Recovery']} (but should {should_be_reco_model})",
)

yield Result(state=State.OK, summary="Recovery: %s" % data["Recovery"])

for what in ["close", "shrink"]:
Expand All @@ -110,7 +119,7 @@ def cluster_check_mssql_databases(
service_name="MSSQL %s Database",
discovery_function=discover_mssql_databases,
check_function=check_mssql_databases,
check_default_parameters={},
check_default_parameters={"if_not_reco_model": 1},
check_ruleset_name="mssql_databases",
cluster_check_function=cluster_check_mssql_databases,
)

0 comments on commit 587be51

Please sign in to comment.