不用从nagios主页获取源码,那份源码已经陈旧,而且存在不少问题,直接从做者php
<pre> git clone https://github.com/NagiosEnterprises/nrdp.git </pre>html
将应用拷贝到apache根目录下python
<pre> git clone https://github.com/NagiosEnterprises/nrdp.git cp -rp nrdp/server /var/www/html/nrdp chown -R nagios.nagios /var/www/html/nrdp </pre>ios
修改nrdp插件配置 /var/www/html/nrdp/config.inc.phpgit
$cfg['authorized_tokens'] = array( "k&d@dlz9x", "df23m7jadI34", ); $cfg["command_file"]="/var/lib/nagios3/rw/nagios.cmd"; $cfg["check_results_dir"]="/var/lib/nagios3/spool/checkresults"; $cfg["tmp_dir"]="/var/lib/nagios3/spool/tmp/";
添加 http 配置 /etc/apache2/conf-enabled/nrdp.confgithub
<Directory "/var/www/html/nrdp"> # SSLRequireSSL Options None AllowOverride None Order allow,deny Allow from 10.0.0.0/8 # Order deny,allow # Deny from all # 使用与nagios相同的认证用户 #AuthName "NRDP" #AuthType Basic #AuthUserFile /etc/nagios3/htpasswd.users #Require valid-user </Directory>
修改 apache 守护进程用户 /etc/apache2/envvarsapache
<pre> export APACHE_RUN_USER=nagios export APACHE_RUN_GROUP=nagios </pre>ubuntu
重启服务,访问 URLvim
/etc/init.d/httpd restart http://server_ip/nrdp/
若是提交数据返回 OK 的结果,说明 http 配置正确,正确结果以下:安全
<result> <status>0</status> <message>OK</message> </result> <result> <status>0</status> <message>OK</message> <meta> <output>2 checks processed.</output> </meta> </result>
参考 Nagios被动检测的配置 定义要被动监控的主机及其服务,使用nrdp客户端向服务器发送检测结果,看nagios是否正确接收到并正确反馈处理!
<pre> python send_nrdp.py --url=http://server_ip/server/ --token="l@bs&d" --host=localhost --service=check_disk_passive --state=0 --output="ok ok ok" </pre>
<pre> python send_nrdp.py --url=http://server_ip/server/ --token="l@bs&d" --host=localhost --state=0 --output="ok ok ok" </pre>
因为 nrdp-server 是运行在 apache 服务器上的应用,能够充分利用apache提供的安全机制,好比
1 SSL加密传输 ,对应配置
SSLRequireSSL
2 限制IP访问
Order allow,deny Allow from 10.0.0.0/8
3 用户认证
#使用与nagios相同的认证用户 #AuthName "NRDP" #AuthType Basic #AuthUserFile /etc/nagios3/htpasswd.users #Require valid-user
在ubuntu 14.04 系统探索部署 nagios nrdp 插件过程当中,测试 http: ip /nrdp/ 提交结果的页面中,老是报以下错误:
<result> <status>-1</status> <message>BAD COMMAND FILE</message> </result> <result> <status>-1</status> <message>BAD CHECK RESULTS DIR</message> </result>
“BAD COMMAND FILE” “BAD CHECK RESULTS DIR” 开发者定义的这两条运行错误提示信息,语义解误差很大,弄了两天依然无头绪, 只能在阅读插件的源码,分别找到了源码中对应的位置,如今把报错信息出处的调用的函数写成两个测试脚本
test_file_exists.php <?php $result=file_exists("/var/lib/nagios3/spool/checkresults","c"); print $result."\n\r"; ?> test_tempnam.php <?php $tmpname=tempnam("/var/lib/nagios3/spool/checkresults","c"); print $tmpname."\n\r"; ?>
分别以nagios www-data 用户身份执行,会返回不一样的结果,插件不能工做的正常缘由就这里!
sudo -u nagios php test_tempnam.php sudo -u nagios php test_file_exists.php sudo -u www-data php test_tempnam.php sudo -u www-data php test_file_exists.php
最后给出一种解决办法,更改apache服务的运行时用户 vim /etc/apache2/envvars
<pre> export APACHE_RUN_USER=nagios export APACHE_RUN_GROUP=nagios </pre>
最后测试一切OK