event handler won't trigger

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.
Locked
leifa
Posts: 4
Joined: Fri Mar 15, 2019 10:09 am

event handler won't trigger

Post by leifa »

hi everyone, I'm new to this forum, but I really need help.

I'm using CGI's and Mysql database to store information about health of my servers and reboot some of them if necessary, I'm trying to use the event handler from nagios to trigger a script that will make somme changes in database via CGI .

but the event_handler never trigger.
this is the services.cfg config:

define service{
name generic-service
active_checks_enabled 1 ; Active service checks enabled
passive_checks_enabled 1 ; Passive service checks enabled/accepted
parallelize_check 1 ; Active service checks parallelized
obsess_over_service 1 ; We should obsess over this service
check_freshness 0 ; Default is to NOT check service freshness
notifications_enabled 1 ; Service notifications enabled
event_handler_enabled 1 ; Service event handler enabled
flap_detection_enabled 1 ; Flap detection enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across restarts
retain_nonstatus_information 1 ; Retain non-status information across restarts
register 0
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 1
contact_groups ****************
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
is_volatile 0


the service :
define service {
host_name mail2
use ping-service
event_handler notify_critical_bdd
register 1
}


the commands.cfg:

define command {
command_name notify_critical_bdd
command_line /usr/bin/notify_critical_bdd $HOSTNAME$ $HOSTADDRESS$ $SERVICEDESC$ $SERVICESTATE$
}


and nagios.cfg event_handler config:

log_event_handlers=1
event_handler_timeout=30
enable_event_handlers=1

the event_handler scipt (modified to trigger for any service state changes):

#!/bin/sh

sudo touch /tmp/test.log
sudo echo "$1 $2 $3 $4" >/tmp/test.log

today=`date`

case "$4" in

WARNING)
sudo echo "$today $1 $2 $3 $4" >> /tmp/critical_log
;;

OK)
sudo echo "$today $1 $2 $3 $4" >> /tmp/critical_log
;;

UNKNOWN)
sudo echo "$today $1 $2 $3 $4" >> /tmp/critical_log
;;

CRITICAL)
sudo echo "$today $1 $2 $3 $4" >> /tmp/critical_log
;;

*)
exit 0
;;

esac

exit 0


and every script and files used are for nagios user and are "chmod 777" and nagios is in the sudoers list.

cannot find why it doesn't work

Help please :)))))
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: event handler won't trigger

Post by scottwilkerson »

Can you run this successfully?

Code: Select all

su nagios -c "/usr/bin/notify_critical_bdd arg1 arg2 arg3 arg4"
Is the service changing state?

does the template ping-service have

Code: Select all

use generic-service


??
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
leifa
Posts: 4
Joined: Fri Mar 15, 2019 10:09 am

Re: event handler won't trigger

Post by leifa »

ok the command
su nagios -c "/usr/bin/notify_critical_bdd arg1 arg2 arg3 arg4"
does not work

I tried it with another user and it worked so it seems to be a rights problem.

maybe the sudoers is not configured correctly i'm gonna look into it thx ;)
leifa
Posts: 4
Joined: Fri Mar 15, 2019 10:09 am

Re: event handler won't trigger

Post by leifa »

ok
so i just tried
su nagios -c "/usr/bin/notify_critical_bdd arg1 arg2 arg3 arg4"

and it doesn't work but it worked whith another user so it's a rights problem, maybe the sudoers is not set up correctly.

I'm going to look into it thx :)
leifa
Posts: 4
Joined: Fri Mar 15, 2019 10:09 am

Re: event handler won't trigger

Post by leifa »

I have my answer, my user Nagios was /bin/false in /etc/passwd
Thx anyway for helping me
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: event handler won't trigger

Post by scottwilkerson »

leifa wrote:I have my answer, my user Nagios was /bin/false in /etc/passwd
Thx anyway for helping me
Glad to help
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked