Page 1 of 1

Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 5:13 am
by Pitone_Maledetto
Hi all,

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
    }
This is today log:

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.
As you can see from the first line entry the event handler should have run since it is within its timeperiod validation.

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
    ;;
This is the command definition to run the event handler with:

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$
   }
Now I just wondering if instead I should use this format for the $ISVALIDTIME$ macro:

Code: Select all

$ISVALIDTIME:hr-s3bt-nm:TIMESTAMP$
Where:

Code: Select all

TIMESTAMP=$(date +%s)
Any help would be greatly appreciated.
Thanks

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 1:39 pm
by scottwilkerson
I'm going to stop right here because this is not a valid timeperiod
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
        }

Time periods, cannot wrap around past 24:00, you would need to change the timeperiod to something like this

Code: Select all

define timeperiod{
        timeperiod_name     hr-s3bt-nm
        alias               LService
        sunday              22:00-24:00
        monday              00:00-06:00
        monday              22:00-24:00
        tuesday             00:00-06:00
        tuesday             22:00-24:00
        wednesday           00:00-06:00
        wednesday           22:00-24:00
        thursday            00:00-06:00
        thursday            22:00-24:00
        friday              00:00-06:00
        friday              22:00-24:00
        saturday            00:00-06:00
        saturday            22:00-24:00
        sunday              00:00-06:00
        }


Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 2:13 pm
by Pitone_Maledetto
Thanks for the reply.
It is definetly me then; however I don't understand the logic.
I would like the resume of service between 22pm and 6am only every day.
Why my timeperiod is not good?
I would be glad if you could explain further.
Thanks

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 2:20 pm
by scottwilkerson
Pitone_Maledetto wrote:I would like the resume of service between 22pm and 6am only every day.
Why my timeperiod is not good?
Because once you reach 24:00 on sunday, it becomes 00:00 on monday and nagios timeperiods do not wrap from one day to the next like that

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 2:26 pm
by Pitone_Maledetto
That is clear thanks.
So am I right to say that the timepriod above would be working between 22 and 24 and from 6 to 22?

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 2:55 pm
by scottwilkerson
The one I posted works from 22-24 and then 00-06 which is really the same thing you had, just broken up to cross midnight

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 3:04 pm
by Pitone_Maledetto
Thank you very much Scott!
Very helpful, have a nice weekend.
This can now be closed and I am looking forward to a full night sleep :)
Regards

Re: Event Handler stopped working! Part 2

Posted: Fri Jul 06, 2018 3:10 pm
by scottwilkerson
Pitone_Maledetto wrote:Thank you very much Scott!
Very helpful, have a nice weekend.
This can now be closed and I am looking forward to a full night sleep :)
Regards
You too!

Closing