Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Example: Generate a Custom System Log Message

Junos OS commit scripts can generate custom system log messages during a commit operation to alert you when the configuration does not comply with custom configuration rules. The commit process is not affected by generating system log messages. This example creates a commit script that generates a custom system log message when a specific statement is not included in the device configuration.


Junos OS Release 16.1R3 or later when using a Python script.

Overview and Commit Script

Using a commit script, write a custom system log message that appears when the read-write statement is not included at the [edit snmp community community-name authorization] hierarchy level.

The script is shown in XSLT, SLAX, and Python.

XSLT Syntax

SLAX Syntax

Python Syntax



Step-by-Step Procedure

Download, enable, and test the script. To test that a commit script generates a system log message correctly, make sure that the candidate configuration contains the condition that elicits the system log message. For this example, ensure that the read-write statement is not included at the [edit snmp community community-name authorization] hierarchy level.

To test the example in this topic:

  1. Copy the script into a text file, name the file read-write.xsl, read-write.slax, or as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.


    Unsigned Python scripts must be owned by either root or a user in the Junos OS super-user login class, and only the file owner can have write permission for the file.

  2. In configuration mode, configure the file statement and the script filename at the [edit system scripts commit] hierarchy level.

  3. If the script is written in Python, enable the execution of unsigned Python scripts.


    Configure the language python3 statement to use Python 3 to execute Python scripts, or configure the language python statement to use Python 2.7 to execute Python scripts. For more information, see language.

  4. (Optional) To test the condition, if the read-write statement is included at the [edit snmp community community-name authorization] hierarchy level for every community, temporarily delete the authorization for an existing SNMP community.

  5. Issue the following command to verify that system logging is configured to write to a file (a commonly used file name is messages):

    For information about system log configuration, see the System Log Explorer.

  6. Issue the commit command to commit the configuration.


Verifying Script Execution


Verify the system log message generated by the commit script.


System log messages are generated during a commit operation for Python, SLAX, and XSLT scripts, but they are only generated during a commit check operation for Python scripts. This means you cannot use the commit check | display xml or commit check | display detail configuration mode commands to verify the output of system log messages for SLAX and XSLT scripts.


When the commit operation completes, inspect the system log file. The default directory for log files is /var/log/. View the log file by issuing the show log filename operational mode command. For example, if messages are logged to the messages file, issue the following command:

System log entries generated by commit scripts have the following format:

Since the read-write statement was not included at the [edit snmp community community-name authorization] hierarchy level, the commit script should generate the “SNMP community does not have read-write access” message in the system log file.