Monitor a UPS Zen-X with a .txt file

Hello everyone,

I’m trying to monitor my UPS with CheckMK, the problem is, it is not possible to connect it in network, but only by USB port.

I installed NUT tools on a VM Debian, by a command I can receive information I need like :

  • the state of my UPS ( On battery or ONline),
  • Voltage…

I created a script bash that extracts the information I need and returns it to a txt file repeating it every minute and overwriting the file every time.

So, I’m asking if it is possible to, via CheckMK, monitor the information I have in this txt file ? So I can know if the UPS is up or down.

Thank you for your help !

Hello,

You could let your script write a spool file in the checkmk agent var directory.
See documentation about writing local checks.

regards

Michael

Hi @Obeylife10

Do I understand this correctly: the UPS is connected to the Checkmk host, just via USB, right?
As an alternative/complement to @mike1098 's suggestion, if your script that generates a text file is written to output your UPS data in a way Checkmk understands, you could just run it as local check

In Checkmk, you could configure it as a host with “No IP”, and assign with the “Host check command” rule, the output of your script as “Status”. Should work…

Thomas

@openmindz That´s an interesting Answer I want to learn more form it.
Could you please explain a little bit more in detail because I didnt understood it.
A local check always need an agent even if that agent runs locally on the monitoring host.
For the hostobject IP he could use 127.0.0.1.

BR

Michael

Hi @mike1098

Yes, but you can abuse another host’s agent to run a local check that creates piggyback data for it.
As previously stated, I assume the UPS is connected to the Checkmk host, so we can use the
agent from the Checkmk host. It could be any other host, too, doesn’t matter.

This example, is completely fake, it’s just for show:

  • A new “dummy” host, called “otherhost”:
    image

  • My fake local check, does this:

#!/bin/sh
echo "<<<<otherhost>>>>"
echo "<<<local>>>"
echo "0 Status - I'm OK"
echo "0 Voltage - I'm OK, too"
echo "<<<<>>>>"
  • And this creates “piggyback” data for me in $OMD_ROOT/var/check_mk/piggyback/otherhost:
<<<local:cached(1643199412,90)>>>
0 Status - I'm OK
0 Voltage - I'm OK, too
  • Which I can then see, as services:

  • Finally, to not ping it (because we can’t), and to use my script output as status check whether the host is UP or not, I create a “Host check command” rule, like this:

  • Done. Coffee… :slight_smile:

Thomas

1 Like

Thanks for your help guys @mike1098 @openmindz , I will try what you suggest me and I come back to you.

@openmindz What do you mean by “connected to CheckMK host” ? the UPS is connected via USB to the VM where CheckMK is installed, is that what you were asking? then yes.

Yes, that’s what I meant. Then you can use the agent running on this VM.

OK, thank you for this explanation. I was not aware that this is possible with a local check and now I also understand why you referred to NoIP option.
I would expect in case yo use NoIP option that checkmk knows automatically that a normal host check will not work anymore. Maybe I send a change request if it bother me sometimes.

regards

Michael

I’m not sure to have the Checkmkagent, I mean when I installed CheckMK, I used this Method :

So no Checkmk directory in /usr/lib but I got a check_mk directory in /opt/omd/sites/monsvrs/tmp :

It doesnt change anything right ?

Where you saved your script file ?

“Otherhost and Local” correspond to what ?

Sorry guys I’m really beginning :grinning_face_with_smiling_eyes:

Ok I understand, in my VM I have just the Checkmk server installed, not the agent, I will do it tomorrow.

Hi @Obeylife10

Yes, apparently. See the Getting Started guide, section 4, about how to install an agent.

Where to place scripts one has written to be executed as local checks, is described in the local checks part of the manual, section 2.2.

The <<<local>>> identifier, signifies to Checkmk that this is a local check. Normally, the agent adds this on its own, but in my example I’m faking the check results of a piggybacked host, which is why I had to add it explicitly, otherwise services wouldn’t show up.

The piggyback principle is explained in the corresponding part of the manual. Section 4.1 refers to its detailed inner workings, where one gets the hint I utilized to execute a check for my fake <<<<otherhost>>>> (note: four (4) arrows, not three).

You should be able to use this method to get check results for your UPS, with your script.

If it’s still unclear, scream. :slight_smile: Someone is always listening in this forum…

Thomas

There is a check plugin for NUT: GitHub - nagyrobi/check_mk-nut: my plugins for check_mk

Maybe that can be used here?

Hello everyone,

@r.sander I’m trying the check plugin as you suggested.

I installed the agent successfully, I followed the tutorial, I couldn’t download the files directly, so I had to create each file and pasted the contents, I named them like this “nut.sh” in /usr/lib/check_mk_agent/plugins
and “nut.py” in /opt/omd/versions/default/share/check_mk/checks, I made them executable both.

On the Checkmk interface > Setup > Host > New Host, I configured the host like this :

But nothing appear in my main Dashboard ? Do I have to configure something else ?

No informations about the UPS but only the computer itself

EDIT :

@openmindz I wanted to try to same method as you, I created the same script than yours, I named it “mylocalcheck” and placed it in /usr/lib/check_mk_agent/local as explained.

I created the new host, configured exactly like yours, but nothing appear in services of the host, and no “piggyback” was created in /var/check_mk. Besides there is no directory “check_mk” in /var but I supposed it has to create it by itself ?

Hi @Obeylife10

OK, would it be possible to paste your script in a posting to
take a look at it?

Thomas

#!/bin/sh
echo "<<<<otherhost>>>>"
echo "<<<local>>>"
echo "0 Status - I'm OK"
echo "0 Voltage - I'm OK, too"
echo "<<<<>>>>"

It’s exactly the same than yours, I want to see at first if local check returns something in checkmk then if it works I can adapt my script for the final result.

Hi @Obeylife10

Theoretically, after two or three executions, you should have a directory called otherhost in
$OMD_ROOT/tmp/check_mk/piggyback/. You would then need to create a host called otherhost as in my comment.

If you want to just see that it works as a (fake) local check, you would need to comment
out lines 1,2 and 5, and then you should have two new services.

Thomas

my Piggyback directory is located in "/omd/sites/monsvrs/tmp/check_mk/piggyback" and it’s empty but maybe it’s not the good one ?

When I created the host I already named it otherhost :

OK, stupid question: Is your local check, executable? :slight_smile:

You mean the script ? then yes ofc, I put a chmod +x namescript, on it