Don't work event handler, PLEASE HELP!

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Don't work event handler, PLEASE HELP!

Postby MapycR » Thu Jun 15, 2017 5:23 am

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

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

Postby tgriep » Thu Jun 15, 2017 2:33 pm

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!
User avatar
tgriep
Madmin
 
Posts: 6019
Joined: Thu Oct 30, 2014 9:02 am

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

Postby MapycR » Thu Jun 15, 2017 11:49 pm

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

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

Postby tgriep » Fri Jun 16, 2017 10:53 am

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!
User avatar
tgriep
Madmin
 
Posts: 6019
Joined: Thu Oct 30, 2014 9:02 am


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 4 guests