nagios之集成snmptt
一、什么是SNMPTT(SNMP Trap Translator)SNMPTT是用perl写的SNMP trap处理器,它需要使用Net-SNMP/UCD-SNMP snmptrapd程序。SNMPTT支持Linux,Unix和Windows。具体工作原理如下图:
http://blog.运维网.com/attachment/201303/161524340.png
Net-SNMP程序的snmptrapd是收集和记录SNMP trap,并通过TCP/IP发送消息的程序。
snmptrapd程序接收到的告警的输出如下,一般格式为 variable name=value, variable name=value。
Feb 12 13:37:10 server11 snmptrapd: 192.168.110.192: EnterpriseSpecific Trap (3008) Uptime: 306 days, 23:13:24.29, .1.3.6.1.2.1.1.5.0 =SERVER08, .1.3.6.1.4.1.232.11.2.11.1.0 = 0,.1.3.6.1.4.1.232.3.2.3.1.1.4.8.1 = rebuilding(7)
or
Feb 12 13:37:10 server11 snmptrapd: 192.168.110.192:Enterprise Specific Trap (3008) Uptime: 306 days, 23:13:24.29, sysName.0= SERVER08, cpqHoTrapFlags.0 = 0, cpqDaLogDrvStatus.8.1 = rebuilding(7)
使用SNMPTT的变量替换功能,消息可以变的更友好,如在SNMPTT 配置文件中定义如下的格式:
FORMAT Logical Drive Status Change: Status is now $3.
那么上面收到的消息将会显示,可以看出,第三个变量rebuilding被替换显示出来:
Feb 12 13:37:13 server11 TRAPD:.1.3.6.1.4.1.232.0.3008 Normal "XLOGONLY" server08 - Logical DriveStatus Change: Status is now rebuilding
SNMPTT可以将输出记录到文本日志,NT event 日志,SQL数据库,或者通过外部程序传给Nagios,邮件客户端等。除了变量替换,SNMPTT允许如下复杂的配置:
*接受或拒绝一个trap信息,基于主机名/IP地址/网络段/trap变量中的值
*执行外部程序来发送page,email等
*执行正则表达式来匹配和替换消息中的内容。
二、软件前提需求
1.perl及模块支持
(1). Perl 5.6.1 or higher.SNMPTT is developed with 5.6.1 and 5.8.0, but other versions may also work.
(2). Required: Net-SNMP (formerly known as UCD-SNMP).Specifically snmptrapd.
(3). Required: Text::ParseWords module (included with most distributions including ActivePerl)
(4). Required: Getopt::Long module (included with most distributions including ActivePerl)
(5). Required: Posix module (included with most if not all distributions including ActivePerl)
(6). Required: Config::IniFiles module
(7). Required: Time::HiRes module (only required when using SNMPTT in daemon mode - required by snmptthandler)
(8). Required: Sys::Hostname module (included with most if not all distributions including ActivePerl).
(9). Required: File::Basename module (included with most if not all distributions including ActivePerl).
(10). Required: Text::Balanced module (included with most if not all distributions including ActivePerl).
其中 Config::IniFiles、 Text::Balanced等比较少用,可以使用cpan进行安装,可能安装过程中碰到模块信赖的问题,像我碰到了信赖关系,例: Config::IniFiles信赖Perl::OSType、Bundle::CPAN和ExtUtils::MakeMaker,有时候还是满麻烦的。碰到问题,慢慢解决,嘿嘿。
2.其他软件支持
(1).nagios:3版本以上,下载链接:http://www.nagios.org/download/core
(2).snmptt:1.3版本了,网上有gz包和rpm包,根据自己需求来下载了。
gz包下载地址:http://sourceforge.net/projects/snmptt/
三、snmptt和snmptrapd的安装及配置:
1.snmptt的安装及配置
. 下载snmptt.tgz 包解压
. 拷贝snmptt到/usr/sbin, 加可执行权限(chmod +x snmptt)
. 拷贝snmptthandler到/usr/sbin,加可执行权限(chmod +x snmptthandler)
. 拷贝snmptt.ini 到/etc/snmp或者/etc。更改文件中的选项。
. 创建日志文件夹/var/log/snmptt
. 创建spool文件夹(daemon mode会使用)
mkdir /var/spool/snmptt/
. 拷贝启动脚本到init.d目录
cp snmptt.init.d /etc/rc.d/init.d/snmptt
. 增加启动项
chkconfig --add snmptt
chkconfig --level 2345 snmptt on
service snmptt start
或者手工执行snmpttt
snmptt --daemon
. 拷贝日志轮训脚本cp snmptt.logrotate /etc/logrotate.d/snmptt,并根据具体目录更改文件中的路径
. 手工创建snmptt.conf文件,或者使用snmpttconvertmib工具创建。
使用命令:
snmpttconvertmib --in= --out=/etc/snmp/snmptt.conf. \ --exec='/usr/local/nagios/libexec/eventhandlers/submit_check_result $r TRAP 1'
例:
http://blog.运维网.com/attachment/201303/110213137.png
*其中MIB file可以到各具体设置的官网上进行下载
. 更改snmptt.ini文件包含snmptt.conf.*文件,并设置选项 http://blog.运维网.com/attachment/201303/163711261.png
. 启动snmptt: service snmptt restart
2.snmptrapd的配置:
.配置snmptrapd的配置文件/etc/snmp/snmptrapd.conf
对于standlone mode: 更改Net-SNMP的snmptrapd.conf配置文件,添加如下行:
traphandle default /usr/sbin/snmptt
对于 daemon mode,更改Net-SNMP的snmptrapd.conf配置文件,增加如下行:
traphandle default /usr/sbin/snmptthandler
http://blog.运维网.com/attachment/201303/164245491.png
第一行:配置一个认证的community,设置所有用户的访问权限:可执行,记录,传递同时方便agent进行使用snmptrap进行命令测试;
第二行:接收到的trap信息默认调用/usr/sbin/snmptt来进行处理。同时也可以针对具体的OID,来指定调用的程序;
第三行:禁止访问控制检查 willdisabletheaboveaccess control checks, and revert to the previous behaviour of accepting all incoming notifications.
第四行:禁止通知的日志记录disablesthelogging of notifications altogether.This is useful if the snmptrapd application should only run traphandle hooks and should not log traps to any location.
注:snmptrapd.conf有很多很多具体的参数配置,具体可以man一下。
.snmptrapd服务启动配置:
使用如下命令启动snmptrapd,snmptrapd -On.
如果存在/etc/rc.d/init.d/snmptrapd文件,则也要更改添加上选项”-On”。
OPTIONS="-On -Lf /var/log/snmptrapd.log -p /var/run/snmptrapd.pid"
注:具体参数意思可查看帮助
四、snmptt.ini主配置文件的配置
snmptt_system_name =
mode = standalone
multiple_event = 1
dns_enable = 0
strip_domain = 0
strip_domain_list =
页:
[1]