How to configure Nagios to run plugin with sudo

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

How to configure Nagios to run plugin with sudo

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: How to configure Nagios to run plugin with sudo

Post 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:

Code: Select all

chmod u+s <yourpluginfile>  
Or sudoers (add to /etc/sudoers):

Code: Select all

nagios  ALL=(ALL) NOPASSWD: /bin/mount
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

Re: How to configure Nagios to run plugin with sudo

Post 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
You do not have the required permissions to view the files attached to this post.
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

Re: How to configure Nagios to run plugin with sudo

Post by xtremax »

Hi,

I have attached also the sudoers file for you to check.

Thanks,

Rudy
You do not have the required permissions to view the files attached to this post.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: How to configure Nagios to run plugin with sudo

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

Re: How to configure Nagios to run plugin with sudo

Post 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
You do not have the required permissions to view the files attached to this post.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: How to configure Nagios to run plugin with sudo

Post by sreinhardt »

Just to verify, did you take a look in the /etc/sudoers file itself?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

Re: How to configure Nagios to run plugin with sudo

Post by xtremax »

Hi,

Yes, please refer to the sudoers file that i attached in my previous post and also to my attached screenshot.

Rudy
You do not have the required permissions to view the files attached to this post.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to configure Nagios to run plugin with sudo

Post by tmcdonald »

What command did you use to edit your sudoers file? It must be edited by running

Code: Select all

visudo
and nothing else, no command line arguments.
Former Nagios employee
xtremax
Posts: 28
Joined: Wed Jul 17, 2013 11:30 pm

Re: How to configure Nagios to run plugin with sudo

Post by xtremax »

Hi,

I am using visudo -f /etc/sudoers. I think it's the same thing right?

Thanks,

Rudy
Locked