示例:针对事件更改接口配置
可能需要修改配置以响应特定事件。从 Junos OS 版本 12.1 开始,您可以配置事件策略,以便在事件策略由一个或多个特定事件触发时执行配置更改。
此示例使用实时性能监控 (RPM) 探测器为给定接口生成PING_TEST_FAILED事件。从配置的 RPM 探测器收到 60 秒内三个PING_TEST_FAILED事件的第一个实例后,事件策略将执行更改配置事件策略操作,以对指定接口进行管理禁用。如果您的接口一直影响网络性能,则此类操作可能十分必要。
要求
运行 Junos OS 版本 12.1 或更高版本的路由、交换或安全设备。
概述
此示例会创建名为“禁用接口-on-ping-failure”的事件策略。配置事件策略,以便对特定 RPM 探测器生成且与 ge-0/3/1 接口关联的PING_TEST_FAILED事件进行事件进程侦听。如果在 60 秒内给定接口发生三次PING_TEST_FAILED事件,则事件策略将执行更改配置操作。事件策略配置命令以管理方式禁用接口。
要测试事件策略,该示例配置 RPM 探测器,用于 ping 与 ge-0/3/1 接口关联的 IP 地址。在此示例中,ge-0/3/1.0 接口配置了 IPv4 地址 10.1.4.1/26。默认情况下,每个测试发送一个探测器,该示例在测试之间使用 5 秒暂停。在连续三次探查丢失后,RPM 探测器会生成PING_TEST_FAILED事件。由于多个 RPM 测试可以同时运行,因此事件策略会将收到PING_TEST_FAILED事件的和test-name
属性与 RPM 探测器所有者名称和测试名称匹配owner-name
。当 RPM 探测器在 60 秒内生成三个PING_TEST_FAILED事件时,它会触发禁用接口的事件策略。
此事件策略还演示了如何因相同事件或关联事件的发生而多次限制执行相同的配置更改。在此示例中,语 within 60 trigger on 3
句指定配置更改仅在 60 秒内第三次发生PING_TEST_FAILED事件时触发。该 trigger until 4
声明规定,PING_TEST_FAILED事件的后续发生不应导致事件策略再次触发。
如果仅配置 trigger on 3
条件,则提交操作可能会进入环路。将事件策略组合 trigger on 3
并 trigger until 4
防止重复更改相同的配置。
配置
配置 RPM 探测器
CLI 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,移除任何换行符,更改任何必要的详细信息,以便与网络配置匹配,将命令复制粘贴到层级的 CLI 中 [edit]
,然后从配置模式进入 commit
。
set services rpm probe icmp-ping-probe test ping-probe-test probe-type icmp-ping set services rpm probe icmp-ping-probe test ping-probe-test target address 10.1.4.1 set services rpm probe icmp-ping-probe test ping-probe-test test-interval 5 set services rpm probe icmp-ping-probe test ping-probe-test thresholds successive-loss 3 set system syslog file syslog-event-daemon-info daemon info
逐步过程
要配置 RPM 探测器,此示例创建PING_TEST_FAILED事件:
创建名为 ping-probe-test 的 RPM 探测器,其中具有所有者 icmp-ping-probe。
[edit services rpm] bsmith@R1# set probe icmp-ping-probe test ping-probe-test
配置 RPM 探测器以发送 ICMP 回应请求。
[edit services rpm probe icmp-ping-probe test ping-probe-test] bsmith@R1# set probe-type icmp-ping
配置 RPM 探测器,以在 IP 地址 10.1.4.1 上将 ICMP 回应请求发送至 ge-0/3/1 接口。
[edit services rpm probe icmp-ping-probe test ping-probe-test] bsmith@R1# set target address 10.1.4.1
在测试窗口之间配置 5 秒暂停。
[edit services rpm probe icmp-ping-probe test ping-probe-test] bsmith@R1# set test-interval 5
配置 RPM 探测器阈值,以便在连续三次探测丢失后触发PING_TEST_FAILED事件。
[edit services rpm probe icmp-ping-probe test ping-probe-test] bsmith@R1# set thresholds successive-loss 3
在层次结构级别配置新的日志文件
[edit system syslog]
,记录设备daemon
和严重性的info
syslog 事件。这会捕获探查测试期间发送的事件。
[edit system syslog] bsmith@R1# set file syslog-event-daemon-info daemon info
提交配置。
bsmith@R1# commit
结果
在配置模式下,输入 show services
和 show system syslog
命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
[edit] services { rpm { probe icmp-ping-probe { test ping-probe-test { probe-type icmp-ping; target address 10.1.4.1; test-interval 5; thresholds { successive-loss 3; } } } } } system { syslog { file syslog-event-daemon-info { daemon info; } } }
配置事件策略
CLI 快速配置
要快速配置示例的此部分,请复制以下命令,将其粘贴到文本文件中,移除任何换行符,更改任何必要的详细信息,以便与网络配置匹配,将命令复制粘贴到层级的 CLI 中 [edit]
,然后从配置模式进入 commit
。
set event-options policy disable-on-ping-failure events ping_test_failed set event-options policy disable-on-ping-failure within 60 trigger on set event-options policy disable-on-ping-failure within 60 trigger 3 set event-options policy disable-on-ping-failure within 65 trigger until set event-options policy disable-on-ping-failure within 65 trigger 4 set event-options policy disable-on-ping-failure attributes-match ping_test_failed.test-owner matches icmp-ping-probe set event-options policy disable-on-ping-failure attributes-match ping_test_failed.test-name matches ping-probe-test set event-options policy disable-on-ping-failure then change-configuration commands "set interfaces ge-0/3/1 disable" set event-options policy disable-on-ping-failure then change-configuration user-name bsmith set event-options policy disable-on-ping-failure then change-configuration commit-options log "updating configuration from event policy disable-on-ping-failure"
逐步过程
创建和命名事件策略。
[edit] bsmith@R1# edit event-options policy disable-interface-on-ping-failure
配置事件策略以在PING_TEST_FAILED事件上匹配。
[edit event-options policy disable-interface-on-ping-failure] bsmith@R1# set events ping_test_failed
配置策略以在 60 秒内发生三PING_TEST_FAILED事件时触发。
[edit event-options policy disable-interface-on-ping-failure] bsmith@R1# set within 60 trigger on 3
配置语
within 65 trigger until 4
句以防止在发生三次以上PING_TEST_FAILED事件时再次触发策略。[edit event-options policy disable-interface-on-ping-failure] bsmith@R1# set within 65 trigger until 4
配置语
attributes-match
句,以便事件策略仅由相关 RPM 探测器生成的PING_TEST_FAILED事件触发。[edit event-options policy disable-interface-on-ping-failure] bsmith@R1# set attributes-match ping_test_failed.test-owner matches icmp-ping-probe bsmith@R1# set attributes-match ping_test_failed.test-name matches ping-probe-test
指定触发事件策略时执行的配置模式命令。
在单行中配置每个命令,将命令字符串括在引文中,然后指定完整的语句路径。
[edit event-options policy disable-interface-on-ping-failure then change-configuration] bsmith@R1# set commands "set interfaces ge-0/3/1 disable"
使用描述配置更改的评论来配置
log
选项。在通过相关事件策略成功执行提交操作后,将该评论添加到提交日志中。
[edit event-options policy disable-interface-on-ping-failure then change-configuration] bsmith@R1# set commit-options log "updating configuration from event policy disable-interface-on-ping-failure"
(可选)如果有双路由引擎,则配置
synchronize
选项以在两个路由引擎上提交配置。force
包括在其他路由引擎上强制提交的选项,而忽略任何警告。此示例未配置synchronize
和force
选项。(可选)配置对配置进行更改和提交权限的用户名。
如果未指定用户名,则该操作将作为用户
root
执行。[edit event-options policy disable-interface-on-ping-failure then change-configuration] bsmith@R1# set user-name bsmith
在进行配置更改之前,请查看操作模式命令的输出
show interfaces ge-0/3/1
。注意:应启用接口。
bsmith@R1> show interfaces ge-0/3/1 Physical interface: ge-0/3/1, Enabled, Physical link is Up Interface index: 142, SNMP ifIndex: 531 ...
提交配置。
bsmith@R1# commit
结果
在配置模式下,输入 show event-options
命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明以更正配置。
[edit event-options] policy disable-interface-on-ping-failure { events ping_test_failed; within 60 { trigger on 3; } within 65 { trigger until 4; } attributes-match { ping_test_failed.test-owner matches icmp-ping-probe; ping_test_failed.test-name matches ping-probe-test; } then { change-configuration { commands { "set interfaces ge-0/3/1 disable"; } user-name bsmith; commit-options { log "updating configuration from event policy disable-interface-on-ping-failure"; } } } }
验证
确认配置工作正常。
验证事件
目的
要手动测试事件策略,请使 ge-0/3/1 接口脱机,直至生成三个PING_TEST_FAILED事件。
行动
查看已配置的 syslog 文件。验证 RPM 探测器是否在连续丢失的探测器后生成PING_TEST_FAILED事件。
bsmith@R1> show log syslog-event-daemon-info Oct 7 15:48:54 R1 rmopd[1345]: PING_TEST_COMPLETED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test Oct 7 15:49:54 R1 rmopd[1345]: PING_TEST_COMPLETED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test ... Oct 7 15:52:54 R1 rmopd[1345]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host Oct 7 15:52:54 R1 rmopd[1345]: PING_PROBE_FAILED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test Oct 7 15:52:54 R1 rmopd[1345]: PING_TEST_FAILED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test Oct 7 15:52:57 R1 rmopd[1345]: PING_TEST_FAILED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test Oct 7 15:53:00 R1 rmopd[1345]: PING_TEST_FAILED: pingCtlOwnerIndex = icmp-ping-probe, pingCtlTestName = ping-probe-test
验证提交
目的
查看提交日志和消息日志文件,验证事件策略提交操作是否成功。
行动
show system commit
发出操作模式命令以查看提交日志。
bsmith@R1> show system commit 0 2011-10-07 15:53:00 PDT by bsmith via junoscript updating configuration from event policy disable-interface-on-ping-failure 1 2011-09-02 14:16:44 PDT by admin via netconf 2 2011-07-08 14:33:46 PDT by root via other
查看消息日志文件。
bsmith@R1> show log messages | last 20 Oct 7 15:52:54 R1 rmopd[1345]: RMOPD_ICMP_SENDMSG_FAILURE: sendmsg(ICMP): No route to host Oct 7 15:53:00 R1 file[9972]: UI_COMMIT: User 'bsmith' requested 'commit' operation (comment: updating configuration from event policy disable-interface-on-ping-failure) Oct 7 15:53:02 R1 eventd: EVENTD_CONFIG_CHANGE_SUCCESS: Configuration change successful: while executing policy disable-interface-on-ping-failure with user bsmith privileges
意义
操作show system commit
模式命令和消息日志文件的输出验证 Junos OS 是否执行了用于修改和提交配置的已配置事件策略操作。提交操作是在给定日期和时间的用户 bsmith 的权限下通过事件策略完成的,非常成功。show system commit
输出和消息日志文件引用层级语句中指定的log
[edit event-options policy disable-interface-on-ping-failure then change-configuration commit-options]
提交评论。
验证配置更改
目的
查看 [edit interfaces ge-0/3/1]
配置的层次结构级别,以验证配置更改。
行动
bsmith@R1> show configuration interfaces ge-0/3/1 disable; unit 0 { family inet { address 10.1.4.1/26; } }
意义
ge-0/3/1 配置层次结构通过事件策略进行修改,以添加语 disable
句。