Hi,
I’m writing a plugin to monitor the status of the Rudder agent. And, this is my first attempt at writing a plugin for Check_MK that will make use of a WATO configurable ruleset. However, no matter what I try, I cannot find my rule anywhere in the web interface, so obviously I’m doing something wrong. I followed the documentation found here:
If someone could help pointing me in the right direction that would be greatly appreciated. The plugin is far from complete so I know not everything is neatly handled yet.
The code of the agent is this (rudder_agent.py):
#!/usr/bin/env python3
from .agent_based_api.v1 import *
def discover_rudder_agent(section):
yield Service()
def check_rudder_agent(params, section):
lastrun_warn = params["agent_lastrun"][0]
lastrun_crit = params["agent_lastrun"][1]
for lastrun, compliantcount, repaircount, nacount, errorcount, acompliantcount, anccout, anacount, aerr in section:
lastrun = lastrun.replace("(","").replace(")","").replace("s","")
lastrun = int(lastrun)
compliantcount = int(compliantcount)
repaircount = int(repaircount)
nacount = int(nacount)
errorcount = int(errorcount)
acompliantcount = int(acompliantcount)
anccout = int(anccout)
anacount = int(anacount)
aerr = int(aerr)
yield Metric(
name ="lastrun",
value = lastrun,
levels = (lastrun_warn,lastrun_crit)
)
yield Metric("Complientcount", compliantcount)
yield Metric("Repaircount", repaircount)
yield Metric("nacount", nacount)
yield Metric("errorcount", errorcount)
yield Metric("acomplientcount", acompliantcount)
yield Metric("anccout", anccout)
yield Metric("anacount", anacount)
yield Metric("aerrorcount", aerr)
if errorcount > 0:
yield Result (state=State.CRIT, summary="Not all directives applied")
else:
yield Result (state=State.OK, summary="No erroros found")
if lastrun >= lastrun_warn:
yield Result (state=State.WARN, summary="Last agentrun too long ago")
elif lastrun >= lastrun_crit:
yield Result (state=State.CRIT, summary="Last agentrun way too long ago")
else:
yield Result (state=State.OK, summary="Last agentrun not too long ago")
return
register.check_plugin(
name = "rudder_agent",
service_name = "Rudder Agent",
discovery_function = discover_rudder_agent,
check_function = check_rudder_agent,
check_default_parameters={'agent_lastrun' : (300,600)},
check_ruleset_name="rudder_agent",)
And for the parameter check I have this (rudder_agent-parameters.py):
from cmk.gui.i18n import _
from cmk.gui.valuespec import (
Dictionary,
Integer,
Age,
TextAscii,
)
from cmk.gui.plugins.wato import (
CheckParameterRulespecWithoutItem,
rulespec_registry,
RulespecGroupCheckParametersOperatingSystem,
RulespecGroupCheckParametersApplications,
)
def _item_valuespec_rudder_agent():
return TextAscii(title=_("Rudder agent"))
def _parameter_valuespec_rudder_agent():
return Dictionary(
elements=[
("agent_lastrun", Tuple(
title=_("Time since last run"),
help=_("This is the time elapsed since the last run of the"
" rudder agent."),
elements=[
Age(title=_("Warning over"), default_value=300),
Age(title=_("Critical over"), default_value=600),
],
)),
],
)
rulespec_registry.register(
CheckParameterRulespecWithoutItem(
check_group_name="rudder_agent",
group=RulespecGroupCheckParametersOperatingSystem,
match_type="dict",
item_spec=_item_ValueSpec_rudder_agent,
parameter_valuespec=_parameter_valuespec_rudder_agent,
title=lambda: _("Time since last run of the Rudder agent"),
))
In the graph for the “agent_lastrun” I can see the yellow warning line, defaulting to 300 seconds, but that’s about it.
Kind regards,
Louis