Running local scripts

Hi,

I’m trying to get a specific script to run on a monitored host. All the other usual checks are working, but this script is not returning what I want to see. On the host, the scripts run as expected:

/usr/lib/check_mk_agent/local/check_node_sync.sh
OK - Node is in sync

The check_mk_agent also picks it up:

sudo check_mk_agent | grep -A 10 ‘^<<<local’
<<local:sep(0)>>
OK - Node is in sync

But on the checkmk server, all I see is this:

Can someone please guide me in the right direction to have this sorted? Thank you!

Regards,
Rubin

Hi @rubin.j,
the output format does not seem to be quite correct. You must output 4 columns:

Status (0-3) Servicename Performancedata Plugin output
0 YourService - Node is in sync

0 = OK, 1 = WARN, 2 = CRIT

Karl

3 Likes

Hi Karl,

Thanks for your quick reply! So here’s a part of the script I’m running:

BLOCK_DIFF=$(($LATEST_BLOCK_HEIGHT - $LOCAL_BLOCK_HEIGHT))
THRESHOLD=10
if [ “$BLOCK_DIFF” -gt “$THRESHOLD” ]; then
echo “CRITICAL - Node is out of sync by $BLOCK_DIFF blocks”
exit 2
elif [ “$BLOCK_DIFF” -gt 0 ]; then
echo “WARNING - Node is out of sync by $BLOCK_DIFF blocks”
exit 1
else
echo “OK - Node is in sync”
exit 0
fi

How would you recommend I modify the output to be in an acceptable format for CheckMK?

Thanks!

Regards,
Rubin

Have a look at Local checks, it explains everything.

What you seem to have is a classical Nagios plugin with its exit codes. These can be called by the Checkmk agent via the MRPE mechanism, explained here: Monitoring Linux - The new agent for Linux in detail

1 Like

Hi,

Thanks for your reply. I’m not using Nagios at all. I just want CheckMK to pick up the values. I referred to the Local checks document and this is what my script looks like now:

if [ “$BLOCK_DIFF” -gt “$THRESHOLD” ]; then
echo “2 "Blockchain" - Node is out of sync by $BLOCK_DIFF blocks”
exit 2
elif [ “$BLOCK_DIFF” -gt 0 ]; then
echo “1 "Blockchain" - Node is out of sync by $BLOCK_DIFF blocks”
exit 1
else
echo “0 "Blockchain" - Node is in sync”
exit 0
fi

Here’s what the output looks like:

0 “Blockchain” - Node is in sync

sudo check_mk_agent | grep -A 10 ‘^<<<local’
<<local:sep(0)>>
0 “Blockchain” - Node is in sync

But now, it comes up “Unknown” on the server:

Any ideas?

The backward slash isn’t showing up on this post. But it’s definitely in my script:

image

Any help, please?

You must make a service discovery for that host. Because of your old check checkmk thought there was a check named - (just a minus/dash sign), but the actual name is Blockchain.

Also, let your script always do an exit 0, even in the WARN/CRIT cases. Any other value cause problems when the script runs asynchronously (say, every five minutes only or so). Exit values != 0 are used only if the script itself could not run properly (missing permissions or something like that).

Besides that, your local check looks okay to me.

2 Likes

That saved the day! I’ve also changed the exit codes as you suggested. Thank you very much, sir!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.