Writing custom plugin

Hello,

Is it possible to write a custom plugin like the:

  • Check HTTP
  • Check DNS
  • Check FTP
    etc.

located under Setup → Services

I’ve gone through the documentation, however, the only article related to custom plugins is agent based.

My main goal is to gather some data without the agent need on the server.

Thanks a ton for your time.

Have a good day/night.

Regards,

Marcus

Hi Marcus,

yes, that is possible, there are at least two possible options to achieve that.

The simple way is to create a “classical” nagios plugin that you can then integrate into checkmk with the rule “Integrate classical nagios plugin” and that is being executed on the checkmk server.
This can be any shell/python/whatever script that hast to exit with the correct format and exit code.

The second possibility is to write a so called special agent / server side call.
This would be the more checkmk way and has better integration and configuration options, but is currently not very well documented.
There are a few working implementations that use this already for 2.3, so you could go that way based on the examples.

2 Likes

Hello,

Andre, thanks a million for this. Would it be possible to provide me with some example URLs, any docs, etc. so I could get started?

The second version is more preferable for me.

Once again, thank you very much.

Regards,

Marcus

Hi Marcus,

i think Andreas Redfish Plugin is currently the best example (for the new 2.3 API) :

You have the special agent fetch the data and from it the agent based plugins will receive the monitoring data:

1 Like

Here are two examples of my plugins:

This are both active checks like the ones you mentioned.

3 Likes

Hello,

Thanks a lot, both of you, for the guidance! Appreciate it a lot.

It seems that it will be a lot harder to write such check, rather than the agent based one.

So far I understood that the main check, which will output data will be in the nagios folder, as well as the plugin render which is in ‘gui/wato/’.

Still confused about the ‘gui/metrics’ check and the check under the ‘checks’ folder.

This is regarding the comment from ’ thl-cmk’.

Thank you!

Regards,

Marcus

1 Like

Hello,

Multiple hours later and nothing. I’ve gone through the NTP plugin like a million times, through the docs and cant seem to figure out how exactly I can pass the data received from the custom plugin and to which file the data should be passed?

Currently, the structure is the following:

The actual check that will output the data is located here:

./local/lib/nagios/plugins/uptime

The check inside ./local/share/check_mk/checks/uptime has this code:

active_check_info['uptime'] = {
    'command_line': 'uptime $ARG1$',
    'argument_function': uptime_check_arguments,
    'service_description': _check_description,
    'has_perfdata': True,
}

The ‘plugins/wato’ has the actual graphical fields and:

rulespec_registry.register(
    HostRulespec(
        group=RulespecGroupActiveChecks,
        match_type='dict',
        name='active_checks:uptime',
        valuespec=_valuespec_active_checks_upt,
    )
)

The ‘plugins/metrics/’ have not been yet edited, but I can seem to figure out how the data is being passed there.

Can I pass a JSON like data structure like so:

{‘dns_resolution_time’: 0.002, ‘ttfb’: 0.169, ‘tplt’: 1.394, ‘db_err’: 0, ‘http_err’: 0, ‘unknown_err’: 0, ‘up’: 0}

Any help is greatly, greatly appreciated.

Regards,

Marcus

Please keep in mind that many people do this in their free time. So always be patient and be happy when you get a (quick) answer.

As I don’t know what you are trying to archive…

Here a sample output from the check_ntp plugin. The frist line will show up in the info line of the servise, everyting from behind the first new line (\n) to the pipe (|) will go to the service details, the values after the pipe are the perfdata, this will more or less go to the metrics. Hope this helps a bit about the struckture of a active chek output. so there is no need to pass anything…

~$ ~/local/lib/nagios/plugins/check_ntp -H 192.168.10.254
Stratum: 3, Reference ID: 194.25.134.196, Time: Tue May 28 20:32:38 2024
Stratum: 3
Ref-ID: 194.25.134.196, 
Time: Tue May 28 20:32:38 2024
Mode: server
Version: 4
Poll: 0
Precision: -21
Leap: no warning

Perfdata
Offset: 0.0020 s
Delay: 0.0018 s
Root dispersion: 0.0046 s

Timestamps:
Reference Timestamp (ref): 3925909387.043589
Origin Timestamp (org): 3925909958.5226116
Receive Timestamp (rec): 3925909958.5254507
Transmit Timestamp (xmt): 3925909958.525785
Destination Timestamp (dst): 3925909958.524705

Times
 Reference time: 1716920587.043589
 Origin time: 1716921158.5226116
 Receive time: 1716921158.5254507
 Transmit time: 1716921158.525785
 Destination time: 1716921158.524705
 | ntp_offset=0.001959562301635742;0.2;0.5; ntp_delay=0.0017590522766113281;0.2;0.5; ntp_root_dispersion=0.0045623779296875;200;500; 

Cheers
Thomas

1 Like

Thomas thanks a ton for the reply. Apologize, but with this phrase Multiple hours later and nothing. I was referring to the fact that I’ve been trying to understand how exactly I should structure this, not that I have not received a response.

I am fully aware that this is not a technical support service and each reply costs time and effort. Thus I am always grateful to every person that responds.

Once again thanks a lot for your reply. I will take this into consideration as well. The main thing which I dont understand is an example:

metric_info['ntp_offset'] = {

Where exactly the value ‘ntp_offset’ is defined as the data you provided above is not json.

Have a good night!

Regards,

Marcus

2 Likes

have a look at the perfdata. the ntp_offset is the name of one of the metrics. In the metrics file you define how cmk should handle a metric wih a given name (ie. unit, color, title or description)

2 Likes

Hello Thomas,

Apologies for once again updating this. Would it be possible, if you have spare time to let me know the following:

In the ‘local/share/check_mk/checks/’ the file must have the actual logic for executing the check right?

Therefore if I construct it as it follows:

active_check_info['monitor_uptime'] = {
    'command_line': 'monitor_uptime $ARG1$',
    'argument_function': monitor_uptime_check_arguments,
    'service_description': _check_description,
    'has_perfdata': True,
}

The command_line should contain the exact name of the python executable found here:

local/lib/nagios/plugins

If that is correct, I’ve created a test file which prints dummy data named monitor_uptime, but I get:

(Return code of 127 is out of bounds - plugin may be missing)

Also, the registration of the plugin:

rulespec_registry.register(
    HostRulespec(
        group=RulespecGroupActiveChecks,
        match_type='dict',
        name='active_checks:ntp',
        valuespec=_valuespec_active_checks_ntp,
    )
)

The name should match active_checks:monitor_uptime right?

I will be so grateful if you have time to explain to me these things.

Once again thank you!

Regards,

Marcus

Send you a PM.

Cheers
Thomas

Any updates on this topic? This seems very useful.