Monitor weather site with checkmk and curl/jq

Hi,

I am trying to monitor the temperature through an online weatherservice, using curl and jq. I have created a bash script as a local check and put it in /lib/check_mk_agent/plugins/.
Edit: It is in the /usr/lib/check_mk_agent/local directory.

From the monitored host it works fine calling the script directly on the commandline and when I run the check_mk_agent it also works.

The plugin is discovered in CheckMK, and is receiving content, but for some reason the value (temperature) gathered by curl and jq is not passed to the CheckMK Server. Everything else is.

The content is sent from bash as:

echo “P "Temperature" myvalue=$value;20;30 It is $value degrees outside”

Should also note that the Checkmk Server it self does not have access to internet via curl.

I hope someone in this forum have an idea to what causes this :slight_smile:

Hi,

local checks should be placed at: /usr/lib/check_mk_agent/local/ directory

When you call the check_mk_agent you should see your script output below the <<<local>>> part of the agent like:

check_mk_agent | grep -v grep | grep -A2 "<<<local"
<<<local>>>
P "Temperature" myvalue=25;20;30 It is 25 degrees outside

Further details at: Local checks

Hi,
can you show your script?

Karl

Hi,

The script is located in /usr/lib/check_mk_agent/local, it was a typo :slight_smile:

Here is the output from your command at my host:

$ check_mk_agent | grep -v grep | grep -A2 "<<<local"
<<<local:sep(0)>>>
P "Temperature" count=8.4;20;30 It is 8.4 degrees outside

Strange thing though, if I collect the temperature to a file, with crontab each hour, and then read it from the file instead, it works fine :thinking:

Hi, of course, here it is:

#!/bin/sh

count=$(curl 'https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=60.38721&lon=5.97101&altitude=500' | jq .properties.timeseries[1].data.instant.details.air_temperature)

echo "P \"Temperature\" count=$count;20;30 It is $count degrees outside"

Hi @ronny.gronsdal,
I tested your script on Checkmk 2.1.0p26. That’s the result:

It work’s for me.

Karl

hi @kdeutsch, that sure is strange…

Can I ask if your checkmk server have access to internet, i.e. can it ping api.met.no?

Ronny

Hi @ronny.gronsdal,
Checkmk server and monitored host are the same und have access to internet.

Karl

Hi @ronny.gronsdal,
I modified your script a little bit to use piggyback data. This works for me also:

#!/bin/sh

count=$(curl -s 'https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=60.38721&lon=5.97101&altitude=500' | jq .properties.timeseries[1].data.instant.details.air_temperature)

echo "<<<local:sep(0)>>>" > /var/lib/check_mk_agent/spool/weather
echo "P Temperature count=$count;20;30 It is $count degrees outside" >> /var/lib/check_mk_agent/spool/weather
echo "<<<>>>" >> /var/lib/check_mk_agent/spool/weather

Karl

There might be an issue with the empty line, please get rid of this and also be aware there might be an issue with DOT’s in the output.

Output should look like this:

<<<local>>>
P "Temperature" count=8.4;20;30 It is 8.4 degrees outside

Issue with DOT in the output (?)
Check this Thread - Item not found in monitoring data even though it's there

@dabrain I removed the empty line, but it still not giving me any data on the temperature.
Also, if I put in a static number or read it from a file it is ok, even with a dot in it.

I will check the thread :ok_hand:

I am fairly new to checkmk :slight_smile: , Can you please explain to me how I go about using your modified script @kdeutsch?

1 Like

Hi @ronny.gronsdal,

replace your script with mine in /usr/lib/check_mk_agent/local. You should also change the first line to #!/bin/bash.

Karl

Hi @kdeutsch,

Sorry to say, but it did not work. Same result

Ronny

Hi @ronny.gronsdal,
too bad - your script works fine for me. Let me know if you have found a solution.

Karl

I suspect something with permissions or network, so I will investigate further and update this thread.

Thank you for answering and helping me troubleshoot, @kdeutsch and @dabrain :slight_smile:

Ronny

1 Like