Issue : The tmp file clearing script is able to execute successfully on nagios client machine. When same script called from the nagios master, the script is executed but it skips sudo line in the script. Can some one help me on this.

nrpe.cfg :

root@nagislave:/tmp# grep -i usedspace /etc/nagios/nrpe.cfg | grep -v '#'


Sudo permission:

root@nagislave:/etc/sudoers.d# cat nagios-test

nagios ALL=(ALL) NOPASSWD:/bin/rm


root@nagislave:/etc/sudoers.d# cat /usr/local/nagios/libexec/tmp_space.sh

used_space=`df -h /tmp | grep -v Filesystem | awk '{print $5}' | sed 's/%//g'`

if [ $used_space -le 10 ]
   echo "tmp FS OK - $used_space% of disk space used."
elif [ $used_space -gt 11 ]
   sudo rm -rf /tmp/*
   d=`df -h /tmp | grep -v Filesystem | awk '{print $5}' | sed 's/%//g'`
   echo "OK - House keeping done on /tmp FS and now $d% of disk space used"
   echo "UNKNOWN"

You have to enable terminal-less access in sudo by disabling requiretty for this command. a tty (ie interactive usage) is required by default because otherwise this can help escalate security holes. So if you're fine with this, replace:

nagios ALL=(ALL) NOPASSWD:/bin/rm


Cmnd_Alias        NAGIOSRM = /bin/rm
nagios            ALL=(ALL) NOPASSWD: NAGIOSRM
Defaults!NAGIOSRM !requiretty

The Cmnd_Alias isn't mandatory but recommended, and becomes mandatory if you need extra parameters. This will allow only the rm command run by nagios.

Check man 5 sudoers for more informations.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.