JunosでPINGの応答結果をトリガーに所定のコマンドを実行する
event-optionsとrpmの機能を使って実装する。
ルーティングプロトコルなどNW機器の機能で迂回できない故障時などにワークアラウンドとして使うことが多い。
他にもevent-optionsを使えば機器の様々な状態をトリガーに自動設定や自動ログ取得が可能。
自動設定についてはNW機器のデフォルトの動作を変える柔軟さがある反面、運用側からは動作仕様がわかりにくくなる。検討&検証を綿密にしないと後々リスクになる恐れもある。NW導入前なら安易に実装に行く前に論理・構成構成を再検討することも必要。
必要な設定
以下の2項を設定
- **[rpm probe]**配下で監視先へのPING実行方法を定義。
- **[event-options policy]**配下でeventとなるPING結果に対して実施するactionを定義。
決めておくこと
以下命名を決めておく
ICMP-NG-probe
probe 名
sw-icmp-down
probe 用のテスト名
ICMP-NG-event
イベント名
updating configuration from event policy
イベント発生時に出力させるログ文言
set形式のconfig
3秒間隔で10.1.0.1あてにPINGtラッキングを実行。
withinで指定の10秒内で3回PINGがNGとなるとevent-optionsのイベントのトリガになる。トータル15秒以内に次のPINGがNG(4回NG)になった場合はthen以降の処理を実施する。attributes-matchでトリガーとなるイベント属性名を指定しprobe名と紐づけ。then以降でchange-configuration command の後に実行したいset形式のconfigをそのまま""で囲って記載する。
{master:0}
38pinn@L3SW-sby> show configuration | display set | match event-options
set event-options policy ICMP-NG-event events ping_test_failed
set event-options policy ICMP-NG-event within 10 trigger on
set event-options policy ICMP-NG-event within 10 trigger 3
set event-options policy ICMP-NG-event within 15 trigger until
set event-options policy ICMP-NG-event within 15 trigger 4
set event-options policy ICMP-NG-event attributes-match ping_test_failed.test-owner matches ICMP-NG-probe
set event-options policy ICMP-NG-event attributes-match ping_test_failed.test-name matches sw-icmp-down
set event-options policy ICMP-NG-event then change-configuration commands "deactivate interfaces ge-0/0/0"
set event-options policy ICMP-NG-event then change-configuration commit-options log "updating configuration from event policy"
オペレーションモードでconfig表示
{master:0}
38pinn@L3SW-sby> show configuration event-options
policy ICMP-NG-event {
events ping_test_failed;
within 10 {
trigger on 3;
}
within 15 {
trigger until 4;
}
attributes-match {
ping_test_failed.test-owner matches ICMP-NG-probe;
ping_test_failed.test-name matches sw-icmp-down;
}
then {
change-configuration {
commands {
"deactivate interfaces ge-0/0/0";
}
commit-options {
log "updating configuration from event policy";
}
}
}
}
config変更確認
event-optionsのPING-NG-eventをトリガーにge-0/0/0をdeactivateする設定を入れたのでinactiveになった。
{master:0}
38pinn@L3SW-sby> show configuration interfaces
inactive: ge-0/0/0 {
description To:ISP-RT;
unit 0 {
family inet {
address 10.1.0.9/30;
}
}
}
イベント発生時のログ
{master:0}
38pinn@L3SW-sby>
*** messages ***
Mar 22 14:25:49.584 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:25:59.358 2020 L3SW-sby last message repeated 3 times
Mar 22 14:25:59.448 2020 L3SW-sby file[89573]: UI_COMMIT: User 'root' requested 'commit' operation (comment: updating configuration from event policy)
Mar 22 14:25:59.882 2020 L3SW-sby file[89573]: UI_CHILD_EXITED: Child exited: PID 89580, status 7, command '/usr/sbin/mustd'
Mar 22 14:26:00.665 2020 L3SW-sby dcd[89611]: Warning: identical local address found on rt_inst default, intfs me0.0 and em0.0, family inet.
Mar 22 14:26:00.665 2020 L3SW-sby dcd[89611]: DCD_PARSE_WARN_INCOMPATIBLE_CFG: [edit interfaces me0 unit 0 family inet address 192.168.1.1/24] : Incompatible configuration detected : identical local address is found on different interfaces
Mar 22 14:26:02.333 2020 L3SW-sby xntpd[3985]: ntpd 4.2.0-a Thu Oct 24 17:26:47 2019 (1)
Mar 22 14:26:02.355 2020 L3SW-sby dcd[2118]: Warning: identical local address found on rt_inst default, intfs me0.0 and em0.0, family inet.
Mar 22 14:26:02.403 2020 L3SW-sby rpd[2080]: RPD_OSPF_NBRDOWN: OSPF neighbor 10.1.0.10 (realm ospf-v2 ge-0/0/0.0 area 0.0.0.0) state changed from Full to Down due to KillNbr (event reason: interface went down)
Mar 22 14:26:02.425 2020 L3SW-sby mib2d[2079]: SNMP_TRAP_LINK_DOWN: ifIndex 529, ifAdminStatus down(2), ifOperStatus down(2), ifName ge-0/0/0.0
Mar 22 14:26:02.560 2020 L3SW-sby file[89573]: UI_COMMIT_COMPLETED: commit complete
Mar 22 14:26:02.613 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:02.674 2020 L3SW-sby eventd: EVENTD_CONFIG_CHANGE_SUCCESS: Configuration change successful: while executing policy ICMP-NG-event with user root privileges
Mar 22 14:26:05.865 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:09.130 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:11.335 2020 L3SW-sby xntpd[3985]: kernel time sync disabled 2041
Mar 22 14:26:12.381 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:15.642 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:17.335 2020 L3SW-sby xntpd[3985]: kernel time sync enabled 2001
Mar 22 14:26:18.902 2020 L3SW-sby rmopd[2083]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host
Mar 22 14:26:44.955 2020 L3SW-sby last message repeated 8 times
config設定ユーザの確認と変更方法
event-optionsでconfig変更される場合はデフォルトでrootユーザ権限で実行され
以下Commit履歴やlogファイルにはcommit-options logで指定したログが残る。
指定ユーザで実行させたい場合は以下1行設定追加する。
(例:user名が38pinnの場合)
set event-options policy ICMP-NG-event then change-configuration user-name 38pinn
{master:0}
38pinn@L3SW-sby> show system commit
0 2020-03-22 14:26:02 JST by root via junoscript
updating configuration from event policy
1 2020-03-22 14:23:27 JST by 38pinn via cli
---snip---
確認したJUNOSと機種
EX4200-12.3R6.6
EX4600-18.4R2-S2.3