Page 1 of 1

event handler issue

Posted: Thu Sep 08, 2016 1:46 pm
by shan123
I am trying to setup event handler for ntpd service..
i created event handler script that restarts ntpd using command "/etc/init.d/ntpd restart" in nagios core.

on the remote server, i have below entries in the sudoers file

nagios ALL=NOPASSWD: /usr/sbin/ntpd
Defaults:nagios !requiretty
nagios ALL= NOPASSWD: /etc/init.d/ntpd restart

problem is it keeps throwing the errors "sudo: no tty present and no askpass program specified"..

when i run the restart command as nagios user on the server it works fine
su -s /bin/bash nagios
sudo -u root /etc/init.d/ntpd restart -- this works

but through event handler its not workking..am i missing something here ?

pls help
Shan

Re: event handler issue

Posted: Thu Sep 08, 2016 1:56 pm
by shan123
correction : my event handler script has the entry - "sudo -u root /etc/init.d/ntpd restart" (because my ntpd script will work only if the UID matches to zero)

Re: event handler issue

Posted: Thu Sep 08, 2016 4:18 pm
by tgriep
Are you trying to restart ntpd on a remote server or the local Nagios server?
If it is a remote server, the following link is a guide for setting that up.
https://assets.nagios.com/downloads/nag ... h_NRPE.pdf
It says it is for Nagios XI but is should work just the same.

Re: event handler issue

Posted: Fri Sep 09, 2016 10:00 am
by eloyd
Event handlers run without a TTY. Sudo complains if it's being executed without a TTY; that's the error you're seeing.

Your "!requiretty" command needs to be before any specific commands in your sudoers file:

Code: Select all

Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/sbin/ntpd
nagios ALL= NOPASSWD: /etc/init.d/ntpd restart

Re: event handler issue

Posted: Fri Sep 09, 2016 1:02 pm
by mcapra
Thanks @eloyd!

@shan123 let us know if neither recommendation provides a solution.