Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

PFE stats to SNMP values

‎01-02-2015 11:16 AM

I need to get specific PFE stats set to the MIB.  here is my script.  I cant quite seem to parse the values from the "show pfe statistics traffic"

What do I need to change?

 

---- snip ---

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";
ns ext = "http://xmlsoft.org/XSLT/namespace";
ns jhk = "http://xml.juniper.net/jhk";

import "../import/junos.xsl";

match / {

    <op-script-results> {

        var $conn = jcs:open();

        /*
        * Open a connection with mgd
         */
        /* Read the system mbufs */
        var $rsummary-rpc := {<command> "show pfe statistics traffic";}

        var $out = jcs:invoke( $rsummary-rpc );
    var $lines = jcs:break_lines($out);
    <output> $out;

     var $pfe-input-packets := ( $out/pfe-statistics/pfe-local-traffic-statistics/pfe-input-packets );
    var $hardware-input-drops := ( $out/pfe-statistics/pfe-local-traffic-statistics/hardware-input-drops );
    var $info-cell-discard = ( $out/pfe-statistics/pfe-hardware-discard-statistics/info-cell-discard );
    var $fabric-discard := ( $out/pfe-statistics/pfe-hardware-discard-statistics/fabric-discard );

        call snmp-mib-poke( $snmp-object-type = "integer", $snmp-instance-name = "pfe-input-packets", $snmp-object-value = $pfe-input-packets);
        call snmp-mib-poke( $snmp-object-type = "integer", $snmp-instance-name = "hardware-input-drops-chassis", $snmp-object-value = $hardware-input-drops);
    call snmp-mib-poke( $snmp-object-type = "integer", $snmp-instance-name = "info-cell-drops-chassis", $snmp-object-value = $info-cell-discard);
    call snmp-mib-poke( $snmp-object-type = "integer", $snmp-instance-name = "fabric-drops-chassis", $snmp-object-value = $fabric-discard);

        expr jcs:close($conn);
    }
}

template snmp-mib-poke ( $snmp-object-type, $snmp-instance-name, $snmp-object-value ) {
    var $rpc = <request-snmp-utility-mib-set> {
        <object-type> $snmp-object-type;
        <instance> $snmp-instance-name;
        <object-value> $snmp-object-value;
    }
    var $results = jcs:invoke($rpc);
    <output> "Utility MIB " _ $snmp-instance-name _ " has value " _ $snmp-object-value;

 

--- snip ---

1 REPLY 1
Highlighted
Junos Automation (Scripting)

Re: PFE stats to SNMP values

[ Edited ]
‎01-04-2015 06:26 AM

Try the following and see how you get on with it.

 

I've made use of jcs:execute instead of jcs:invoke, as this will only create a single connection for all the RPC calls that are made unlike jcs:invoke which will create a new session each time that it is called.  I've also declared $conn as a global variable so that the same connection can be used within the snmp-mib-poke template too.  Finally, I've used the RPC get-pfe-statistics instead of using the command RPC, which I was able to identify using the following command:  "show pfe statistics traffic | display xml rpc"

 

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

/* open a single connection for all RPCs as a global variable */
var $conn = jcs:open();

match / {
  <op-script-results> {
    var $summary-rpc = <get-pfe-statistics>;
    var $out = jcs:execute($conn,$summary-rpc);

    var $pfe-input-packets = $out/pfe-traffic-statistics/pfe-input-packets;
    var $hardware-input-drops = $out/pfe-local-traffic-statistics/hardware-input-drops;
    var $info-cell-discard = $out/pfe-hardware-discard-statistics/info-cell-discard;
    var $fabric-discard = $out/pfe-hardware-discard-statistics/fabric-discard;

    call snmp-mib-poke($snmp-object-type = "integer",$snmp-instance-name = "pfe-input-packets",$snmp-object-value = $pfe-input-packets);
    call snmp-mib-poke($snmp-object-type = "integer",$snmp-instance-name = "hardware-input-drops-chassis",$snmp-object-value = $hardware-input-drops);
    call snmp-mib-poke($snmp-object-type = "integer",$snmp-instance-name = "info-cell-drops-chassis",$snmp-object-value = $info-cell-discard);
    call snmp-mib-poke($snmp-object-type = "integer",$snmp-instance-name = "fabric-drops-chassis",$snmp-object-value = $fabric-discard);

    /* close connection */
    expr jcs:close($conn);
  }
}

template snmp-mib-poke ($snmp-object-type,$snmp-instance-name,$snmp-object-value) 
{
  var $rpc = <request-snmp-utility-mib-set> {
    <object-type> $snmp-object-type;
    <instance> $snmp-instance-name;
    <object-value> $snmp-object-value;
  }
  var $results = jcs:execute($conn,$rpc);
  <output> "Utility MIB " _ $snmp-instance-name _ " has value " _ $snmp-object-value;
}

 

With a test on an Firefly Perimiter the following output was generated:

 

space@vSRX2> op snmp-set
Utility MIB pfe-input-packets has value 10994935
Utility MIB hardware-input-drops-chassis has value 0
Utility MIB info-cell-drops-chassis has value 0
Utility MIB fabric-drops-chassis has value 0

 

A mib walk of jnxUtilMibRoot will then display the following output.

 

space@vSRX2> show snmp mib walk jnxUtilMibRoot ascii
jnxUtilIntegerValue."fabric-drops-chassis" = 0
jnxUtilIntegerValue."hardware-input-drops-chassis" = 0
jnxUtilIntegerValue."info-cell-drops-chassis" = 0
jnxUtilIntegerValue."pfe-input-packets" = 10995586
jnxUtilIntegerTime."fabric-drops-chassis" = 07 de 0c 0b  0c 33 1a 00  2b 00 00
jnxUtilIntegerTime."hardware-input-drops-chassis" = 07 de 0c 0b  0c 33 1a 00  2b 00 00
jnxUtilIntegerTime."info-cell-drops-chassis" = 07 de 0c 0b  0c 33 1a 00  2b 00 00
jnxUtilIntegerTime."pfe-input-packets" = 07 de 0c 0b  0c 33 1a 00  2b 00 00

 

 

Hope that this helps.

 

 

Feedback