How to execute simple checks with multiple services at once on the checkmk host iself?

I have checkmk raw installed via docker.

Now I would like to add simple checks for a host (e.g. “gate”), for example “Service1”, “Service2”, “Service3”. I know I could put them into legacy nagios scripts but this means each service is executed individually. For performance reasons, I would like to output all service results at once (in one call), similar to how it’s possible with piggyback.

Which means technically I could pick another random host with check-mk-agent installed and run the checl there via piggyback. However, I really want to run the script within the docker container of the checkmk host itself.

What is the best way for this?

Local checks should fit your needs: Local checks

Indeed this would be exactly what I’d be looking for but as I understand, this could be executed on a different host with check -mk-agent installed. But I’d really like to run it on the checkmk host (inside the raw docker container) itself.

I am not sure if and how this works on checkmk host, for example, in which directory to put the local check script and how to enable it.

Do you have any info on this?

My insights on this:

If a/the services are like obtainable from an API of some kind ( http/https/rest/etc.)

  • use a datasource program (see Datasource programs, it is executed from the cmk monitoring host.

If there is no way to retrieve the information externally from a/the monitored host, use a localcheck ( link to docs of those was already given above)

For a simple Datasource program grabbing information from a http-source take a look at:
Datasource P1 program

  • Glowsome

IIRC, when using a data source program, other ways of obtaining agent data for a host are not possible. I will check whether this limitation still exists. If this is no problem, using a data source program that emits a local section (as in this example) might be a way to go.

If execution is not needed once a minute and/or other means of data retrieval are needed, you might deploy a cronjob writing local spool files that contain a piggyback section that contains a local section.

Sounds weird? It isn’t. Would look like:

<<<<some.host.name.test>>>>
<<<local>>>
0 "Spool Test Dummy" - This static service is always OK
<<<<>>>>

No, it’s not. I actually want to write custom checks for my Mikrotik router (the existing Mikrotik extension and SNMP are not enough). So, It’s a python script which already successfully runs on the monitoring host (inside the docker container). Question is just how to make the script called.

Apologies, maybe I have a misunderstanding here. Yes, I am using local checks but they are executed by the check-mk-agent, right? And check-mk-agent runs on some other host (usually the host to be monitored). But I want to execute the script on the monitoring host (checkmk raw docker container) itself. Does it include agent functionality? If so, how?

The script itself is not the issue and probably I would also be able to execute a script for a single service. But, I want to output the results of multiple services in a simple command run, similar as piggyback.

Let me clarify again: The host to be monitored is “gate01” and does not have any agents running (it’s a proprietary system).

On the monitoring host (i.e., the checkmk system itself) is a script that outputs the following:

OMD[cmk]:~$ /omd/sites/cmk/local/lib/nagios/plugins/mikrotik_inactive
<<<<gate01>>>>
<<<local>>>
0 BFD - All sessions up
0 Internet - OK to 8.8.8.8
2 DefaultRoute - No active default route
OMD[cmk]:~$
<<<<>>>>

I want the services BFD, Internet and DefaultRoute show up as individual services of host “gate01”

What do I need to do that script mikrotik_inactive is executed on the monitoring host?

EDIT: Ok, I understand now what you mean. Indeed, “Datasource program” would work with the exception of @mschlenker 's remark:

IIRC, when using a data source program, other ways of obtaining agent data for a host are not possible.

Because the host does have other data sources as well.

Yes, exactly such script exists already (see above). My question is just how it’s being executed.

But the “local spool” is again a feature of the check-mk-agent, not the checkmk monitoring server, right? I want to use the latter.

Using cron itself (putting the script in /etc/cron.d and writing to spool file) isn’t my preferred option but might work in the worst case.

Ok, you have just with your reply totally confused me here in regards of your reply.

As you had not stated such detail in your question, but did in your answer i will have adapt my answer:

As you have specified (in your answer) you are wanting to (as far as i understand) monitor parts of a microtik device which are not currently (assumption) monitored by the list of plugins listed on CheckMK Exchange.

It would be my suggestion to take a look at those already created extensions/plugins, and if they are missing something which you require to use these as a starting-point, and then add the functionality you are missing.

A lot of participants on the forum would gladly help you to achieve your goal here (including me).

Hope this puts you on the path to solve this after having specified your case more in detail.

  • Glowsome

Right

Parts of the reason why I was so hesitant mentioning Mikrotik is because I was afraid I will be pointed to the CheckMK exchange and existing packages.

  • Mikrotik is just one example. I have more similar checks planned like “smart managed” switches and more exotic applications
  • Yes I could extend something but it doesn’t really make sense. My intention is to run custom check scripts. For example, ping through a specific interface with ttl=1, check traceroute results executed to different destinations in different VRFs etc
  • Reason why I picked CheckMK in the first place is because everyone was saying how easy it is to just add simple, no frills check scripts. Unfortunately doesn’t seem to be as simple.
  • Packages and custom API extensions add so much complexity: Many different files, WATO etc. Even just installing them is complex (on the raw edition at least). Quite some overhead when all I want is to execute a simple script

EDIT: Of all the sub-optimal choices I think “data source program” seems the best of the worst choices. If I understand correctly, I am giving up the option to use it together with the normal agent on the same host but piggyback and APIs would still work.

To run this script on the CheckMK host you need to install the CheckMK Agent on the host (which you normaly should have already as checking the host itself always make sense). Than you can just place it in the local folder of the agent. I do this for a couple of checks and it works fine. Be aware that using piggyback in local checks is not a documented feature (but it works :slight_smile: )