layout: post
不用从nagios主页获取源码,那份源码已经陈旧,并且存在很多问题,直接从作者
git clone https://github.com/NagiosEnterprises/nrdp.git
将应用拷贝到apache根目录下
git clone https://github.com/NagiosEnterprises/nrdp.git cp -rp nrdp/server /var/www/html/nrdp chown -R nagios.nagios /var/www/html/nrdp
修改nrdp插件配置 /var/www/html/nrdp/config.inc.php
$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.conf
<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/envvars
export APACHE_RUN_USER=nagios export APACHE_RUN_GROUP=nagios
重启服务,访问 URL
/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是否正确接收到并正确反馈处理!
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"
python send_nrdp.py --url=http://server_ip/server/ --token="l@bs&d" --host=localhost --state=0 --output="ok ok ok"
由于 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
export APACHE_RUN_USER=nagios export APACHE_RUN_GROUP=nagios
最后测试一切OK