How to add custom wato parameter to a check?

I would like to integrate custom parameter for my SNMP check of check_MK. Unfornetally I dont find documentation and I dont understand how to setup rules to fit my check. I always receive a error message:

#The ruleset “checkgroup_parameters:defender_ft_stats_suspend” does not exist.

Do I need to add a rule in check_MK by the wato webinterface or do I need to fix my code? Thank you.

/opt/omd/sites/mysite/local/share/check_mk/checks/defender_ft_stats_suspend

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

factory_settings["defender_ft_stats_suspend_defaults"] = {
    'ft_stats_suspend_tranfer_limits': (5,10),
}

def inventory_defender_ft_stats_suspend(info):
    inventory = []
    for r in range(len(info)):
        inventory.append(("", None))
    return tuple(inventory)

...
reduced code
...

def check_defender_ft_stats_suspend(item, params, info):

    global state, perfdata

    warn  = params['ft_stats_suspend_tranfer_limits'][0]
    error = params['ft_stats_suspend_tranfer_limits'][1]

    stats_suspend_tranfer = int(info[0][2])

    if   (error <= stats_suspend_tranfer):
        state = 2
    elif (warn <= stats_suspend_tranfer):
        state = 1
    else:
        state = 0

    perfdata = [('ft_stats_suspend_tranfer_limits', stats_suspend_tranfer, warn, error, 0, 100)]

    output = 'Current suspend transfer: {0}\n'.format(stats_suspend_tranfer)

    return (state, output, perfdata)




# This check works on all SNMP hosts

check_info["defender_ft_stats_suspend"] = {
    'check_function':           check_defender_ft_stats_suspend,
    'inventory_function':       inventory_defender_ft_stats_suspend,
    'service_description':      'Defender FT stats suspend',
    'snmp_info':                ('.x.x.x.x.x.x', sorted(mibs_ft)),
    'group':                    'defender_ft',
    'default_levels_variable':  'defender_ft_stats_suspend_defaults',
    'has_perfdata':             True
}

/opt/omd/sites/mysite/local/share/check_mk/web/plugins/wato/defender_ft_stats_suspend

#!/usr/bin/python

import cmk.utils.defines as defines

group = "checkparams"
subgroup_defender_ft = _("defender_ft_stats_suspend")

register_check_parameters(
    subgroup_defender_ft,
    "defender_ft_stats_suspend",
    _("Defender FT Stats Suspend"),
    Dictionary(
        elements=
                [
                ('ft_stats_suspend_tranfer_limits',
                Tuple(
                    title=_('Suspend FT Transfer'),
                    elements=[
                            Integer(title=_("Warning"),   unit='', default_value=30),
                            Integer(title=_("Critical"), unit='', default_value=20),
                            ]
                    ),
                 ),
                 ],
        optional_keys=[],
    ),
    TextAscii(title = _("ascii title sm2")),
    match_type="dict",
)

I added this snippet into: /etc/check_mk/conf.d/wato/rules.mk

checkgroup_parameters.setdefault('defender_ft_stats_suspend', [])

checkgroup_parameters['defender_ft_stats_suspend'] = [
  ( {'ft_stats_suspend_tranfer_limits': (50, 60)}, [], ALL_HOSTS ),
] + checkgroup_parameters['defender_ft_stats_suspend']

The second parameter to register_check_parameters() must match the group parameter in the check_info structure. So try

register_check_parameters(
    subgroup_defender_ft,
    "defender_ft",
    _("Defender FT Stats Suspend"),
    ...
)

(Actually it’s the other way round: the group parameter in the check_info structure defines which WATO ruleset applies to the check. For example, if you build a check for temperatures you can set the group parameter to 'temperature' and thus reuse an already existing WATO rule.)

Also, remove your additions to /etc/check_mk/conf.d/wato/rules.mk. The file is written by WATO.

Try this:
#!/usr/bin/python
# -- encoding: utf-8; py-indent-offset: 4 --
register_check_parameters(
subgroup__networking,
“defender_ft”,
(“Defender FT Stats Suspend”),
Dictionary(
elements=
[
(‘ft_stats_suspend_tranfer_limits’,
Tuple(
title=
(‘Suspend FT Transfer’),
elements=[
Integer(title=(“Warning”), unit=’’, default_value=30),
Integer(title=
(“Critical”), unit=’’, default_value=20),
]
),
),
],
optional_keys=[],
),
TextAscii(title = _(“ascii title sm2”)),
match_type=“dict”,
)
You will find your Rule in Networking parameters. As Dirk mentioned: please remove your manually implemented rule first!

Hello everybody,
thank you very much for your support.

I changed register_check_parameters as you mentioned and cleaned the ruleset. Also restarted omd.
Now I can click in WATO on parameters of my service and have some more options, but still cant configure my elements.

CHECK ORIGIN AND PARAMETERS
Type of check… inventorized check
Parameters… This check is not configurable via WATO

Any tips?

You shoul look in the rules.mk if you find the new rule in it. If yes, please check your checks from command line.
Try to debug your check with “print params” and run "cmk --debug -vv ". If nothing print in the output, the used var for parameters is not correct.

Well, I checked rules.mk and cound not find the entry. I think there is the problem.

My file is saved at /opt/omd/sites/mysite/local/share/check_mk/web/plugins/wato/defender_ft_stats_suspend
(-rwxr-xr-x 1 mysite mysite).

The name of the group is the same as in register_check_parameters. I used the posted script of ChristianM.
‘group’: ‘defender_ft’,

Where should I find my rule ?
I cant find any entry in WATO - “Rule-Based Configuration of Host & Service Parameters”

I also debuged my check and returend the values of params correctly as I can see in factory settings.
(warn=5, error=10)

Hello everybody,

I could fix my problem. The solution was the missing subgroup_defender_ft definition, the file ending *.py and I removed the first line (#!/usr/bin/python).

Now I can see my parameters.

Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.