[Contents] [Prev] [Next] [Index] [Report an Error]

Example: Generating a Custom Warning Message

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 in Step item.

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.";
        }
    }
}

Verifying the Commit Script Warning Output

To test the output of a warning message, 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 chapter, perform the following steps:

  1. Copy the XSLT script shown just previously into a text file, and name the file source-route.xsl.
  2. Depending on whether you save your commit script files to the flash drive or the hard drive, copy the source-route.xsl file to the /config/scripts/commit or the /var/db/scripts/commit directory on your routing platform.
  3. Include the file source-route.xsl statement at the [edit system scripts commit] hierarchy level:
    user@host> edit
    [edit]
    user@host# set system scripts commit file source-route.xsl

  4. 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
  5. Issue the commit command.

When you issue the commit command, the following output appears:

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

To display the Extensible Markup Language (XML) output of a 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/7.4R1/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
2005-06-14 14:40:29 PDT: reading commit script configuration
2005-06-14 14:40:29 PDT: testing commit script configuration
2005-06-14 14:40:29 PDT: opening commit script '/var/db/scripts/commit/source-route-warning.xsl'
2005-06-14 14:40:29 PDT: reading commit script 'source-route-warning.xsl'
2005-06-14 14:40:29 PDT: running commit script 'source-route-warning.xsl'
2005-06-14 14:40:29 PDT: processing commit script 'source-route-warning.xsl'
[edit chassis]
    warning: IP source-route processing is not enabled.
2005-06-14 14:40:29 PDT: no errors from source-route-warning.xsl
2005-06-14 14:40:29 PDT: saving commit script changes
2005-06-14 14:40:29 PDT: summary: changes 0, transients 0 (allowed), syslog 0
2005-06-14 14:40:29 PDT: no commit script changes
2005-06-14 14:40:29 PDT: exporting juniper.conf
2005-06-14 14:40:29 PDT: expanding groups
2005-06-14 14:40:29 PDT: finished expanding groups
2005-06-14 14:40:29 PDT: setup foreign files
2005-06-14 14:40:29 PDT: propagating foreign files
2005-06-14 14:40:30 PDT: complete foreign files
2005-06-14 14:40:30 PDT: daemons checking new configuration
configuration check succeeds

[Contents] [Prev] [Next] [Index] [Report an Error]