Page 1 of 1
Need help on Macro name
Posted: Wed Oct 25, 2017 1:21 pm
by bsivavani
Hi,
Can you let me know the macro name for red highlighted value (2). We would like to restart the service at SOFT 2.
Event Handler 2017-10-25 20:03:12 SERVICE EVENT HANDLER: s910a3000;test_service_restart;CRITICAL;SOFT;2;gwd_service_restart
Event Handler 2017-10-25 20:03:12 GLOBAL SERVICE EVENT HANDLER: s910a3000;test_service_restart;CRITICAL;SOFT;2;xi_service_event_handler
Service Critical 2017-10-25 20:03:12 SERVICE ALERT: s910a3000;test_service_restart;CRITICAL;SOFT;2;iphlpsvc: Stopped
Kindly advice ?
Re: Need help on Macro name
Posted: Wed Oct 25, 2017 2:11 pm
by kyang
You are probably looking for the macro of
$HOSTSTATETYPE$ or
$SERVICESTATETYPE$
The $HOSTSTATETYPE$ or $SERVICESTATETYPE$ macros will have a value of "SOFT" when event handlers are executed, which allows your event handler scripts to know when they should take corrective action. More information on event handlers can be found here
Here's the link for an explanation as well.
https://assets.nagios.com/downloads/nag ... types.html
Does this help?
Re: Need help on Macro name
Posted: Thu Oct 26, 2017 11:15 am
by bsivavani
Hi,
We would like to execute the service at SOFT 2, not in HARD and SOFT1 state.
Re: Need help on Macro name
Posted: Thu Oct 26, 2017 1:02 pm
by npolovenko
Thanks for the reference,
@kyang!
@bsivavani, Seems like the macro that you're looking for is called $SERVICESTATETYPE$ .
We would like to execute the service at SOFT 2, not in HARD and SOFT1 state.
Generally, in Nagios OK state refers to 1(SOFT STATE), WARNING is 2(soft state), and CRITICAL is 3(hard state).
Could you describe what you're trying to achieve? Seems like you want the event handler to start working after the second warning, but before the critical state?
Re: Need help on Macro name
Posted: Thu Oct 26, 2017 1:22 pm
by mcapra
In a pseudocode, to capture a SOFT 2:
Code: Select all
if(($SERVICESTATETYPE$ == 'SOFT') && ($SERVICESTATEID$ == 2)) {
// do the thing
}
Re: Need help on Macro name
Posted: Thu Oct 26, 2017 1:56 pm
by kyang
Thanks for the example
@mcapra!
@bsivavani, does this help?
Re: Need help on Macro name
Posted: Fri Oct 27, 2017 5:42 am
by bsivavani
Hi,
Thanks for the update. We have tested the suggested solution but it is not working, the macro SERVICESTATEID has different definition.
$SERVICESTATEID$ - A number that corresponds to the current state of the service: 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN.
Re: Need help on Macro name
Posted: Fri Oct 27, 2017 8:16 am
by mcapra
Ah, I've been out of the game too long
In the context of those log entries, the 2 actually represents the current attempt (
logging.c#L270-L275), eg how many times a problem state has been detected since the last OK state. See if
$SERVICEATTEMPT$ gets you what you're looking for:
Code: Select all
if(($SERVICESTATETYPE$ == 'SOFT') && ($SERVICEATTEMPT$ == 2)) {
// do the thing
}
Re: Need help on Macro name
Posted: Fri Oct 27, 2017 9:57 am
by kyang
Thanks again for the example
@mcapra!
@bsivavani, let us know if this works for you.