2016年12月19日月曜日

ZABBIX SNMP Trap 設定

【snmp/snmptrap】

# yum -y install net-snmp
# yum -y install net-snmp-utils
# yum -y install snmptt
# yum install perl-Sys-Syslog


# firewall-cmd --permanent --zone=public --add-service=snmp
# firewall-cmd --permanent --zone=public --add-service=snmptrap
# firewall-cmd --reload
# firewall-cmd --list-all

# vi /etc/snmp/snmptrapd.conf<< __EOF__

authCommunity execute public
traphandle default /usr/sbin/snmptthandler

__EOF__

【参考】Vendor MIBの登録(snmptt使用時は、必ずしも必要ではない。)

# mkdir /usr/share/snmp/vendors-mibs               <-- Vendor固有のMIB格納場所
# ls /usr/share/snmp/vendors-mibs
 FORTINET-CORE-MIB.MIB
 FORTINET-FORTIGATE-MIB.MIB

# vi /etc/snmp/snmp.conf
MIBDIRS /usr/share/snmp/mibs:/usr/share/snmp/vendors-mibs
MIBS all

# snmptranslate .1.3.6.1.4.1.9.9.46.2.0.7              <-- 確認

※MIBファイルからsnmptt.confファイル作成
# snmpttconvertmib --in /usr/share/snmp/vendors-mibs/FORTINET-CORE-MIB.MIB --out snmptt.conf.core.fortinet

# snmpttconvertmib --in /usr/share/snmp/vendors-mibs/FORTINET-FORTIGATE-MIB.MIB --out snmptt.conf.fortigate.fortinet


# vi /etc/sysconfig/snmptrapd
OPTIONS="-On -Lsd -p /var/run/snmptrapd.pid -M /usr/share/snmp/mibs:/usr/share/snmp/vendors-mibs -m all"

# vi  /etc/snmp/snmptt.ini
mode = daemon
log_file = /var/log/snmptt/snmptt.log
date_time_format = %Y/%m/%d %H:%M:%S

syslog_enable =1
           ↓
syslog_enable = 0


■Zabbixサーバの設定と再起動

# vi /etc/zabbix/zabbix_server.conf

SNMPTrapperFile=/var/log/snmptt/snmptt.log

# StartSNMPTrapper=0
               ↓
StartSNMPTrapper=1


# systemctl restart zabbix-server
# systemctl enable zabbix-server

(参考-クライアントの起動)
# systemctl restart zabbix-agent
# systemctl enable zabbix-agent


■SNMPTTの設定。
# vi /etc/snmp/snmptt.ini

snmptt_conf_files = <<END
/etc/snmp/conf.d/snmptt.conf.generic
/etc/snmp/conf.d/snmptt.conf.cisco
/etc/snmp/conf.d/snmptt.conf.f5
/etc/snmp/conf.d/snmptt.conf.yamaha
/etc/snmp/conf.d/snmptt.conf.core.fortinet
/etc/snmp/conf.d/snmptt.conf.fortigate.fortinet
END

# mkdir /etc/snmp/conf.d
このディレクトリに各社の変換したファイルを格納。

■ZABBIX Webへの設定
「設定」→ホスト 該当ホスト選択後、
SNMPインタフェース にIPアドレス入力。

■ZABBIXの設定

1) テンプレート作成
設定→テンプレート→テンプレートの作成
テンプレート名:CXD_Template_SNMP_Trap
所属グループ:必要な所属グループを選択
 Managemant Servers
 Network Devices



■Templatesの作成

2) アプリケーション作成
設定→テンプレート→テンプレート行のアプリケーションを選択し、アプリケーションの作成
名前:SNMP Trap 受信アプリケーション

3) アイテムの作成
設定→テンプレート行のアイテムを選択し、アイテムの作成
名前:SNMP Trap  受信アイテム
タイプ:SNMPトラップ
キー:snmptrap
データ型:ログ
ログの時間の形式:yyyy/MM/dd hh:mm:ss
ヒストリ保存期間:90
説明:SNMP TRAPを受信しました。
有効:チェック

3) トリガーの作成
設定→テンプレート行のトリガーを選択し、トリガーの作成
名前:SNMP Trap の受信 from {HOST.NAME}
深刻度:重要な障害
条件式:
障害:{CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].str(Failure)}<>0
復旧:{CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].str(Recovered)}<>0
手動でクローズ許可:○
説明:{HOST.NAME}からSNMP TRAPを受信しました。


一覧にも戻ってステータスを有効に変更。

※設定→ホスト→ホスト行のトリガー で確認する不明になっていて!マークがついている。???


最後に、該当ホストにテンプレートを設定する。

設定→ホスト選択後、 テンプレートタブを選択し、作成したテンプレートを選択。


■コミュニティ名の変更
管理→一般→マクロ
{$SNMP_COMMUNITY} ⇒ public    ←変更


復旧(参考)
{CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].str(Trap Recovered)}=0&(({TRIGGER.VALUE}=0& {CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].regexp(.*)}=1}| {TRIGGER.VALUE}=1)


({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン障 害)}=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン復旧)}=0))

({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション障 害)}=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション復旧)}=0))







【参考】


【YAMAHA】
#vi /etc/snmp/snmptt.conf.yamaha

#
#
EVENT coldStart .1.3.6.1.6.3.1.1.5.1 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Device reinitialized coldStart
SDESC
YAMAHA Router coldStart
EDESC
#
#
#
EVENT warmStart .1.3.6.1.6.3.1.1.5.2 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Device reinitialized warmStart
SDESC
YAMAHA Router warmStart
EDESC
#
#
#
EVENT linkDown .1.3.6.1.6.3.1.1.5.3 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Link Down on LAN interface $1.
SDESC
YAMAHA Router LAN Link Down Event
EDESC
#
#
#
EVENT linkUp .1.3.6.1.6.3.1.1.5.4 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Link Up on LAN interface $1.
SDESC
YAMAHA Router LAN Link Up Event
EDESC
#
#
#
EVENT PPlinkDown .1.3.6.1.4.1.1182.2.3.0.2 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Link Down on PP interface $1.
SDESC
yrIfPpLinkDown
EDESC
#
#
#
EVENT PPlinkUp .1.3.6.1.4.1.1182.2.3.0.3 "Status Events" Normal
FORMAT ZBXTRAP $aA $ar Link Up on PP interface $1.
SDESC
yrIfPpLinkUp
EDESC
#
#







Variable substitution is performed on this string using the following variables:
$A – Trap agent host name (see Note 1)
$aA – Trap agent IP address
$Be – securityEngineID (snmpEngineID) (see Note 7)
$Bu – securityName (snmpCommunitySecurityName) (see Note 7)
$BE – contextEngineID (snmpCommunityContextEngineID) (see Note 7)
$Bn – contextName (snmpCommunityContextName) (see Note 7)
$c – Category
$C – Trap community string
$D – Description text from SNMPTT.CONF or MIB file (see Note 6)
$E – Enterprise trap OID in symbolic format
$e  – Enterprise trap OID in number format
$Fa  – alarm (bell) (BEL)
$Ff  – form feed (FF)
$Fn  – newline (LF, NL)
$Fr  – return (CR)
$Ft  – tab (HT, TAB)
$Fz  – Translated FORMAT line (EXEC only)
$G  – Generic trap number (0 if enterprise trap)
$H  – Host name of the system running SNMPTT
$S  – Specific trap number (0 if generic trap)
$N
最後に、該当ホストにテンプレートを設定する。

設定→ホスト選択後、 テンプレートタブを選択し、作成したテンプレートを選択。




復旧(参考)
{CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].str(Trap Recovered)}=0&(({TRIGGER.VALUE}=0& {CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].regexp(.*)}=1}| {TRIGGER.VALUE}=1)


({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン障 害)}=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン復旧)}=0))

({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション障 害)}
最後に、該当ホストにテンプレートを設定する。

設定→ホスト選択後、 テンプレートタブを選択し、作成したテンプレートを選択。




復旧(参考)
{CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].str(Trap Recovered)}=0&(({TRIGGER.VALUE}=0& {CXD_Template_SNMP_Trap:snmptrap[EMERGENCY].regexp(.*)}=1}| {TRIGGER.VALUE}=1)


({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン障 害)}=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(ファン復旧)}=0))

({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション障 害)}=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション復旧)}=0))

=1)or(({TRIGGER.VALUE}=1)and({CXD_Template_SNMP_Trap:snmptrap["Status Events"].str(リンクアグリケーション復旧)}=0))

– Event name defined in .conf file of matched entry
$i  – Event OID defined in .conf file of matched entry (could be a wildcard OID)
$O – Trap OID in symbolic format (see Note 4)
$o – Trap OID in numerical format (see Note 4)
$R, $r  – Trap hostname (see Note 1)
$aR, $ar – IP address
$s  – Severity
$T  – Uptime:  Time since network entity was initialized
$X  – Time trap was spooled (daemon mode) or current time (standalone mode)
$x  – Date trap was spooled (daemon mode) or current date (standalone mode)
$# – Number of (how many) variable-bindings in the trap
$$  – Print a $
$@ – Number of seconds since the epoch of when the trap was spooled (daemon mode) or the current time (standalone mode)
$n  – Expand variable-binding n (1-n(see Note 2,5)
$+n  – Expand variable-binding n (1-n) in the format of variable name:value (see Note 2,3,5)
$-n  – Expand variable-binding n (1-n) in the format of variable name (variable type):value (see Note 2,3,5)
$vn  – Expand variable name of the variable-binding n (1-n)(see Note 3)
$*  – Expand all variable-bindings (see Note 5)
$+*  – Expand all variable-bindings in the format of variable name:value (see Note 2,3,5)
$-*  – Expand all variable-bindings in the format of variable name (v
#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public  localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。

ariable type):value (see Note 2,3,5)

出展: https://log4hc.wordpress.com/2011/09/19/snmp-trap-translator-v1-3/

参考:http://ricemalt.blog98.fc2.com/blog-category-5.html










#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。
http://snmptt.sourceforge.net/docs/snmptt.shtml

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。

#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。
http://snmptt.sourceforge.net/docs/snmptt.shtml

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。






ログローテートの設定

#vi /etc/logrotate.d/snmptt
/var/log/snmptt/snmptt*.log /var/log/snmptt/snmptthandler.debug {
 weekly
 notifempty
 missingok
}

/var/log/snmptt/snmptt.debug {
 weekly
 notifempty
 missingok
 postrotate
 /etc/init.d/snmptt reload >/dev/null 2>/dev/null || true
 endscript
}
#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。
http://snmptt.sourceforge.net/docs/snmptt.shtml

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。
http://snmptt.sourceforge.net/docs/snmptt.shtml

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。

# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。




#vi /etc/snmp/snmptt.conf

下記追加

#
# Zabbixテスト用
#
EVENT general .* "General event" Normal
FORMAT ZBXTRAP $aA $*

※snmptt.confについては、下記を参照。
http://snmptt.sourceforge.net/docs/snmptt.shtml

# systemctl enable snmptt
# systemctl start snmptt

# systemctl enable snmptrapd
# systemctl start snmptrapd


【snmptrap確認】
# snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.3
# snmptrap -v 2c -c public 192.168.25.199 '' systemStats 1 s "TEST TRAP Message"
# snmptrap -v 2c -c public localhost '' .1.3.6.1.4.1.8072.99999 .1.3.6.1.4.1.8072.99999.1 s "SNMP Trap test message"


# cat /var/log/snmptt/snmptt.log を確認。



















RTX1210
console character en.ascii
ip route default gateway 192.168.25.220
ip lan1 address 142.1.5.220/24
switch control use lan1 on
ip lan2 address 142.1.4.220/24
switch control use lan2 on
ip lan3 address 192.168.25.220/24
switch control use lan3 on
dhcp service server
dhcp server rfc2131 compliant except remain-silent
dhcp scope 1 142.1.5.2-142.1.5.100/24
dns server 128.1.41.5 128.1.30.81
snmp host 192.168.25.199 public public
snmp trap host 192.168.25.199
snmp trap community public
snmpv2c host 192.168.25.199 public public
snmpv2c trap host 192.168.25.199
snmpv2c trap community public
snmpv3 host 192.168.25.199 user 1
snmpv3 trap host 192.168.25.199 user 1
snmp trap enable snmp all
snmp sysname RTX1210
dashboard accumulate traffic on




0 件のコメント:

コメントを投稿

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...