Event Handler Script not working.

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Figment
Posts: 17
Joined: Mon Jan 28, 2019 5:21 am
Location: London, UK

Re: Event Handler Script not working.

Post by Figment »

Yeah, as far as I can see all files seem to be in their right location.

Code: Select all

[root@Nagios ~]# ls -l /usr/local/nagios/libexec/auto-acknowledge.sh
-rwxr-xr-x. 1 nagios nagios 693 Jan 28 14:42 /usr/local/nagios/libexec/auto-acknowledge.sh
[root@Nagios ~]# ls -d /usr/local/nagios/libexec/
/usr/local/nagios/libexec/
[root@Nagios ~]# ls -d /usr/local/nagios/
/usr/local/nagios/
[root@Nagios ~]# ls -d /usr/local/
/usr/local/
Thanks,
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler Script not working.

Post by scottwilkerson »

Sorry I missed the most important char in 3 of the commands

Code: Select all

ls -dl /usr/local/nagios/libexec/
ls -dl /usr/local/nagios/
ls -dl /usr/local/
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Figment
Posts: 17
Joined: Mon Jan 28, 2019 5:21 am
Location: London, UK

Re: Event Handler Script not working.

Post by Figment »

no worries, here's the results of that command.

Code: Select all

[root@Nagios ~]# ls -dl /usr/local/nagios/libexec/
drwxrwxr-x. 2 nagios nagios 4096 Jan 28 14:42 /usr/local/nagios/libexec/

[root@Nagios ~]# ls -dl /usr/local/nagios/
drwxrwxr-x. 10 root root 4096 Jan  3 14:21 /usr/local/nagios/

[root@Nagios ~]# ls -dl /usr/local/
drwxr-xr-x. 16 root root 4096 Nov  1 15:57 /usr/local/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler Script not working.

Post by scottwilkerson »

This all looks as expected, can you post the output of the following as I'm still not seeing what could be giving you a file not found

Code: Select all

cat /usr/local/nagios/libexec/auto-acknowledge.sh
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Figment
Posts: 17
Joined: Mon Jan 28, 2019 5:21 am
Location: London, UK

Re: Event Handler Script not working.

Post by Figment »

Certainly,

Code: Select all

[root@SU-GBCP-VTDS150 ~]# cat /usr/local/nagios/libexec/auto-acknowledge.sh
#!/bin/sh
#
# Event handler script for acknowledging non critical hosts.
#
#

# What state is the Host  in?
case "$1" in
UP)
        ;;
UNREACHABLE)
        ;;
DOWN)
        case "$2" in

        SOFT)

                case "$3" in

                1)
                        now=`date +%s`
                        commandfile='/usr/local/nagios/var/rw/nagios.cmd'
                        /bin/printf "[%lu] ACKNOWLEDGE_HOST_PROBLEM;$4;2;1;1;Autobot;Non-critical host, outage acknowledged\n" $now > $commandfile
                        ;;
                        esac
                ;;

        HARD)
                now=`date +%s`
                commandfile='/usr/local/nagios/var/rw/nagios.cmd'
                /bin/printf "[%lu] ACKNOWLEDGE_HOST_PROBLEM;$4;2;0;1;Autobot;Non-critical host, outage acknowledged\n" $now > $commandfile
                ;;
        esac
        ;;
esac
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler Script not working.

Post by scottwilkerson »

It just hit me, you don't have quotes around the items in your command definition

lets change this

Code: Select all

define command{
        command_name    auto-acknowledge
        command_line    $USER1$/auto-acknowledge.sh $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTATTEMPT$ $HOSTNAME$
}
to this

Code: Select all

define command{
        command_name    auto-acknowledge
        command_line    $USER1$/auto-acknowledge.sh '$HOSTSTATE$' '$HOSTSTATETYPE$' '$HOSTATTEMPT$' '$HOSTNAME$'
}
and then apply configuration
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Figment
Posts: 17
Joined: Mon Jan 28, 2019 5:21 am
Location: London, UK

Re: Event Handler Script not working.

Post by Figment »

Hi Scott,

Apologies for the delayed response, I have been out of office for a few days. Even with the quotes i'm still getting a "No such file or directory" error.

Code: Select all

[1549385220] HOST EVENT HANDLER: TEST_PRINTER;DOWN;SOFT;3;auto-acknowledge
[1549385220] wproc: HOST EVENTHANDLER job 2518 from worker Core Worker 16314 is a non-check helper but exited with return code 2
[1549385220] wproc:   early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1549385220] wproc:   stderr line 01: execvp(/usr/local/nagios/libexec/auto-acknowledge.sh, ...) failed. errno is 2: No such file or directory
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler Script not working.

Post by scottwilkerson »

This is so bizarre, the error is like the file /usr/local/nagios/libexec/auto-acknowledge.sh doesn't exist.

Out of curiosity, can you change the command to the following and restart nagios and see if you get the same error testing this

Code: Select all

define command{
        command_name    auto-acknowledge
        command_line    $USER1$/auto-acknowledge.sh
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Figment
Posts: 17
Joined: Mon Jan 28, 2019 5:21 am
Location: London, UK

Re: Event Handler Script not working.

Post by Figment »

scottwilkerson wrote:This is so bizarre, the error is like the file /usr/local/nagios/libexec/auto-acknowledge.sh doesn't exist.

Out of curiosity, can you change the command to the following and restart nagios and see if you get the same error testing this

Code: Select all

define command{
        command_name    auto-acknowledge
        command_line    $USER1$/auto-acknowledge.sh
}
Yeah its not really making any sense to me either. I've tried with non of the variables passed as you suggested and still get the file not found error.

Is it worth trying to put the script in a different directory?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler Script not working.

Post by scottwilkerson »

Figment wrote:Is it worth trying to put the script in a different directory?
might as well try, I'm actually out of ideas....
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked