Nagiosにてsnmpによる値監視をするにあたり、nagios-plugins 「check_snmp」が用意されている。
ググると、トラフィックの監視事例が上位にHitする。
値が+方向に上昇していくパターンを監視しようというものだ。
今回やりたかった事は、値が1=正常、0=異常という事をやりたい。
例えば、NW機器の物理ポート(SWHUBのPort1)I/FがLinkUpしているかどうかという場合だ。
OID:
・ifAdminStatus(.1.3.6.1.2.1.2.2.1.7)
1 - Up
2 - Down
3 - Testing
・ifOperStatus(.1.3.6.1.2.1.2.2.1.8)
1 - Up
2 - Down
3 - Testing
5 - Dormant(休止)
6 - notPresent
上記の場合は、ifAdminStatus=1, ifOperStatus =1 が正常なので、1以外の値は異常(Critical)とした場合、
(Warningはなし)
check_snmp -H 192.168.1.1 -P 2c -C public -o .1.3.6.1.2.1.2.2.1.7.1 -c 1:1
「1:1」と下限値:上限値 を指定する。この値なら正常。この値以外は異常となる。
詳しくは、
check_snmp -h
にて、
Notes:
- Multiple OIDs (and labels) may be indicated by a comma or space-delimited
list (lists with internal spaces must be quoted).
- See:
https://www.nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT
for THRESHOLD format and examples.
- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'
- Note that only one string and one regex may be checked at present
- All evaluation methods other than PR, STR, and SUBSTR expect that the value
returned from the SNMP query is an unsigned integer.
と書かれており、上記URLの [Threshold and Ranges] を参照して欲しい。
一部抜粋
Table 4. Command line examples
Command line | Meaning |
check_stuff -w10 -c20 | Critical if "stuff" is over 20, else warn if over 10 (will be critical if "stuff" is less than 0) |
check_stuff -w~:10 -c~:20 | Same as above. Negative "stuff" is OK |
check_stuff -w10: -c20 | Critical if "stuff" is over 20, else warn if "stuff" is below 10 (will be critical if "stuff" is less than 0) |
check_stuff -c1: | Critical if "stuff" is less than 1 |
check_stuff -w~:0 -c10 | Critical if "stuff" is above 10; Warn if "stuff" is above zero (will be critical if "stuff" is less than 0) |
check_stuff -c5:6 | Critical if "stuff" is less than 5 or more than 6 |
check_stuff -c@10:20 | OK if stuff is less than 10 or higher than 20, otherwise critical |
今回、例にしたOIDは正の整数しか値として格納されない想定だが、
check_snmp 以外にも同様に、-w , -c の値を範囲指定する事が可能なプラグインが存在する。
状況に応じて、範囲の書き方を確認しないと、予想値以外の値が格納された場合、本来は異常となって欲しいのに、”正常”とみなされる場合があるので注意が必要だ。