Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Example: Generating a Custom Warning Message

This example commit script generates a custom warning message when a specific statement is not included in the device configuration. The commit process is not affected by warnings.

Requirements

This example uses a device running Junos OS.

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. (This example is the complete script for the sample <xnm:warning> element used in Generating a Custom Warning, Error, or System Log Message.)

The script is shown in both XSLT and SLAX syntax.

XSLT Syntax

<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:junos="http://xml.juniper.net/junos/*/junos"
    xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
    xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
    <xsl:import href="../import/junos.xsl"/>
 
    <xsl:template match="configuration">
        <xsl:if test="not(chassis/source-route)">
            <xnm:warning>
                <xsl:call-template name="jcs:edit-path">
                    <xsl:with-param name="dot" select="chassis"/>
                </xsl:call-template>
                <message>IP source-route processing is not enabled.</message>
            </xnm:warning>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

SLAX Syntax

version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
 
match configuration {
    if (not(chassis/source-route)) {
        <xnm:warning> {
            call jcs:edit-path($dot = chassis);
            <message> "IP source-route processing is not enabled.";
        }
    }
}

Configuration

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, perform the following steps:

  1. Copy the XSLT or SLAX script into a text file, name the file source-route.xsl or source-route.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.
  2. In configuration mode, include the file statement at the [edit system scripts commit] hierarchy level and source-route.xsl or source-route.slax as appropriate.

    [edit]user@host# set system scripts commit file source-route.xsl
  3. If the source-route statement is included at the [edit chassis] hierarchy level, issue the delete chassis source-route configuration mode command:

    [edit]user@host# delete chassis source-route
  4. Issue the commit and-quit command.

    [edit]user@host# commit and-quit

Verification

Verifying Script Execution

Purpose

Verify the warning message generated by the commit script.

Action

Review the output of the commit command. 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.

[edit]
user@host# commit
[edit chassis]
    warning: IP source-route processing is not enabled.
commit complete

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

[edit]
user@host# commit check | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.0R1/junos">
    <commit-results>
        <routing-engine junos:style="normal">
            <name>re0</name>
            <xnm:warning>
                <edit-path>
                    [edit chassis]
                </edit-path>
                <message>
                    IP source-route processing is not enabled.
                </message>
            </xnm:warning>
            <commit-check-success/>
        </routing-engine>
    </commit-results>
</rpc-reply>

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

[edit]
user@host# commit check | display detail
2009-06-15 14:40:29 PDT: reading commit script configuration
2009-06-15 14:40:29 PDT: testing commit script configuration
2009-06-15 14:40:29 PDT: opening commit script '/var/db/scripts/commit/source-route-warning.xsl'
2009-06-15 14:40:29 PDT: reading commit script 'source-route-warning.xsl'
2009-06-15 14:40:29 PDT: running commit script 'source-route-warning.xsl'
2009-06-15 14:40:29 PDT: processing commit script 'source-route-warning.xsl'
[edit chassis]
    warning: IP source-route processing is not enabled.
2009-06-15 14:40:29 PDT: no errors from source-route-warning.xsl
2009-06-15 14:40:29 PDT: saving commit script changes
2009-06-15 14:40:29 PDT: summary: changes 0, transients 0 (allowed), syslog 0
2009-06-15 14:40:29 PDT: no commit script changes
2009-06-15 14:40:29 PDT: exporting juniper.conf
2009-06-15 14:40:29 PDT: expanding groups
2009-06-15 14:40:29 PDT: finished expanding groups
2009-06-15 14:40:29 PDT: setup foreign files
2009-06-15 14:40:29 PDT: propagating foreign files
2009-06-15 14:40:30 PDT: complete foreign files
2009-06-15 14:40:30 PDT: daemons checking new configuration
configuration check succeeds

Published: 2013-03-05