Pages

Friday, September 14, 2012

NRPE: Unable to read output

In my recent assignment I wanted to monitor the contents of a particular file and basis on that contents Nagios should send an alert. Pretty straight forward job :)

But there was a catch !!! the file that I wanted to monitor is actually owned by root user.

So my custom written plugin  was working very well when I am running manually (using root user ) but failing  when nagios was trying to run it via NRPE it was not working.


Solution :   Use Sudo to run the custom plugin , so that when NRPE tries to execute the script it is actually running as a root user.

For that , add a very restrictive entry in sudoers file , giving access to the Nagios user only for that single command as below,

nagios ALL=(ALL) NOPASSWD: /usr/local/nagios/libexec/check_my_file

and in the nrpe.cfg use sudo to run the command , as shown below

command[check_my_file]=sudo /usr/local/nagios/libexec/check_my_file

and its done :)



Note :  On Centos and Redhat Machines you also need to turn off the requiretty option in your suoders file

Comment out the line,

#Defaults requiretty


No comments:

Post a Comment