Examples: Generating Custom Warning, Error, and System Log Messages
- Example: Generating a Custom Warning Message
- Example: Generating a Custom Error Message
- Example: Generating a Custom System Log Message
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 used in Generating a Custom Warning, Error, or System Log Message.)
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 Warning Message Generated by the Commit 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:
- Copy the XSLT script from the preceding section into a
text file named
source-route.xsl. - Copy the
source-route.xslfile to the/var/db/scripts/commitdirectory on the device hard drive or the/config/scripts/commitdirectory on the flash drive. 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.xslIf 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-routeIssue 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 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 detail2009-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
Example: Generating a Custom Error Message
Using a commit script, write a custom error message that appears when the description statement is not included at the [edit interfaces t1-fpc/pic/port] hierarchy level:
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:variable name="interface" select="interfaces/interface"/>
<xsl:for-each select="$interface[starts-with(name, 't1-')]">
<xsl:variable name="ifname" select="."/>
<xsl:if test="not(description)">
<xnm:error>
<xsl:call-template name="jcs:edit-path"/>
<xsl:call-template name="jcs:statement"/>
<message>Missing a description for this T1 interface.</message>
</xnm:error>
</xsl:if>
</xsl:for-each>
</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 {
var $interface = interfaces/interface;
for-each ($interface[starts-with(name, 't1-')]) {
var $ifname = .;
if (not(description)) {
<xnm:error> {
call jcs:edit-path();
call jcs:statement();
<message> "Missing a description for this T1 interface.";
}
}
}
}
Verifying the Error Message Generated by the Commit Script
To test that a commit script generates an error message correctly, make sure that the candidate configuration contains the condition that elicits the error. For this example, ensure that the configuration for a T1 interface does not include the description statement.
To test the example in this topic, perform the following steps:
- Copy the XSLT script from the preceding section into a
text file named
description.xsl. - Copy the
description.xslfile to the/var/db/scripts/commitdirectory on the device hard drive or the/config/scripts/commitdirectory on the flash drive. Include the file description.xsl statement at the [edit system scripts commit] hierarchy level:
user@host> edit[edit]user@host# set system scripts commit file description.xslIf the configuration for every T1 interface includes the description statement, issue the following configuration mode commands:
[edit]user@host# edit interfaces t1-0/0/1[edit interfaces t1-0/0/1]user@host# delete descriptionIssue the commit command. The following output appears:
[edit]
user@host# commit
[edit interfaces interface t1-0/0/1]
'description'
Missing a description for this T1 interface.
[edit interfaces interface t1-0/0/2]
'description'
Missing a description for this T1 interface.
error: 2 errors reported by commit scripts
error: commit script failure
To display the XML-formatted version of the error message, issue the commit check | display xml command:
[edit interfaces t1-0/0/1]
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:error>
<edit-path>
[edit interfaces interface t1-0/0/1]
</edit-path>
<statement>
description
</statement>
<message>
Missing a description for this T1 interface.
</message>
</xnm:error>
<xnm:error>
<edit-path>
[edit interfaces interface t1-0/0/2]
</edit-path>
<statement>
description
</statement>
<message>
Missing a description for this T1 interface.
</message>
</xnm:error>
<xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm"
xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<message>
2 errors reported by commit scripts
</message>
</xnm:error>
<xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm"
xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<message>
commit script failure
</message>
</xnm:error>
</routing-engine>
</commit-results>
<cli>
<banner>[edit interfaces]</banner>
</cli>
</rpc-reply>
To display a detailed trace of commit script processing, issue the commit check | display detail command:
[edit interfaces t1-0/0/1]
user@host# commit check | display detail2009-06-15 15:56:09 PDT: reading commit script configuration
2009-06-15 15:56:09 PDT: testing commit script configuration
2009-06-15 15:56:09 PDT: opening commit script '/var/db/scripts/commit/error.xsl'
2009-06-15 15:56:09 PDT: reading commit script 'error.xsl'
2009-06-15 15:56:09 PDT: running commit script 'error.xsl'
2009-06-15 15:56:09 PDT: processing commit script 'error.xsl'
[edit interfaces interface t1-0/0/1]
'description'
Missing a description for this T1 interface.
[edit interfaces interface t1-0/0/2]
'description'
Missing a description for this T1 interface.
2009-06-15 15:56:09 PDT: 2 errors from script 'error.xsl'
error: 2 errors reported by commit scripts
error: commit script failure
Example: Generating a Custom System Log Message
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.
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:for-each select="snmp/community">
<xsl:if test="not(authorization/read-write)">
<syslog>
<message>SNMP community does not have read-write access.
</message>
</syslog>
</xsl:if>
</xsl:for-each>
</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 {
for-each (snmp/community) {
if (not(authorization/read-write)) {
<syslog> {
<message> "SNMP community does not have read-write access.";
}
}
}
}
Verifying the System Log Message Generated by the Commit Script
System log messages are generated during a commit operation but not during a commit check operation. This means you cannot use the commit check | display xml and commit check | display detail configuration mode commands to verify the output of system log messages.
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. In 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, perform the following steps:
- Copy the XSLT script from the preceding section into a
text file named
read-write.xsl. - Copy the
read-write.xslfile to the/var/db/scripts/commitdirectory on the device hard drive or the/config/scripts/commitdirectory on the flash drive. Include the file read-write.xsl statement at the [edit system scripts commit] hierarchy level:
user@host> edit[edit]user@host# set system scripts commit file read-write.xslIf the read-write statement is included at the [edit snmp community community-name authorization] hierarchy level, issue the following configuration mode command:
[edit]user@host# delete snmp community community-name authorization read-write- For information about system log configuration, see the Junos System Log Messages Reference.
Issue the following command to verify that system logging is configured to write to a file (a commonly used file name is
messages):[edit]user@host# show system syslog Issue the commit command:
[edit]user@host# commit
When the commit operation completes, inspect the system log
file. The default directory for log files is /var/log. System log entries generated by commit scripts have the following
format:
timestamp router-id cscript: message
For example:
Jun 3 14:34:37 router cscript: SNMP community does not have read-write access
Hide Navigation Pane
Show Navigation Pane
Download
SHA1