Can't pass macros to service check

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
bshellrude
Posts: 4
Joined: Tue Nov 27, 2012 1:35 pm

Can't pass macros to service check

Post by bshellrude »

Hi all... having a problem that's driving me absolutely crazy.

Here's the quick and dirtly. We're primarily monitoring network devices, and for that we're taking syslog and snmp traps as passive checks into Nagios. We also - naturally - have a number of devices that we don't want to be paged on after hours... however, we do want to know about the issue by way of notification when the notification period becomes valid again. In addition, the notifications are also used to automatically create service desk tickets for problem tracking.

Given these checks are passive, and not being received on a regular basis from an agent - for instance a state change is only done when a new syslog of snmp trap is received and passed Nagios.

My initial understanding from the Nagios documentation was that if a service was in non-OK state when the notification period became valid, that a notification would be generated. It seems that this is not the case according to Nagios XI Support, that we would need to continue to receive "updates" from the agent as a pseudo "active check" and that then when the first update from the agent during the valid notification period would then create a notification. So.... the solution put forward by support was to use freshness checking... and therein is the problem...

Typically, we would be using "check_dummy" to do this, which normally would take two arguments, stateid (0-3), and optional text. However this still doesn't really fix the problem, as regardless of whether I told check_dummy to submit an OK state or a "non-OK - results are stale" state, I'll still lose the original information and state from the initial alert.

My thought then was to use some nagios macros to pass the previous stateid and status output to the check_dummy plugin for consumption by Nagios.

So the thought was to use freshness checking with the check definition as $USER1$/check_dummy $LASTSERVICESTATEID$ $SERVICEOUTPUT$

Unfortunately it seems that despite the macro matrix stating that those two macros can be used in service checks, it seems not to be passing the data to the check. I've even tried creating a quick little bash script that echos the values of those macros to verify I was actually getting the info, and the results are NULL...

So... any ideas as to A) why isn't nagios passing the values of those macros to the check command, and; B) is there another way anyone can think of that I might accomplish what I'm trying to do?

Any help would be very helpful!!

Thanks

Ben
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Can't pass macros to service check

Post by sreinhardt »

I had no issues with either check_dummy or a script i quickly wrote to do the same thing. Both should also return performance data if needed.

My script (return_last_result):

Code: Select all

#!/bin/sh
echo $2
exit $1

Code: Select all

Nagios Command: $USER1$/return_last_result $SERVICESTATEID$ "$SERVICEOUTPUT$"
Nagios Command: $USER1$/check_dummy $SERVICESTATEID$ "$SERVICEOUTPUT$"
The only problem with check_dummy is that it adds the state(ok, warning...) to the beginning of the return comment, so you can run into a string of status instead of important information. My script does not do this. Also you do not want to use the LASTSERVICESTATEID as it is not the current, but the previous one that is not shown.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
rokborn
Posts: 3
Joined: Mon Nov 23, 2015 10:13 pm

Re: Can't pass macros to service check

Post by rokborn »

Hello sreinhardt,

I am aware this post is from sometime ago, but I am facing the same issue and I need to find a solution. I have tried to implement your solution but I admit I do not exactly know how to do it. Is this:

#!/bin/sh
echo $2
exit $1

a script on its own? And how you implement this into a service check? I have tried it in different ways without luck.

Thanks for any inside you can give me.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Can't pass macros to service check

Post by rkennedy »

As this is an older thread, can you provide more information about what exactly you're running into?

Not all issues are the same, so please explain what you're trying to accomplish, and the problems you're currently facing. Screenshots will help as well.

Code: Select all

#!/bin/sh
echo $2
exit $1
This script just takes the $2 input from a bash script, and exits with the code of $1.
Former Nagios Employee
Locked