snmpttとnagios連携

snmptrapをnagios経由でメールで通知させてみた

環境は以下の通り
CentOS 5.5(64bit)
net-snmp-5.3.2.2-9.el5_5.1(rpm)
snmptt-1.3(src)
nagios-3.2.1(src)
nagios-plugin-1.4.15(src)

  • snmpttconvertmibコマンドでmibファイルを変換
snmpttconvertmib --in=/usr/share/snmp/mibs/SNMPv2-MIB.txt --out=/etc/snmp/snmptt.conf.SNMPv2-MIB --exec='/usr/local/nagios/libexec/eventhandlers/submit_check_result TRAP "SNMP_TRAPS" 2'

mibファイルをsnmpttで読み込める形へ変換してくれるコマンドです。
http://snmptt.sourceforge.net/docs/snmpttconvertmib.shtml

ここの--execオプションで指定している"SNMP_TRAPS"と下記⑥のサービス追加時に指定している「service_description」は同じ値を入れてください。

  • snmptt.iniに以下の項目を追加
[TrapFiles]
# A list of snmptt.conf files (this is NOT the snmptrapd.conf file).  The COMPLETE path
# and filename.  Ex: '/etc/snmp/snmptt.conf'
snmptt_conf_files = <<END
/etc/snmp/snmptt.ini
/etc/snmp/snmptt.conf.IF-MIB
/etc/snmp/snmptt.conf.SNMPv2-MIB
END
  • snmptt再起動
  • snmptrapd.confの設定

authCommunity log,execute,net trapprivate
traphandle default /usr/sbin/snmptthandler
コミュニティ名は任意で付けました(今回はtrapprivate)
あとは確認できるようにログに出力しておく

  • snmptrap再起動

※snmptrapdの起動オプションに「-On」を付けてください

/usr/sbin/snmptrapd -Lsd -On -p /var/run/snmptrapd.pid
こうしておかないとsnmptt側でOIDを変に解釈してしまいunknownトラップとしてnagiosに渡してしまうので

http://snmptt.sourceforge.net/docs/snmptt.shtml

以下のサービスを追加

define service{
use                             local-service         ; Name of service template to use
host_name                       dbt.ln
service_description             SNMP_TRAPS
active_checks_enabled            1
max_check_attempts              1
is_volatile                     1
check_command                   check_dummy!0!"OK"
}
  • nagiosリロード
  • snmptrapコマンドからtrap送信
snmptrap -v 2c -c trapprivate localhost '' .1.3.6.1.6.3.1.1.5.3
tailf /var/log/messages
Oct  1 19:37:56 dbt snmptrapd[3316]: 2010-10-01 19:37:56 dbt.ln [UDP: [127.0.0.1]:52634]: .1.3.6.1.2.1.1.3.0 = Timeticks: (2025240) 5:37:32.40  .1.3.6.1.6.3.1.1.4.1.0 = OID: .1.3.6.1.6.3.1.1.5.3
Oct  1 19:37:57 dbt snmptt[0]: .1.3.6.1.6.3.1.1.5.3 Normal "Status Events" dbt.ln - A linkDown trap signifies that the SNMP entity, acting in $1
Oct  1 19:37:57 dbt nagios: EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;dbt.ln;SNMP_TRAPS;2;A linkDown trap signifies that the SNMP entity, acting in
Oct  1 19:38:06 dbt nagios: PASSIVE SERVICE CHECK: dbt.ln;SNMP_TRAPS;2;A linkDown trap signifies that the SNMP entity, acting in
Oct  1 19:38:06 dbt nagios: SERVICE ALERT: dbt.ln;SNMP_TRAPS;CRITICAL;HARD;1;A linkDown trap signifies that the SNMP entity, acting in
Oct  1 19:38:06 dbt nagios: SERVICE NOTIFICATION: nagiosadmin;dbt.ln;SNMP_TRAPS;CRITICAL;notify-service-by-email;A linkDown trap signifies that the SNMP entity, acting in

うまく動作すると上記のようなメッセージが出力されています。

実際に通知されるnagiosからのメッセージ内容

***** Nagios *****

Notification Type: PROBLEM

Service: SNMP_TRAPS
Host: dbt
Address: 127.0.0.1
State: CRITICAL

Date/Time: Fri Oct 1 19:38:06 JST 2010

Additional Info:

A linkDown trap signifies that the SNMP entity, acting in

これでsnmptrapをnagios経由で通知する事ができますが
各ベンターのmibをsnmpttconvertmibで一つ一つ変換していかないといけないのが
面倒だ…