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
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,