Event Handler script not running

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.
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Event Handler script not running

Post by yaarak »

I can't get the event-handler script to run. I'm not getting any errors in the log file and the script runs manually.

Service:
define service{
use local-service
host_name localhost
service_description restart ulink PolicyServer
check_command check_ulink_procs!2:2!'uLinkPolicyServer'
check_interval 2
event_handler restart_ulink-policy
}

Handler (defined in command.cfg):
define command{
command_name restart_ulink-policy
command_line /usr/local/nagios/libexec/eventhandlers/restart_ulink-policy $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}

The script is the template copied from the nagios event-handler instructions.

permissions for the script:
-rwxr-xr-x restart_ulink-policy

nagios.log doesn't indicate any problems:
[1430607293] SERVICE EVENT HANDLER: localhost;restart ulink PolicyServer;CRITICAL;SOFT;3;restart_ulink-policy
[1430607353] SERVICE ALERT: localhost;restart ulink PolicyServer;CRITICAL;HARD;4;PROCS CRITICAL: 0 processes with args 'uLinkPolicyServer'
[1430607353] SERVICE NOTIFICATION: nagiosadmin;localhost;restart ulink PolicyServer;CRITICAL;notify-service-by-email;PROCS CRITICAL: 0 processes with args 'uLinkPolicyServer'
[1430607353] SERVICE EVENT HANDLER: localhost;restart ulink PolicyServer;CRITICAL;HARD;4;restart_ulink-policy
[1430607593] SERVICE ALERT: localhost;restart ulink PolicyServer;OK;HARD;4;PROCS OK: 2 processes with args 'uLinkPolicyServer'

It seems the script isn't being run at all. echo commands in the script isn't being printed either.
Any help would be greatly appreciated as I'm out of ideas.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Event Handler script not running

Post by ssax »

Please post the output of the following command:

Code: Select all

ls -l /usr/local/nagios/libexec/eventhandlers/restart_ulink-policy
Have you tried running it as the nagios user?

Code: Select all

su nagios
cd /usr/local/nagios/libexec/eventhandlers
./restart_ulink-policy
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Re: Event Handler script not running

Post by yaarak »

Thanks for your reply.

The output for the ls is:
ls -l /usr/local/nagios/libexec/eventhandlers/restart_ulink-policy
-rwxr-xr-x 1 nagios nagios 2815 May 3 14:40 /usr/local/nagios/libexec/eventhandlers/restart_ulink-policy

I can't su to nagios because it's asking for a password and I don't know what it is.
Where can i find it?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Event Handler script not running

Post by ssax »

Are you trying it as root?

Are you a sudoer?

Code: Select all

sudo su nagios
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Re: Event Handler script not running

Post by yaarak »

sudoer.

Tried switching but nothing happens:
/usr/local/nagios/etc/objects$ sudo su nagios
$ cd /usr/local/nagios/libexec/eventhandlers ./restart_ulink-policy
$

no errors but the script isn't running
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Re: Event Handler script not running

Post by yaarak »

I'm sorry if this sounds stupid, but it doesn't look like i switched user, it looks like i switched environment.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Event Handler script not running

Post by ssax »

Post the output of the following command:

Code: Select all

grep nagios /etc/passwd
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Re: Event Handler script not running

Post by yaarak »

Code: Select all

/usr/local/nagios/libexec/eventhandlers$ grep nagios /etc/passwd
nagios:x:1001:1001::/home/nagios:/bin/sh
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Event Handler script not running

Post by ssax »

Ok, let's try this:

Code: Select all

sudo su - nagios

Code: Select all

cd /usr/local/nagios/libexec/eventhandlers

Code: Select all

./restart_ulink-policy
Nothing happens? No errors or anything? Is it supposed to output anything?

Can you attach your restart_ulink-policy script so we can review it (might want to sanitize it first)?
yaarak
Posts: 9
Joined: Sat May 02, 2015 7:03 pm

Re: Event Handler script not running

Post by yaarak »

Ok, there was a permission problem. Now it runs the script and I get the echo printouts, but it's ignoring the command:

Code: Select all

sudo nohup mono >/dev/null /opt/ulink/Tools/PolicyServer/uLinkPolicyServer.exe &
Could it be a sudo problem?
Locked