- 安装软件包
yum -y install net-snmp*
chconfig nrpe on
chconfig snmpd on
chkconfig nagios on - 修改snmp参数,vi /etc/snmp/snmpd.conf(可备份snmpd.conf,修改下面的localhost-IP为服务器IP,保存此文件即可)
com2sec notConfigUser localhost-IP public group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser view systemview included .1.3.6.1.2.1.1 view systemview included .1.3.6.1.2.1.25.1.1 access notConfigGroup "" any noauth exact all none none view all included .1 80 syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <[email protected]> (configure /etc/snmp/snmp.local.conf)
snmpd.conf
- 拷贝check_traffic.sh到/usr/lib64/nagios/plugins/check_traffic.sh
check_traffic.sh文件GitHub下载地址:https://github.com/cloved/check_traffic/blob/master/check_traffic.shwget https://github.com/cloved/check_traffic/archive/master.zip - 赋予执行权限并测试:
chmod +x check_traffic.sh
./check_traffic.sh -V 2c -C public -H your_ip -I 2 -w 1200,1500 -c 1700,1800 -K –B
./check_traffic.sh -V 2c -C public -H your_ip –L - 例子:
./check_traffic.sh -V 2c -C public -H your_ip -N eth0 -w 8,7 -c 16,14 -M -b
-V snmp 版本
-C 认证信息
-H 主机IP
-N 网卡
-w 8,7 下行/上行流量超过 8,7 Mbit/s 警告
-c 16,14 下行/上行流量超过 16,14 Mbit/s 严重
-M 兆
-b 比特 - 编辑/etc/nagios/objects/command.cfg文件,追加:
# ‘check_traffic‘ command definition define command{ command_name check_traffic command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b }
Check _traffic Code
- 编辑/etc/nagios/objects/localhost.cfg文件
define service{ use local-service ; Name of service template to use host_name localhost service_description Check_Trafffic check_command check_traffic!2!12,15!20,30 notifications_enabled 1 normal_check_interval 5 retry_interval 1 }
localhost.cfg
并且修改localhost.cfg文件中的IP地址(127.0.0.1)为本机的IP!!!!!!!(坑了我2天)
- 删除临时文件
/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件 - 重启nagios服务
- 参考下面链接的部分内容:
http://2860664.blog.51cto.com/2850664/1567068
时间: 2024-10-29 19:09:57