示例:配置事件策略以上传文件
此示例配置将相关文件上传到指定位置进行分析的事件策略操作。
要求
开始之前:
配置您将在事件策略中参考的目的地。请参阅 示例:按事件策略定义文件存档目标。
配置常规事件策略并触发事件。
概述
当事件策略操作生成输出文件时,您可以将文件存档以进行后续分析。同样,您可能希望从事件发生之时起存档系统文件,包括系统日志文件、核心文件和配置文件。您可以配置事件策略以上传现有系统文件或上传事件发生时从调用的事件脚本或命令中生成的输出文件。本节概述了使用事件策略上传这些输出文件所需的配置。
将事件策略配置为上传文件时,设备会将相关文件上传到为该事件策略操作配置的语句中 destination
引用的位置。您必须指定在层次结构级别上配置的目标 [edit event-options destinations]
名称。
在此示例中,policy1
包含以下语句,触发事件在哪里e1。然后,该示例将事件策略配置为上传日志文件、提交的配置文件以及从和event-script
操作中生成的execute-commands
输出文件。
[edit event-options policy policy1] events e1; then { execute-commands { commands { "show interfaces brief ge-*"; } } event-script event-script1; }
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,移除任何换行符,更改与网络配置匹配所需的任何详细信息,然后将命令复制粘贴到层次结构级别的 [edit]
CLI 中:
set event-options policy policy1 then upload filename /var/log/messages destination mgmt-archives transfer-delay 4 set event-options policy policy1 then upload filename /var/log/messages destination mgmt-archives retry-count 5 retry-interval 4 set event-options policy policy1 then upload filename /var/log/messages destination mgmt-archives user-name admin set event-options policy policy1 then upload filename /var/log/messages destination mgmt-server set event-options policy policy1 then upload filename committed destination mgmt-archives set event-options policy policy1 then execute-commands output-filename ge-interfaces set event-options policy policy1 then execute-commands destination mgmt-archives transfer-delay 5 set event-options policy policy1 then execute-commands destination mgmt-archives retry-count 5 retry-interval 4 set event-options policy policy1 then event-script event-script1 output-filename policy1-script-output set event-options policy policy1 then event-script event-script1 destination mgmt-archives transfer-delay 5 set event-options policy policy1 then event-script event-script1 destination mgmt-archives retry-count 5 retry-interval 4
上传系统文件
逐步过程
配置事件策略 policy1
,将系统文件 /var/log/消息 上传到存档站点 mgmt-file 和 mgmt-server。此外,将提交的配置上传到存档站点 mgmt-archives。目标存档站点应已在 [edit event-options destinations]
层次结构级别配置
配置语
upload
句,并将文件包括到存档和目标存档站点。[edit event-options policy policy1 then] bsmith@R1# set upload filename /var/log/messages destination mgmt-archives bsmith@R1# set upload filename /var/log/messages destination mgmt-server
要上传提交的配置文件,请指定 提交的文件名值。
[edit event-options policy policy1 then] bsmith@R1# set upload filename committed destination mgmt-archives
-
(可选)配置与每个文件和目标关联的传输延迟。
当 /var/log/messages 文件上传到 mgmt-file 目标时,以下命令配置 4 秒的传输延迟。如果还为目标配置传输延迟,则总延迟为两个延迟的总和。
[edit event-options policy policy1 then] bsmith@R1# set upload filename /var/log/messages destination mgmt-archives transfer-delay 4
-
(可选)配置与每个文件和目标关联的重试计数和重试间隔。
在此示例中,如果 /var/log/messages 文件未能上传到 mgmt-file 站点,系统将尝试上传多达 5 次,每次尝试之间等待 4 秒钟。
[edit event-options policy policy1 then] bsmith@R1# set upload filename /var/log/messages destination mgmt-archives retry-count 5 retry-interval 4
-
(可选)配置文件上传操作的用户名。系统使用指定用户的权限上传文件。
[edit event-options policy policy1 then] bsmith@R1# set upload filename /var/log/messages destination mgmt-archives user-name admin
提交配置。
[edit event-options policy policy1 then] bsmith@R1# commit
上传命令输出文件
逐步过程
当事件策略调用 execute-commands
操作时,命令输出可以写入文件。配置事件策略 policy1
,将命令输出写入文件,并将生成的文件上传到目标 mgmt-file,该文件已在 [edit event-options destinations]
层次结构级别配置。
-
定义输出文件的文件名中包含的描述性字符串。
[edit event-options policy policy1 then] bsmith@R1# set execute-commands output-filename ge-interfaces
-
配置语
destination
句以将生成的文件上传到指定的存档站点。[edit event-options policy policy1 then] bsmith@R1# set execute-commands destination mgmt-archives
-
(可选)配置上传操作的传输延迟,此示例为 5 秒。
[edit event-options policy policy1 then] bsmith@R1# set execute-commands destination mgmt-archives transfer-delay 5
-
(可选)配置上传操作的重试计数和重试间隔。
在此示例中,如果上传操作失败,系统将尝试上传多达 5 次,每次尝试之间等待 4 秒。
[edit event-options policy policy1 then] bsmith@R1# set execute-commands destination mgmt-archives retry-count 5 retry-interval 4
提交配置。
[edit event-options policy policy1 then] bsmith@R1# commit
上传事件脚本输出文件
逐步过程
当事件策略调用事件脚本时,脚本输出可以写入文件。配置事件策略 policy1
,将事件脚本输出写入文件,并将生成的文件上传到目标 mgmt-file,该文件已在 [edit event-options destinations]
层次结构级别配置。在此示例中,事件策略调用名为 Event-script1 的事件脚本。
-
定义输出文件的文件名中包含的描述性字符串。
[edit event-options policy policy1 then] bsmith@R1# set event-script event-script1 output-filename policy1-script-output
配置语
destination
句以将生成的文件上传到所需的存档站点。[edit event-options policy policy1 then] bsmith@R1# set event-script event-script1 destination mgmt-archives
-
(可选)配置上传操作的传输延迟,此示例为 5 秒。
[edit event-options policy policy1 then] bsmith@R1# set event-script event-script1 destination mgmt-archives transfer-delay 5
-
(可选)配置上传操作的重试计数和重试间隔。
在此示例中,如果上传发生故障,系统会尝试上传多达 5 次,每次尝试之间等待 4 秒。
[edit event-options policy policy1 then] bsmith@R1# set event-script event-script1 destination mgmt-archives retry-count 5 retry-interval 4
提交配置。
[edit event-options policy policy1 then] bsmith@R1# commit
结果
[edit event-options policy policy1 then] upload filename /var/log/messages destination mgmt-archives { user-name admin; transfer-delay 4; retry-count 5 retry-interval 4; } upload filename /var/log/messages destination mgmt-server upload filename committed destination mgmt-archives; execute-commands { commands { "show interfaces brief ge-*"; } output-filename ge-interfaces; destination mgmt-archives { transfer-delay 5; retry-count 5 retry-interval 4; } } event-script event-script1 { output-filename policy1-script-output; destination mgmt-archives { transfer-delay 5; retry-count 5 retry-interval 4; } }
验证
验证上传
目的
配置的事件触发事件策略时,系统会将生成的输出文件和指定系统文件上传到 mgmt-files 目标中定义的 URL。在目标服务器上,验证所有文件是否已上传。
行动
在目标服务器上,验证上传的所有文件是否都存在。
% ls R1_20111209_213452_ge-interfaces R1_20111209_213409_juniper.conf.gz R1_20111209_212941_messages R1_20111209_212619_policy1-script-output
意义
请注意,每个文件的文件名格式包括设备名称、文件名以及日期和时间戳。
如果上传的所有文件都存在,则事件策略和上传操作正常工作。如果未上传任何文件,请验证目标是否已配置,以及是否正确输入了存档站点 URL 和任何必要的密码。有关配置目标的信息,请参阅 示例:按事件策略定义文件存档的目标。如果缺少部分文件,则配置更长的传输延迟,并增加这些文件的重试计数和重试间隔。