Page 1 of 2
How to configure Nagios to run plugin with sudo
Posted: Tue Oct 22, 2013 9:57 pm
by xtremax
Hi Support,
I would like to know how to enable my Nagios XI to be able to run plugin using sudo. I have the following plugin that I used:
Code: Select all
#!/bin/sh
mount /mnt/backup
DESTINATION=`date +"$1"`
echo $DESTINATION
if [ -e $DESTINATION ]
then
echo "OK - File exist."
umount /mnt/backup
exit 0
else
echo "CRITICAL - File not found."
umount /mnt/backup
exit 2
fi
Since I am using mount and umount command, Nagios unable to run it and returning error. Please advise.
Thanks,
Rudy
Re: How to configure Nagios to run plugin with sudo
Posted: Wed Oct 23, 2013 10:06 am
by abrist
Is this run on the local XI server, or on a remote host?
setuid on the script or edit the sudoers file with a new rule for user 'nagios'.
To setuid:
Or sudoers (add to /etc/sudoers):
Code: Select all
nagios ALL=(ALL) NOPASSWD: /bin/mount
Re: How to configure Nagios to run plugin with sudo
Posted: Wed Oct 23, 2013 9:35 pm
by xtremax
Hi abrist,
It's running on the local XI server. I have tried both of your suggestion, however I am getting the following error:
sudo: no tty present and no askpass program specified
Please advise.
Thanks,
Rudy
Re: How to configure Nagios to run plugin with sudo
Posted: Wed Oct 23, 2013 9:37 pm
by xtremax
Hi,
I have attached also the sudoers file for you to check.
Thanks,
Rudy
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 9:38 am
by abrist
The "no tty present" error indicates that you have the 'requiretty' setting in your sudoers file. In your case, it is probably in /etc/sudoers.d. Once this line is there, it does not matter what group you are in - sudo will require a tty whenever it is executed.
To get around this, you need to either remove (or comment out) the requiretty line in the configuration file, or add a line to exclude your user from the requiretty setting.
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 9:49 am
by xtremax
Hi abrist,
Thanks for your reply. However I am not able to find any configuration file in the folder /etc/sudoers.d.
Refer to my attached screenshot.
Please advise,
Rudy
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 10:36 am
by sreinhardt
Just to verify, did you take a look in the /etc/sudoers file itself?
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 10:43 am
by xtremax
Hi,
Yes, please refer to the sudoers file that i attached in my previous post and also to my attached screenshot.
Rudy
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 4:43 pm
by tmcdonald
What command did you use to edit your sudoers file? It must be edited by running
and nothing else, no command line arguments.
Re: How to configure Nagios to run plugin with sudo
Posted: Thu Oct 24, 2013 9:22 pm
by xtremax
Hi,
I am using visudo -f /etc/sudoers. I think it's the same thing right?
Thanks,
Rudy