This article provides information on how to take the output of certain commands at fixed intervals or at a particular time during the day. The output can be locally recorded or sent to an external server.
You can schedule, for monitoring and troubleshooting purposes, certain operational commands at regular intervals or fixed time of the day. Scripts can be used for this; but it might be hard to figure out when there is an issue with the script.
Junos Event-Options is used to perform the function of operational scripts.
The Event-Options feature allows you to perform predefined tasks, which are triggered based on the following types of events:
In this case, you can use manually generated events, which can be triggered by users at specific times.
Configuration
set event-options generate-event testEvent time-of-day "10:42:00 +0000"
set event-options policy Policy1 events testEvent
set event-options policy Policy1 then execute-commands commands "show system uptime"
set event-options policy Policy1 then execute-commands output-filename test1
set event-options policy Policy1 then execute-commands destination local-directory
set event-options destinations local-directory archive-sites /var/tmp/
Verify the configuration:
show event-options
generate-event {
testEvent time-of-day "10:42:00 +0000";
}
policy Policy1 {
events testEvent;
then {
execute-commands {
commands {
"show system uptime";
}
output-filename test1;
output-format text;
destination local-directory;
}
}
}
destinations {
local-directory {
archive-sites {
/var/tmp/;
}
}
}
This configuration will generate a testEvent
at 10:42:00 +0000
every day. Policy1
will look for testEvent
. Whenever this event is generated, the SRX device will record the output of the configured command in a local file in /var/tmp/
.
The archive destination can be specified as:
You can check the local directory by using the file list /var/tmp/ details
operation mode command, after the scheduled time.
For more information, refer to Event Policy File Archiving Overview
The target filename will start with a underscore ( _ ), if the hostname (#set system hostname
) is not configured for the device. If it is configured, the filename will start with the hostname.Note:
-
A new file will be generated each time the event is triggered and the name of the new file will contain the corresponding time stamp; so the files will keep on archiving without any limit to the number of files. The output will not append to the previous file.
-
URLs of the file:///
type are not supported; however, local device directories are supported (for example, /var/tmp/).
-
If the generate-event option has time-interval in X seconds specified, then the event will be generated right at the commit of this config and after every X seconds.
-
If the generate-event option has time-of-day specified, then the event will be generated every day (24 hrs fixed interval) at the specified time.
-
Additionally, this configuration can also match system generated events. You can explore the events under set event-options policy <policy-name> events.