Help with MACRO LASTSERVICESTATE
Help with MACRO LASTSERVICESTATE
Hello,
We have defined a service who use macro $LASTSERVICESTATE$.
We want the plugin to alternatively return a OK and WARNING state.
He get le content of $LASTSERVICESTATE$ and force the new state like this : if last eq OK then new = WARNING, if last eq WARNING then new = OK
It don't works as we would, but by couple of 2 same results (OK OK or WARN WARN)
Here the result of 5 last checks :
Time last new
17:00 OK WARNING
17:05 OK WARNING
17:10 WARNING OK
17:15 WARNING OK
17:20 OK WARNING
We would have this result :
Time last new
17:00 OK WARNING
17:05 WARNING OK
17:10 OK WARNING
17:15 WARNING OK
17:20 OK WARNING
Thank's for help
We have defined a service who use macro $LASTSERVICESTATE$.
We want the plugin to alternatively return a OK and WARNING state.
He get le content of $LASTSERVICESTATE$ and force the new state like this : if last eq OK then new = WARNING, if last eq WARNING then new = OK
It don't works as we would, but by couple of 2 same results (OK OK or WARN WARN)
Here the result of 5 last checks :
Time last new
17:00 OK WARNING
17:05 OK WARNING
17:10 WARNING OK
17:15 WARNING OK
17:20 OK WARNING
We would have this result :
Time last new
17:00 OK WARNING
17:05 WARNING OK
17:10 OK WARNING
17:15 WARNING OK
17:20 OK WARNING
Thank's for help
Re: Help with MACRO LASTSERVICESTATE
What exactly are you looking to achieve? At this point it sounds like you don't even need to run a check against the service?We want the plugin to alternatively return a OK and WARNING state.
Former Nagios Employee
Re: Help with MACRO LASTSERVICESTATE
Hello,
Our client use a broker HP BSM and want to control if alert are well take by BSM.
So he demand us an alternate state to create a refresh in BSM every 5mn
We want to use LASTSERVICESTATE to be independant of flag file or other method
Thank's
Our client use a broker HP BSM and want to control if alert are well take by BSM.
So he demand us an alternate state to create a refresh in BSM every 5mn
We want to use LASTSERVICESTATE to be independant of flag file or other method
Thank's
Re: Help with MACRO LASTSERVICESTATE
Why don't you handle this logic in the script itself? For instance:
Example script:
Otherwise I'm not sure why your current isn't working. Would you post it so that we could take a look?
Code: Select all
jolson-PC:[~]:$ echo 'OK' > /testfile
jolson-PC:[~]:$ cat /testfile
OK
jolson-PC:[~]:$ ./alternate.sh
jolson-PC:[~]:$ echo $?
0
jolson-PC:[~]:$ ./alternate.sh
jolson-PC:[~]:$ echo $?
1
jolson-PC:[~]:$ ./alternate.sh
jolson-PC:[~]:$ echo $?
0
jolson-PC:[~]:$ ./alternate.sh
jolson-PC:[~]:$ echo $?
1
Code: Select all
#!/bin/bash
File="/testfile"
if grep -q Warning "$File"; then
sed -i 's/Warning/OK/g' "$File"
exit 1
elif grep -q OK "$File"; then
sed -i 's/OK/Warning/g' "$File"
exit 0
fi
Re: Help with MACRO LASTSERVICESTATE
Hello,
We use gearman worker to execute the plugin, so there is 4 server who can execute the script. Using file flag is not recommended.
Here the simplified perl code :
The check-command :
The service :
Thank's
We use gearman worker to execute the plugin, so there is 4 server who can execute the script. Using file flag is not recommended.
Here the simplified perl code :
Code: Select all
# Recuperation du dernier etat du service et force nouvel etat
$lastResult = $o_lastservicestate;
switch ($lastResult) {
case "OK" { $newResult = "WARNING"; }
case "WARNING" { $newResult = "OK"; }
else { $newResult = "CRITICAL"}
}
Code: Select all
command_name u-check-heartbeatbsm
command_line $USER1$/check_heartbeatbsm.pl -H $HOSTNAME$ -s $ARG1$
Code: Select all
check_command u-check-heartbeatbsm!$LASTSERVICESTATE$
Re: Help with MACRO LASTSERVICESTATE
Other information, in thruk log there is only 1/2 check logged at 27, 37, 47 an 57mn. Not 32, 42, 52 !!
Code: Select all
[2016-04-08 11:57:01] SERVICE ALERT: host.recette.fr;dmon-bsmc-heartbeat-evt.appl-bsm-connector;OK;HARD;1;OK: HOSTNAME NAGIOS:host.recette.fr, LASTSERVICESTATE NAGIOS: WARNING force a OK
[2016-04-08 11:47:01] SERVICE ALERT: host.recette.fr;dmon-bsmc-heartbeat-evt.appl-bsm-connector;WARNING;HARD;1;WARNING: HOSTNAME NAGIOS:host.recette.fr, LASTSERVICESTATE NAGIOS: OK force a WARNING
[2016-04-08 11:37:01] SERVICE ALERT: host.recette.fr;dmon-bsmc-heartbeat-evt.appl-bsm-connector;OK;HARD;1;OK: HOSTNAME NAGIOS:host.recette.fr, LASTSERVICESTATE NAGIOS: WARNING force a OK
[2016-04-08 11:27:01] SERVICE ALERT: host.recette.fr;dmon-bsmc-heartbeat-evt.appl-bsm-connector;WARNING;HARD;1;WARNING: HOSTNAME NAGIOS:host.recette.fr, LASTSERVICESTATE NAGIOS: OK force a WARNING
Re: Help with MACRO LASTSERVICESTATE
It looks like you're not changing the exit code, and only the text. This will need to be done since the Core system depends on the exit codes.
Former Nagios Employee
Re: Help with MACRO LASTSERVICESTATE
Hello, here is the part code for exit :
Thank's
Code: Select all
....
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3);
....
$lastResult = $o_lastservicestate;
switch ($lastResult) {
case "OK" { $newResult = "WARNING"; }
case "WARNING" { $newResult = "OK"; }
else { $newResult = "CRITICAL"}
}
.....
exit $ERRORS{"$newResult"};
Re: Help with MACRO LASTSERVICESTATE
Your exit should only be a number, and if I'm following the logic right you won't be doing any switching really.
I suggest following something similar to what @jolson posted above. You can always change $file to be equal to something else.
I suggest following something similar to what @jolson posted above. You can always change $file to be equal to something else.
Former Nagios Employee
Re: Help with MACRO LASTSERVICESTATE
Hello,
The exit is a number call in a hash table (my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3)
The problem is with nagios who don't deliver the attempted value of macro $LASTSERVICESTATE$ every check but only every 2 check.
Is there parameter of nagios who force last state to don't change (flapping or other) ?
Thank's
The exit is a number call in a hash table (my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3)
The problem is with nagios who don't deliver the attempted value of macro $LASTSERVICESTATE$ every check but only every 2 check.
Is there parameter of nagios who force last state to don't change (flapping or other) ?
Thank's