正确返回结果:
OK - The Traffic In is 356Kbps, Out is 414Kbps, Total is 770Kbps. The Check Interval is 30s |In=356Kbps;1200;1700;0;0 Out=414Kbps;1500;1800;0;0 Total=770Kbps;2700;3500;0;0 Interval=30s;1200;1800;0;0
在客户端的snmp配置文件和nrpe文件中的 -H后面的Ip应该写客户端本身的,而不应该是服务器的Ip,因为nagios是通过nrpe来获取数据,并不是通过snmp来获取的即前者snmp数据只会在本机产生,自己采集自身数据而后由nrpe插件传输到nagios服务器前端显示出来(数据文件在本机)。
更改/var/tmp/check_traffic* 文件权限为nagios用户可读写。简单的给个777吧。
chmod 777 /var/tmp/check_traffic_127.0.0.1_2.hist_dat_root__32
重启nrpe
【nagios服务端】
1、定义services.cfg
define service{
host_name xx --客户端
service_description traffic
check_command check_nrpe!check_traffic!3!300,400!500,600
max_check_attempts 5
normal_check_interval 5
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups shyygroup
}
重启nagios,然后再服务器端手工测试
root># ./check_nrpe -H xx -c check_traffic
OK - The Traffic In is 1.25KB, Out is 3.37KB, Total is 4.62KB. The Check Interval is 298s |In=1.25KB;300;500;0;0 Out=3.37KB;400;600;0;0 Total=4.62KB;700;1100;0;0 Interval=298s;1200;1800;0;0
##错误
在运行check_traffic.sh脚本的时候,会出现:
./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 1 -w 1200,1500 -c 1700,1800 -K -b
./check_traffic.sh: line 449: bc: command not found
./check_traffic.sh: line 454: bc: command not found
./check_traffic.sh: line 457: bc: command not found
./check_traffic.sh: line 458: bc: command not found
./check_traffic.sh: line 461: [: too many arguments
./check_traffic.sh: line 576: bc: command not found
./check_traffic.sh: line 577: bc: command not found
Unknown - Can not found data in the history data file. Please to check the file /var/tmp/check_traffic_127.0.0.1_3.hist_dat_root__64 ,or use use verbose mode and check the debug file
--解决:
bc: command not found
yum search bc,结果出现一大堆,然后发现有这么一个需要安装
bc.x86_64 0:1.06.95-1.el6
果断执行yum -y install bc
至于另外一个错误:
Unknown是由于
第一次执行,因为history data file不存在,因此会由此提示,可以忽略。
如果每次执行都忽略,则要检查/var/tmp下是否有/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件生成。
文件的内容是系统当前的时间,in及out当前的数值。
