Nagios通过SNMP检查网卡流量

运维 系统运维
Nagios通过SNMP检查网卡流量:Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等。这篇文章讲述了Nagios通过SNMP检查网卡流量。

  Nagios 通过SNMP检查网卡流量

  google一下snmp的漏洞,避免下载到未打补丁的版本

  Net-SNMP远程绕过认证漏洞

  受影响系统:

  Net-SNMP net-snmp 5.4.x

  Net-SNMP net-snmp 5.3.x

  Net-SNMP net-snmp 5.2.x

  不受影响系统:

  Net-SNMP net-snmp 5.4.1.1

  Net-SNMP net-snmp 5.3.2.1

  Net-SNMP net-snmp 5.2.4.1

  检查有无安装snmp

  rpm -qa|grep snmp

  下载net-snmp

  安装snmp

  rpm -ivh net-snmp-*.rpm

  error: Failed dependencies:

  libc.so.6(GLIBC_2.4) is needed by net-snmp-5.4.2.1-1.i386

  libc.so.6(GLIBC_2.7) is needed by net-snmp-5.4.2.1-1.i386

  librpm-4.4.so is needed by net-snmp-5.4.2.1-1.i386

  librpmio-4.4.so is needed by net-snmp-5.4.2.1-1.i386

  检查glib版本

  rpm -qa | grep glibc

  glibc-2.3.4-2

  glibc-common-2.3.4-2

  glibc-kernheaders-2.4-9.1.87

  glibc-devel-2.3.4-2

  glibc-headers-2.3.4-2

  glibc升级风险比较大,改用soure编译

  先安装beecrypt

  wget http://downloads.sourceforge.net/beecrypt/beecrypt-4.1.2.tar.gz

  tar zxvf beecrypt-4.1.2.tar.gz

  cd beecrypt-4.1.2

  ./configure --prefix=/usr

  make

  _bc-py.c:8:20: Python.h: No such file or directory

  rpm -qa|grep python

  rpm-python-4.3.3-18_nonptl

  gnome-python2-bonobo-2.6.0-3

  python-2.3.4-14.2

  libxml2-python-2.6.16-6

  python-elementtree-1.2.6-4.2.1

  python-sqlite-1.1.7-1.2

  gnome-python2-2.6.0-3

  gnome-python2-canvas-2.6.0-3

  mod_python-3.1.3-5.1

  dbus-python-0.22-12.EL.7

  MySQL-python-1.0.0-1.RHEL4.1

  python-urlgrabber-2.9.8-2

  没有python-devel,升级下python

  http://blog.c1gstudio.com/archives/588

  重新make

  make

  make install

  更新动态库

  ldconfig -v

  ln -s /lib/libelf.so.1 /usr/lib/libelf.so

  安装net-snmp

  wget http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-5.4.2.1.tar.gz

  tar zxvf net-snmp-5.4.2.1.tar.gz

  cd net-snmp-5.4.2.1

  ./configure -enable-mfd-rewrites -with-default-snmp-version="2" -with-sys-contact="admin" -with-sys-location="China" -with-logfile="/var/log/snmpd.log" -with-persistent-directory="/var/net-snmp"

  编译的输出

  SNMP Versions Supported: 1 2c 3

  Net-SNMP Version: 5.4.2.1

  Building for: linux

  Network transport support: Callback Unix TCP UDP

  SNMPv3 Security Modules: usm

  Agent MIB code: default_modules => snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host

  Embedded Perl support: enabled

  SNMP Perl modules: building -- embeddable

  SNMP Python modules: disabled

  Authentication support: MD5 SHA1

  Encryption support: DES AES

  make

  安装出错

  grep: /usr/lib/libbeecrypt.la: No such file or directory

  /bin/sed: can't read /usr/lib/libbeecrypt.la: No such file or directory

  libtool: link: `/usr/lib/libbeecrypt.la' is not a valid libtool archive

  #请安装beecrypt

  /usr/bin/ld: cannot find -lelf

  collect2: ld returned 1 exit status

  #ln -s libelf.so.1 /usr/lib/libelf.so

  make install

  ldconfig -v

  community string

  网络设备在使用SNMP中都设有community string,它类似于简单的口令验证机制,用来确认是否具有可读或读写的权限。许多用户在购买设备以来,从未修改系统缺省的community string,因此非授权用户使用缺省口令就可以对重要的系统信息、设备的状态等进行修改。

  将"COMMUNITY"字段改为你要设置的密码.比如"public"或privatepass.

  将“localhost”改为你想哪台机器可以看到你的snmp信息,如localhost或10.10.10.10。

  SNMP的版本

  在SNMP协议得益于重大升级,因为在1988年推出。

  不幸的是,很大比例的网络内容供应商,甚至一些网络管理系统厂商都没有利用这些改进。

  许多网络元素只支持SNMPv1和SNMPv2c 。 支持SNMPv3的是最小的。

  版本描述

  SNMPv1 SNMPv1 ,其中实施以社区为基础的安全

  SNMPv2c SNMPv2以社区为基础的安全

  SNMPv2u SNMPv2与基于用户的安全

  SNMPv2 SNMPv2党为基础的安全

  SNMPv3安全机制 SNMPv3安全机制,而实现基于用户的安全

  配置snmp

  mkdir /usr/local/etc/snmp  
 
  cp EXAMPLE.conf /usr/local/etc/snmp/snmpd.conf  
 
  vi usr/local/etc/snmp/snmpd.conf  
 
  # sec.name source community  
 
  com2sec local localhost privatepass  
 
  #com2sec mynetwork NETWORK/24 public  
 
  ####  
 
  # Second, map the security names into group names:  
 
  # sec.model sec.name  
 
  #group MyRWGroup v1 local  
 
  #group MyRWGroup v2c local  
 
  #group MyRWGroup usm local  
 
  #group MyROGroup v1 mynetwork  
 
  #group MyROGroup v2c mynetwork  
 
  #group MyROGroup usm mynetwork  
 
  group MyROGroup v1 local  
 
  group MyROGroup v2c local  
 
  ####  
 
  # Third, create a view for us to let the groups have rights to:  
 
  # incl/excl subtree mask  
 
  #view all included .1 80  
 
  view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc  
 
  ####  
 
  # Finally, grant the 2 groups access to the 1 view with different  
 
  # write permissions:  
 
  # context sec.model sec.level match read write notif  
 
  access MyROGroup "" any noauth exact mib2 none none  
 
  #access MyRWGroup "" any noauth exact all all none  
 
  #启动  
 
  /usr/local/sbin/snmpd  
 
  #加入启动  
 
  echo '/usr/local/sbin/snmpd' >> /etc/rc.local  
 
  #查看161端口是否开启  
 
  netstat -ano|grep 161  
 
  #测试  
 
  snmpwalk -v 1 -c privatepass localhost system  
 
  SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686  
 
  SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10  
 
  DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2612) 0:00:26.12  
 
  SNMPv2-MIB::sysContact.0 = STRING: Me  
 
  SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain  
 
  SNMPv2-MIB::sysLocation.0 = STRING: Right here, right now.  
 
  SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance  
 
  SNMPv2-MIB::sysORID.2 = OID: SNMP-MPD-MIB::snmpMPDCompliance  
 
  SNMPv2-MIB::sysORID.3 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance  
 
  SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB  
 
  SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB  
 
  SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip  
 
  SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB  
 
  SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup  
 
  SNMPv2-MIB::sysORDescr.1 = STRING: The SNMP Management Architecture MIB.  
 
  SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.  
 
  SNMPv2-MIB::sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.  
 
  SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities  
 
  SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementations  
 
  SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations  
 
  SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations  
 
  SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP.  
 
  SNMPv2-MIB::sysORUpTime.1 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.2 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.3 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.4 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.5 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.6 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.7 = Timeticks: (0) 0:00:00.00  
 
  SNMPv2-MIB::sysORUpTime.8 = Timeticks: (0) 0:00:00.00  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.

  snmp安装完毕

  安装check_traffic脚本

  下载check_traffic_v1.1.6.zip脚本

  上传./check_traffic.sh 至/usr/local/nagios/libexec

  cd /usr/local/nagios/libexec/

  chown nagios:nagios ./check_traffic.sh

  chmod 755 ./check_traffic.sh

  用 -L选项列出对应主机所有的interface,来确定你要监控的网络接口(如果能你确认接口的index值,这一步可以省略)。

  通过输出,我们确认要监控的网络接口为4,对应为"Macronix MX98715-Based Ethernet Adapter (Generic) - 数据包计划程序微型端口"

  ./check_traffic.sh -V 2c -C privatepass -H localhost -L

  List Interface for host localhost.

  Interface index 1 orresponding to lo

  Interface index 2 orresponding to eth0

  Interface index 3 orresponding to eth1

  Interface index 4 orresponding to sit0

  按照说明,选择版本为2c(一般选择1或者2c),community为privatepass,interface为2,单位为KB/s,in流量对应warning/critical值为200/400,out流量对应warning/critical值为300/500.

  sudo -u nagios ./check_traffic.sh -V 2c -C privatepass -H localhost -I 2 -w12,30 -c15,50 -K -b

  Can not found data in the history data file.

  If it's the first time for this plugins, that's OK.

  Otherwise,please use debug mode and check the debug file.

  第一次执行,因为history data file不存在,因此会由此提示,可以忽略。

  如果每次执行都忽略,则要检查/var/tmp下是否有/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件生成。

  文件的内容是系统当前的时间,in及out当前的数值。

  nagios监控本机的配置

  修改/usr/local/nagios/etc/objects/commands.cfg,增下以下内容

  define command{  
 
  command_name check_traffic_nv  
 
  command_line $USER1$/check_traffic.sh -V 2c -C privatepass -H localhost -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

  修改/usr/local/nagios/etc/objects/localhost.cfg,增下以下内容

  define service{  
 
  use local-service,srv-pnp ; Name of service template to use  
 
  host_name nagios  
 
  service_description check_nv_traffic_eth0  
 
  check_command check_traffic_nv!2!12,30!15,35  
 
  notifications_enabled 0  
 
  normal_check_interval 5 ;5分钟  
 
  retry_interval 1 ;1分钟  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

  nagios监控远程机的配置

  修改/usr/local/nagios/etc/objects/remotehost.cfg,增下以下内容

  define service{  
 
  use local-service,srv-pnp ; Name of service template to use  
 
  host_name nagios  
 
  service_description check_nv_traffic_eth0  
 
  check_command check_nrpe!check_traffic_nv  
 
  notifications_enabled 0  
 
  normal_check_interval 5 ;5分钟  
 
  retry_interval 1 ;1分钟  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

  修改/usr/local/nagios/etc/nrpe.cfg增加以下内容

  command[check_traffic_nv]=/usr/local/nagios/libexec/check_traffic_nv.sh -V 2c -C privatepass -H localhost -I 2 -w 12,30 -c 15,35 -M -b  
 
  • 1.
  • 2.

  访问http://localhost/nagios

  点击Service Detail

  点击check_nv_traffic_eth0服务旁的小太阳

  等5分钟后就可以看到图表

  which: no snmpwalk in (/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin)

  如果check_nv_traffic_eth0服务报找不到snmpwalk.

  ln -s /usr/local/bin/snmpwalk /usr/bin/snmpwalk

  有时我作的软链接会丢失,挺奇怪的...

【编辑推荐】

Nagios飞信linux短信报警脚本配置

Nagios安装记录

如何用Nagios监控远程系统

责任编辑:zhaolei 来源: c1gstudio
相关推荐

2010-06-01 10:59:18

2010-07-05 10:16:31

ucd-snmpSNMP Agent

2010-06-17 17:03:31

Linux流量控制

2024-12-10 13:17:41

2011-03-30 15:05:19

RedHad安装MRTG

2011-03-25 13:10:08

2016-04-18 18:22:06

2020-04-30 13:50:11

Linux网卡信息

2011-03-30 11:04:11

安装MRTG

2010-03-17 14:38:02

2015-09-07 09:41:42

tshark网络流量

2024-10-29 09:40:07

流量技术架构

2010-04-01 16:18:55

无线上网卡流量

2010-05-27 10:00:34

Linux 网卡流量

2011-03-23 12:55:51

NagiosMSN飞信

2011-03-31 13:58:34

cactinagios

2011-03-31 13:40:36

SNMPMRTG安装

2011-03-30 14:36:58

MRTG配置SNMP

2010-09-16 16:06:37

2010-03-24 17:26:50

无线上网卡流量
点赞
收藏

51CTO技术栈公众号