I added a script that checks CPU usage for remote Linux machines. I downloaded the file and give execution permission to it.
# Download the script for CPU usage
http://verypowerful.info/home/nagiosplugin-checkcpuperformance
# Giving a permission
$ chmod a+x /usr/lib64/nagios/plugins/check_cpu_perf.sh
# Command definition in nrpe.cfg on the remote server.
$ vi /etc/nagios/nrpe.cfg
command[check_cpu]=/usr/lib64/nagios/plugins/check_cpu_perf.sh $ARG1$ $ARG2$
While I was testing this script on nagios monitoring server, I got the following error:
$ /usr/lib64/nagios/plugins/check_nrpe -H 192.168.20.174 -c check_cpu -a 30 20
NRPE: Unable to read output
At the start, I searched why this happened and how this solved.
Most of suggestions on those results were:
1) Add the command that you want execute into nrpe.cfg
command[check_cpu]=sudo /usr/lib64/nagios/plugins/check_cpu_perf.sh
2) Add nagios user and the script into /etc/sudoers
nagios ALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/check_cpu_perf.sh
3) Comment out the section in /etc/sudoers
#Defaults requiretty
However, my case was different to these. It caused because of SELINUX.
SELINUX was enabled on my remote server.
$ vi /etc/selinux/config
....
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUX=enforcing
SELINUX=disabled
# Needs to reboot to apply this.
$ reboot
I executed check_cpu again on Nagios Monitoring host
$ /usr/lib64/nagios/plugins/check_nrpe -H 192.168.20.174 -c check_cpu -a 30 20
OK: CPU Idle = 99.79% | CpuUser=0.12; CpuNice=0.00; CpuSystem=0.08; CpuIowait=0.01; CpuSteal=0.00; CpuIdle=99.79:20:10
It worked. If you can't find any solution about the error "Unable to read output", It's good to check SELINUX.
In addition, when you have the following error message, It needs to enable "dont_blame_nrpe " option.
CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
vi /etc/nagios/nrpe.cfg
...
dont_blame_nrpe=1
References:
1. http://stackoverflow.com/questions/10542648/python-unable-to-call-sudo-using-popen
Big thanks my chinese man! Solved it!
답글삭제Thanks for comment.
답글삭제I am a Korean, though. :-)