Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Generate a Custom Warning Message

Junos OS commit scripts can generate custom warning 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 warnings. This example creates a commit script that generates a custom warning message when a specific statement is not included in the device configuration.

Requirements

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

Overview and Commit Script

Using a commit script, write a custom warning message that appears when the source-route statement is not included at the [edit chassis] hierarchy level.

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

XSLT Syntax

SLAX Syntax

Python Syntax

Configuration

Procedure

Step-by-Step Procedure

Download, enable, and test the script. To test that a commit script generates a warning message correctly, make sure that the candidate configuration contains the condition that elicits the warning. For this example, ensure that the source-route statement is not included at the [edit chassis] hierarchy level.

To test the example in this topic:

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

    Note:

    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.

    Note:

    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. If the source-route statement is included at the [edit chassis] hierarchy level, issue the delete chassis source-route configuration mode command.

Verification

Verifying Script Execution

Purpose

Verify the warning message generated by the commit script.

Action

Execute the commit check or commit command and review the output. The commit script generates a warning message when the source-route statement is not included at the [edit chassis] hierarchy level of the configuration. The warning does not affect the commit process.

To display the XML-formatted version of the warning message, issue the commit check | display xml command.

To display a detailed trace of commit script processing, issue the commit check | display detail command.