运行nagios插件时,权限被拒绝

我刚刚写了一个简单的bash脚本来检查文件系统是否正在写入和删除一个文件,但是当我把它放到Nagios中时,它不会像预期的那样运行。

root@debian:~# cat /usr/lib/nagios/plugins/check_filesys.sh #!/bin/bash # Script que checa se file system consegue escrever/ler arquivos if touch teste.txt && rm teste.txt; then echo OK - Teste OK! exit 0 else echo CRITICAL - Teste de escrita/leitura falhou! exit 2 fi root@debian:~# ls -l /usr/lib/nagios/plugins/check_filesys.sh -rwxrwxrwx 1 root root 217 Feb 5 10:40 /usr/lib/nagios/plugins/check_filesys.sh 

我还发现一个debugging脚本,看看是什么问题,这就是输出:

  2016-1-5 13:31:16 ------ debugging cmd=[/usr/lib/nagios/plugins/check_filesys.sh] output=[touch: cannot touch `teste.txt': Permission denied CRITICAL - Teste de escrita/leitura falhou! 

我尝试在/ etc / sudoers文件中插入nagios用户,如下所示:

 nagios ALL:NOPASSWD: /bin/bash -c /usr/lib/nagios/plugins/check_filesys.sh * 

但问题依然存在。 OBS:我正在检查localhost。

您需要使用touch / rm的完整path,因为您的脚本尝试在/运行,并且Nagios没有/写入权限。

(如果$ HOME被设置为理智的话,你也许可以使用~/test.txt

你可以自己validation一下:

 # pgrep nagios 556 # ls -ls /proc/556/cwd 0 lrwxrwxrwx 1 root root 0 Feb 5 11:10 /proc/556/cwd -> / 

这表明Nagios进程正在运行, cwd设置为/

您的nagios插件将作为您在/etc/nagios/nrpe.cfg中定义的“nrpe_user”来运行。 这可能是“用户nagios或用户nrpe”。

如果您更新您的脚本以触摸“/tmp/teste.txt”(换句话说,触摸具有开放权限的位置中的文件),它应该可以工作。

如果你没有真正调用sudo,那么sudoers文件中放置nagios将无济于事。 尝试

 nagios ALL=ALL NOPASSWD: /usr/lib/nagios/plugins/check_filesys.sh 

sudoers ,并有nagios调用

 sudo /usr/lib/nagios/plugins/check_filesys.sh