How to get Check Conditions into Check

Hello together,
im developing a check and need some help maybe :slight_smile:

The Parameters are developed like this:

def _parameter_valuespec_mycheck_subsystem():
    return Dictionary(
            ("levels_percent", Tuple(
                title=_("Levels on Subsystem"),
                    Percentage(title=_("Warning at"), default_value=80),
                    Percentage(title=_("Critical at"), default_value=90)

I can get this values when i define my check with the params option:

def check_mycheck_subsystem(item, params, section):

But how can i get the Conditions into my check?

My Condition of the Check in WATO is this:

def _item_valuespec_mycheck_subsystem():
    return TextAscii(title=_("Subsystem Service Checks"))

But how can i get the Values from this Item into my check?
The params definition does only include my values but not the Conditions.

Maybe someone can help me with this.

Best regards :slight_smile:

I think you miss some things in your checks.

  1. You need to define the group name for the parameters set used by valuesspecs and checks:
        item_spec=lambda: TextAscii(title=_("Service name"),
                        help=_("The identifier of the service.")),
        title=lambda: _("Mycheck"),

Here you can see how the item_pec is defined. You can also set your function there.

    name = "mycheck",
    service_name = "Mycheck",
    discovery_function = discover_mycheck,
    check_function = check_mycheck,
    check_default_parameters = mycheck_default_levels,

check_ruleset_name and group_name musst be equal.

I hope it helps.
Best regards,

Thank you @ChristianM

i guess i missunderstood something in General how Conditions work :smiley:

My follow Up question now is, how can i get Check Values into my special Agent?

I have a “ListOfStrings” in my WATO Check Settings from a specific Check.

("subsystemchecks", ListOfStrings (title=_("Subsystem: Check the Following Services:"), allow_empty=True)),

        title=lambda: _("Levels for License Expiry Check"),

How can i get the params from the ListofStrings Configured here into my Special Agent, so i can tell my Agent wich Licenses the Agent should get from the System?

Hi Matthias

This is done with what I call “agent checks”.
You will have to create a file in the folder local/share/check_mk/checks that should be called agent_<something> where <something> identifies your agent.

There are numerous “agent checks” present that you may use as inspiration. You will find them named share/check_mk/checks/agent_*.

These files register the agent in the special_agent_info dict and parse a command line that should be called when executing the agent.

You have to make sure, the dict-key in special_agent_info matches the name you gave the agent in your parameter specification. For instance, if you registered the agent-spec as name="special_agents:luck_generator you will have to use luck_generator as key for special_agent_info: special_agent_info["luck_generator"] = agent_luck_generator_arguments

Template that I use with cmk 2.0
#!/usr/bin/env python3

from cmk.base.config import special_agent_info, SpecialAgentConfiguration
from cmk.base.check_api import passwordstore_get_cmdline

def agent_something_arguments(params, hostname, ipaddress):
    checks = " ".join(params["checks"]) if "checks" in params else "all"

    args = [
        for chunk in (("--username", params["username"]),
                       passwordstore_get_cmdline("%s", params["password"])),
                      ("--host", ipaddress), ("--checks", checks),
                      ("--timeout", params.get("timeout", 10)))
        for elem in chunk

    return SpecialAgentConfiguration(args, None)

    # Call cmk.utils.password_store.replace_passwords() in datasource program

special_agent_info['something'] = agent_something_arguments

Happy coding :slight_smile:

1 Like