Junos
Reply
New User
clintonw
Posts: 1
Registered: ‎02-16-2009
0

Generate syslog message from JUNOS op script

 

I'm trying to generate a syslog message from a JUNOS op script (XSL) and I can't fine the right syntax.  I found a commit script example, but it doesn't seem to work well for an op script.   Are there parameters that can be passed to syslog in order to set the group and priority? 

 

<?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="/">
        <op-script-results>
    <syslog>
        <message>This is a test. 
        </message>
    </syslog>

        </op-script-results>
    </xsl:template>

</xsl:stylesheet>

 

 

 

 

Juniper Employee
Arborist
Posts: 7
Registered: ‎06-24-2008

Re: Generate syslog message from JUNOS op script

I don't know what you mean by priority and group, but here is a script to send a syslog message. You need to use 9.3 which allows the script to connect to mgd.

 

syslog configuration on the router is setup to send any warnings or higher conditions to the server.

 

example:

 



jnpr@Walnut-RE0# show system
host-name Walnut-RE0;
scripts {
op {
file log.xsl;
}
}
syslog {
host x.x.x.x {
any warning;
interactive-commands any;
facility-override local1;
log-prefix RE0;
}
file messages {
any any;
interactive-commands none;
archive size 10m files 10;
}
}

[edit]
jnpr@Walnut-RE0# run op log

[edit]
jnpr@Walnut-RE0# run show log messages | last 5
Feb 17 15:08:58 Walnut-RE0 cscript: INFO - This is a syslog message
Feb 17 15:08:58 Walnut-RE0 cscript: WARNING - This is a syslog message
Feb 17 15:08:58 Walnut-RE0 cscript: ERROR - This is a syslog message

Syslog server: (NOTE: No Info message sent)

 

Feb 17 15:08:58 RE0: cscript: WARNING - This is a syslog message
Feb 17 15:08:58 RE0: cscript: ERROR - This is a syslog message

 

As you can see you can define the types of user conditions in the syslog messages based on "user.xxxx" see below

 Is that what you mean by priority?

 

Now here is the source code:

 

 


<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/ju
nos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/com
mit-scripts/1.0" version="1.0">
<!--
* OP script that will send messages to syslog server
*
-->
<xsl:import href="../import/junos.xsl"/>
<xsl:template match="/">
<!--
* Open connection with mgd
-->
<xsl:variable name="con" select="jcs: open()"/>
<xsl:choose>
<xsl:when test="not($con)">
<xsl:call-template name="emit-error">
<xsl:with-param name="message" select="&quot;Not able to connect to local mgd&quot;"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:call-template name="emit-info">
<xsl:with-param name="message" select="' INFO - This is a syslog message'"/>
</xsl:call-template>
<xsl:call-template name="emit-warning">
<xsl:with-param name="message" select="' WARNING - This is a syslog message'"/>
</xsl:call-template>
<xsl:call-template name="emit-error">
<xsl:with-param name="message" select="' ERROR - This is a syslog message'"/>
</xsl:call-template>

<!--
* Close the mgd connection
-->
<xsl:value-of select="jcs:close($con)"/>
</xsl:template>
<xsl:template name="emit-info">
<xsl: param name="message"/>
<xsl:value-of select="jcs:syslog('user.info', $message)"/>
</xsl:template>
<xsl:template name="emit-warning">
<xsl: param name="message"/>
<xsl:value-of select="jcs:syslog('user.warning', $message)"/>
</xsl:template>
<xsl:template name="emit-error">
<xsl: param name="message"/>
<xsl:value-of select="jcs:syslog('user.error', $message)"/>
</xsl:template>

</xsl:stylesheet>

 

Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.