event handler issue

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
shan123
Posts: 5
Joined: Mon Aug 29, 2016 4:49 pm

event handler issue

Post 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
shan123
Posts: 5
Joined: Mon Aug 29, 2016 4:49 pm

Re: event handler issue

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

Re: event handler issue

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: event handler issue

Post 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
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: event handler issue

Post by mcapra »

Thanks @eloyd!

@shan123 let us know if neither recommendation provides a solution.
Former Nagios employee
https://www.mcapra.com/
Locked