System Scripts
Junos automation consists of a suite of tools used to automate operational and configuration tasks on network devices running Junos. In this post we will configure different system scripts on the router.
1. Basic system script configuration
First, we need to copy the scripts to the router:
file copy ftp://user:pass123@192.0.2.1/my-op-script.slax /var/db/scripts/op/
file copy ftp://user:pass123@192.0.2.1/my-commit-script.slax /var/db/scripts/commit/
file copy ftp://user:pass123@192.0.2.1/my-event-script.slax /var/db/scripts/event/file copy ftp://user:pass123@192.0.2.1/my-snmp-script.slax /var/db/scripts/snmp/
The script files must be copied to a specific location, as follows:
- op scripts to:
/var/db/scripts/op/ - commit scripts to:
/var/db/scripts/commit/ - event scripts to:
/var/db/scripts/event/ - snmp scripts to:
/var/db/scripts/snmp/
We can check if the scripts are there:
file list /var/db/scripts/op/
file list /var/db/scripts/commit/
file list /var/db/scripts/event/
file list /var/db/scripts/snmp/
To activate the script we will basically tell Junos where to search the script file. Junos will look in the /var/db/scripts/ locations we mentioned above:
root@r1# set system scripts op file ?
Possible completions:
<name> Local filename of the script file
set system scripts op file my-op-script.slax
set system scripts commit file my-commit-script.slaxset system scripts snmp file my-snmp-script.slax
For event script the activation is a little different. We must activate the script, at the [event-options] hierarchy, Additionally we must also create the event policy that will trigger the script:
set event-options event-script file my-event-script.slax
set event-options policy sylog_if_description events snmp_trap_link_up
set event-options policy sylog_if_description events snmp_trap_link_down
set event-options policy sylog_if_description then event‐script my-event-script.slax
2. Run the scripts
For each script type we can note:
- Op script will run with the
op my-op-script.slaxcommand. - Commit script will run on every commit (we can include the
optionalkeyword to avoid commit failure if file is missing). - Event script will be triggered by an event.
- snmp script will trigger automatically when the SNMP manager requests information from the SNMP agent
3. Python Scripts
Python scripts (.py) is very similar with slax scripts (.slax) in terms of location and enabling, so the CLI commands from the previous chapters remain the same. Only the script file and file extension is different.
But, if we want to execute unsigned Python scripts we do need to configure the following:
set system scripts language python3
4. load-scripts-from-flash
When configured, load commit, event, op, SNMP, and library scripts from the device’s flash memory instead of the hard disk.
set system scripts load-scripts-from-flash
This command will create the new script location: /config/scripts/. Files are not moved automatically from default location to this new one.
External Resources: