Don't work event handler, PLEASE HELP!

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
MapycR
Posts: 2
Joined: Thu Oct 06, 2016 8:42 am

Don't work event handler, PLEASE HELP!

Post by MapycR »

Hi all, i'm not understand, why nagios event handler not worked. =-(

Nagios server log file:
nagios:~ # tail -f /var/opt/nagios/local/nagios.log | perl -pe 's/(\d+)/localtime($1)/e' | grep myhostname.*
[Thu Jun 15 12:35:44 2017] SERVICE ALERT: myhostname;NTP::Service availability;CRITICAL;SOFT;1;NTPD service inactive\n
[Thu Jun 15 12:35:44 2017] SERVICE EVENT HANDLER: myhostname;NTP::Service availability;CRITICAL;SOFT;1;restart-ntpd
[Thu Jun 15 12:36:48 2017] SERVICE ALERT: myhostname;NTP::Service availability;CRITICAL;SOFT;2;NTPD service inactive\n
[Thu Jun 15 12:36:48 2017] SERVICE EVENT HANDLER: myhostname;NTP::Service availability;CRITICAL;SOFT;2;restart-ntpd
[Thu Jun 15 12:37:48 2017] SERVICE ALERT: myhostname;NTP::Service availability;CRITICAL;SOFT;3;NTPD service inactive\n
[Thu Jun 15 12:37:48 2017] SERVICE EVENT HANDLER: myhostname;NTP::Service availability;CRITICAL;SOFT;3;restart-ntpd
[Thu Jun 15 12:38:51 2017] SERVICE ALERT: myhostname;NTP::Service availability;CRITICAL;HARD;4;NTPD service inactive\n
[Thu Jun 15 12:38:51 2017] SERVICE EVENT HANDLER: myhostname;NTP::Service availability;CRITICAL;HARD;4;restart-ntpd


command.cfg:
define command {
command_name restart-ntpd
command_line $USER$/check_nrpe -H $HOSTADDRESS$ -c restart-ntpd -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}


local command file (/etc/nrpe.d):
command[restart-ntpd]=/usr/lib64/nagios/plugins/eventhandlers/restart-ntpd $ARG1$ $ARG2$ $ARG3$

event handler script:
rights:
[root@myhostname sergey]# ll /usr/lib64/nagios/plugins/eventhandlers/restart-ntpd
-rwxrwxr-x 1 root root 525 Jun 15 12:27 /usr/lib64/nagios/plugins/eventhandlers/restart-ntpd

script:
#!/bin/sh
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
case "$2" in
SOFT)
case "$3" in
1)
;;
2)
;;
3)
echo -n "Restarting NTP service (3rd soft critical state)..."
/usr/bin/sudo /bin/systemctl restart ntpd > /dev/null
;;
esac
;;
HARD)
echo -n "Restarting NTP service..."
/usr/bin/sudo /bin/systemctl restart ntpd > /dev/null
;;
esac
;;
esac
exit 0

User nrpe added in sudoers, and if i do command - "/opt/nagios/libexec/check_nrpe -H myhostname -c restart-ntpd -a CRITICAL SOFT 3" from nagios server, all works fine, service on remote host was restarted.

Please help, i don't know where problem...
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Don't work event handler, PLEASE HELP!

Post by tgriep »

Can you add this to the top of your /usr/lib64/nagios/plugins/eventhandlers/restart-ntpd script on the remote host, simulate the failure and post the /tmp/event file from the remote server?

Code: Select all

#!/bin/sh

echo $1 >>/tmp/event
echo $2 >>/tmp/event
echo $3 >>/tmp/event
Be sure to check out our Knowledgebase for helpful articles and solutions!
MapycR
Posts: 2
Joined: Thu Oct 06, 2016 8:42 am

Re: Don't work event handler, PLEASE HELP!

Post by MapycR »

Hello tgriep,

Thanks for you reply! Yesterday i solved problem. The problem has been in the same command name in service configuration that in the local nrpe configuration on remote host, after i change name in service configuration on nagios server (service.cfg and commands.cfg), event handler has earned.

command.cfg:
define command {
command_name restart-ntpd
command_line $USER$/check_nrpe -H $HOSTADDRESS$ -c restart-ntpd -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}

in service.cfg for check of ntp service, i changed event_handler parameter value to restart-ntp-host, and change command_name value in commands.cfg on the same.

Thank you!
Best regards,
Sergey Kuzmitskiy
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Don't work event handler, PLEASE HELP!

Post by tgriep »

Glad you figured it out. I'll close and lock the post for you but if you have a new issue in the future, feel free to open a new post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked