I have previously opened a thread regarding some issues with an event handler implemented using the $ISVALIDTIME$ macro which was resolved with the help of @scottwilkerson here:
https://support.nagios.com/forum/viewto ... =7&t=48971
However it has never successfully worked as intended; the service never gets re-started during night time using the timeperiod supplied.
(it might be worth nothing that the Nagios server is in the UK and the service that needs to be resumed is in a different timezone +1 so 22:00 in the UK is 23:00 on the server running the service)
This is the timeperiod:
Code: Select all
define timeperiod{
timeperiod_name hr-s3bt-nm
alias LService
sunday 22:00-06:00
monday 22:00-06:00
tuesday 22:00-06:00
wednesday 22:00-06:00
thursday 22:00-06:00
friday 22:00-06:00
saturday 22:00-06:00
}
Code: Select all
[07-06-2018-00:32:32] - LService can't be resumed during working hours.
[07-06-2018-06:42:32] - LService can't be resumed during working hours.
[07-06-2018-08:37:32] - LService can't be resumed during working hours.
This is a snippet of the event handler script:
Code: Select all
### LEGEND ###
# $SERVICESTATE$=$1
# $SERVICESTATETYPE$=$2
# $SERVICEATTEMPT$=$3
# $HOSTADDRESS$=$4
# $ISVALIDTIME:hr-s3bt-nm$=$5
CRITICAL)
# Is this a "soft" or a "hard" state?
case "$2" in
HARD)
case "$3" in
1)
if [ $5 = 1 ] ; then
# Trying to resume LService.
/usr/local/nagios/libexec/check_by_ssh -t 120 -H $4 -l nagios -C "sudo /usr/local/bin/start_LService" >> /tmp/resume.txt 2>&1
elif [ $5 = 0 ] ; then
# Timeperiod is invalid.
echo "[$NOW] - LService can't be resumed during working hours." >> /tmp/resume.txt
fi
;;
esac
;;
esac
;;
Code: Select all
define command{
command_name resume-hr-LService
command_line /usr/local/nagios/libexec/eventhandlers/resume-hr-LService $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $HOSTADDRESS$ $ISVALIDTIME:hr-s3bt-nm$
}
Code: Select all
$ISVALIDTIME:hr-s3bt-nm:TIMESTAMP$
Code: Select all
TIMESTAMP=$(date +%s)
Thanks