Plugin template?

Hello,

is there some template for check_mk plugin?

I would like to write a plugin to monitor the Status of SIP-Trunks on Alcatel OXO PBX.

I have already a script, which can read and deliver the requested information.

I will modify the Script so, that it will accept four parameters: username, password, ip adress and name of sip trunk. I want to set these Parameters through wato. The Script will then connect to web interface and read the appropriate state of the sip trunk. The output can be “REGISTRATION FAILED” or “REGISTRATION SUCCESSFULL”.

Where can I begin? Unfortunately the documentation on check_mk web did not help me that much.

Thanks!

Hi,

have you already read this document?

https://checkmk.com/cms_devel_check_plugins.html

I suggest you first write a script that takes these 4 arguments as parameters and that returns 0 on success, 1 on warning, 2 on critical, else 3 (unknown).

You can use any programming language, but if you’re not sure then use python since most of the other plugins are written in it.

Hi,

here is my script returning desired values:

https://pastebin.com/WauPnGdR

How could I know proceed to be able to configure the script in WATO?

Thanks!

For configuration in WATO you have to develop other files on the central monitoring server in python.

Example for ~site/local/share/check_mk/web/plugins/wato/<your_filename>. It’s working in 1.5 and is not tested on 1.6. I am not sure if the reference changed for this functions.

register_check_parameters(
        subgroup_storage,
        'multipath_broken',
        _('Linux multipath broken paths'),
        Dictionary(
                elements = [
            ('broken_levels',
                Tuple(
                    title = _("Set levels on broken paths"),
                    elements = [
                                    Integer(title = _("Warning at"), default_value = 1),
                                    Integer(title = _("Critical at"), default_value = 2),
                            ]
                    ),
            ),
            ('sumpaths',
                Integer(title = _("Sum Paths"))
            ),
            ('state_if_new',
                MonitoringState(
                    default_value = 1,
                    title = _("State in case of new paths found"),
                )
            )
       ]
   ),
   None,
   match_type = 'dict',
)

Hi,

I tried to develop the file for wato, but I still do not understand how should I put it all together:

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

register_check_parameters (
    subgroup_applications,
    "alcatel_oxe_sip_trunk_status",
    _("Alcatel-Lucent OXE SIP Trunk Status"),
    Dictionary(
        title=_("Check SIP Trunk Status OXE"),
    help = _("This ruleset can be used to monitor status of SIP Trunk at Alcatel-Lucent OXE     PBX"),
        elements = [
            TextUnicode(
                title=_("Username"),
                allow_empty=False),
            TextUnicode(
                title=_("Password"),
                allow_empty=False),
            TextUnicode(
                title=_("Public Registration Domain"),
                allow_empty=False),
            ],
    ),
)

According to this article https://checkmk.com/cms_devel_check_plugins.html I want to develop an “Active Check”.

Can somebody tell me what should be the next step now to connect all together? Thanks.

I got further now. I can see my check in WATO in “Host & Service Parameters”.

But I still do not know how can I use the IP Address of target host in my script.

My check script needs in parametr -H an ip address of target host. How can I use the $HOSTADDRESS$ variable in my check script?

Thanks

As this script is more an classic active check then a checkmk check.
You cannot use the classic way with check parameters and then the checkmk check.

Take a look at the “check_tcp” https://github.com/tribe29/checkmk/blob/1.6.0/checks/check_tcp
“check_tcp” is only a checkmk plugin making the correct active check syntax for your monitoring core.
The monitoring core then is running your script.

And the options from WATO for this active check.


There the definition
def _valuespec_active_checks_tcp():
and

rulespec_registry.register(
    HostRulespec(
        group=RulespecGroupActiveChecks,
        match_type="all",
        name="active_checks:tcp",
        valuespec=_valuespec_active_checks_tcp,
    ))

If you write your own definition then it is the easiest way to take the complete import block from the start of this file :slight_smile:

Hi Andreas,
thank you for your help.

I managed to create mkp package for my plugin and run it and configure through wato, but unfortunately my script does not function in the same way as if I run it manually from CLI.

The script parses the webpage of OXE PBX and print on its output Status of desired SIP Trunk:

#./check_oxesiptrunkstatus -u user -p secret -H 192.168.2.100 -P voiceconnect.domain.de
0 SIP-TRUNK - OK: Public Registration Domain - voiceconnect.domain.de, Public DDI - f106353ecompany, Status - REGISTRATION SUCCESSFUL

But when check_mk runs the script with the same parameters, then in the script output I cannot see given “Public Registration Domain” but I always see the first PRD from the list.

Out of some reason the script does not work the same way as when I run it manually from CLI.

I also was not able to debug the command using cmk.

When I try to run:

cmk -vn --checks=check_oxesiptrunkstatus OmniPCX-Office

I get:

Check_MK version 1.6.0p10
Unknown plugin file check_oxesiptrunkstatus
Unknown plugin file check_oxesiptrunkstatus
+ FETCHING DATA
 [snmp] Execute data source
 [piggyback] Execute data source
No piggyback files for 'OmniPCX-Office'. Skip processing.
No piggyback files for '192.168.2.100'. Skip processing.
 [snmp] Execute data source
+ EXECUTING INVENTORY PLUGINS
Plugins: inv_if snmp_info snmp_os
OK - [snmp] Success, execution time 0.1 sec | execution_time=0.126 user_time=0.080 system_time=0.000 children_user_time=0.000 children_system_time=0.000 cmk_time_snmp=0.039 cmk_time_agent=0.001

Even though I can fin it in cmk -L:

$ cmk -L|grep oxesip
check_oxesiptrunkstatus                      active Check OXE SIP Trunk Status

This output looks like a local check output, not an active check.
What guide do you used to write this script? Is there somewhere the source code?

To include such a script with an SNMP device can be challenging.

Source code is here: https://pastebin.com/GS6m3dJP

I put it together using various examples, howtos and check_mk documentation.
I used this article a lot: https://www.steinkogler.org/2016/08/21/check-mk-write-your-own-active-check/

The check needs to download a web page, parse the data out of it and then evaluate the data.

Can someone have a look at it? I am almost there. My first check_mk plugin. :slight_smile: Thanks!