Event Handler stopped working! Part 2

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Event Handler stopped working! Part 2

Postby Pitone_Maledetto » Fri Jul 06, 2018 5:13 am

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:
viewtopic.php?f=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
"It is impossible to work in information technology without also engaging in social engineering"
Jaron Lanier
User avatar
Pitone_Maledetto
 
Posts: 62
Joined: Fri Jul 01, 2016 4:11 am
Location: Liverpool, United Kingdom

Re: Event Handler stopped working! Part 2

Postby scottwilkerson » Fri Jul 06, 2018 1:39 pm

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
        }

As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 11563
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Event Handler stopped working! Part 2

Postby Pitone_Maledetto » Fri Jul 06, 2018 2:13 pm

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
"It is impossible to work in information technology without also engaging in social engineering"
Jaron Lanier
User avatar
Pitone_Maledetto
 
Posts: 62
Joined: Fri Jul 01, 2016 4:11 am
Location: Liverpool, United Kingdom

Re: Event Handler stopped working! Part 2

Postby scottwilkerson » Fri Jul 06, 2018 2:20 pm

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 11563
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Event Handler stopped working! Part 2

Postby Pitone_Maledetto » Fri Jul 06, 2018 2:26 pm

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?
"It is impossible to work in information technology without also engaging in social engineering"
Jaron Lanier
User avatar
Pitone_Maledetto
 
Posts: 62
Joined: Fri Jul 01, 2016 4:11 am
Location: Liverpool, United Kingdom

Re: Event Handler stopped working! Part 2

Postby scottwilkerson » Fri Jul 06, 2018 2:55 pm

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 11563
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Event Handler stopped working! Part 2

Postby Pitone_Maledetto » Fri Jul 06, 2018 3:04 pm

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
"It is impossible to work in information technology without also engaging in social engineering"
Jaron Lanier
User avatar
Pitone_Maledetto
 
Posts: 62
Joined: Fri Jul 01, 2016 4:11 am
Location: Liverpool, United Kingdom

Re: Event Handler stopped working! Part 2

Postby scottwilkerson » Fri Jul 06, 2018 3:10 pm

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 11563
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises


Return to Nagios Core

Who is online

Users browsing this forum: Google [Bot], jforcier and 20 guests