0

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 '#'

command[usedspace_bash]=/usr/local/nagios/libexec/tmp_space.sh

Sudo permission:

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

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

Script:

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

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

if [ $used_space -le 10 ]
then
   echo "tmp FS OK - $used_space% of disk space used."
elif [ $used_space -gt 11 ]
then
   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"
else
   echo "UNKNOWN"
fi
0

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

with:

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.