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.";
}
}
}
}
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 the output of a system log message, 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 chapter, perform the following steps:
user@host> edit
[edit]
user@host# set system scripts commit file read-write.xsl
[edit]
user@host# delete snmp community community-name authorization read-write
[edit]
user@host# show system syslog
For information about system log configuration, see the JUNOS System Log Messages Reference.
[edit]
user@host# commit
After you issue the commit command, check the log file. The default directory for log files is /var/log. A common filename for the log file is messages. Commit script system log entries look like this:
timestamp router-id cscript: message
For example:
Jun 3 14:34:37 router cscript: SNMP community does not have read-write access