Junos API

From neil.tappsville.com
Jump to navigationJump to search

Ultimately I did not go this way as the statistics we needed could only be gleemed from the cli using expect scripts.

perl module


Info from

Juniper CLI commands are turned into XML which is passed to the engine to run commands.

You can get the query in the following way:


user@host> show chassis alarms | display xml rpc

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.4B1/junos">
    <rpc>
        <get-alarm-information>
        </get-alarm-information>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

you can get the response in the following way:

user@host> show chassis alarms

No alarms currently active


user@host> show chassis alarms | display xml

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.4B1/junos">
    <alarm-information xmlns="http://xml.juniper.net/junos/10.4B1/junos-alarm">
        <alarm-summary>
            <no-active-alarms/>
        </alarm-summary>
    </alarm-information>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

Some commands have no RPC XML equiv... thus can use the following

<xsl:variable name="query">
    <command>
        <xsl:value-of select="concat('show host ', $hostname)"/>
    </command>
</xsl:variable>
<xsl:variable name="result" select="jcs:invoke($query)"/>
<xsl:variable name="host" select="$result"/>
<output>
    <xsl:value-of select="concat('Name: ', $host)"/>
</output>

Nice lookup for cli --> xml commands [1]