Page 1 of 2

Event Handler script not running

Posted: Sat May 02, 2015 7:35 pm
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.

Re: Event Handler script not running

Posted: Mon May 04, 2015 10:25 am
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

Re: Event Handler script not running

Posted: Mon May 04, 2015 10:56 am
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?

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:23 am
by ssax
Are you trying it as root?

Are you a sudoer?

Code: Select all

sudo su nagios

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:27 am
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

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:35 am
by yaarak
I'm sorry if this sounds stupid, but it doesn't look like i switched user, it looks like i switched environment.

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:42 am
by ssax
Post the output of the following command:

Code: Select all

grep nagios /etc/passwd

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:49 am
by yaarak

Code: Select all

/usr/local/nagios/libexec/eventhandlers$ grep nagios /etc/passwd
nagios:x:1001:1001::/home/nagios:/bin/sh

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:54 am
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)?

Re: Event Handler script not running

Posted: Mon May 04, 2015 11:58 am
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?