Automation

last person joined: 21 hours ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  How to get a value from "show chassis routing-engine"?

    Posted 09-07-2016 06:41

    Hi,

     

    I'm following this example as the goal is identical:

    http://www.juniper.net/techpubs/en_US/junos11.3/topics/task/operational/snmp-best-practices-utility-mib-using.html

     

    But instead of "show system buffers", I use "show chassis routing-engine".

     

    Problem:

    When I do the line-count for "show chassis routing-engine", I get only 2 lines.

     

    Goal:

    Get the output of control-plane memory (percentage).

     

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

    match / {
    <op-script-results> {
    var $rpc = <command> "show chassis routing-engine";
    var $result = jcs:invoke($rpc);
    var $lines = jcs:break-lines($result);
    for-each( $lines ) {
    var $line = .;
    <output> "line " _ position() _ ": " _ $line;
    }

    <output> $result;
    }
    }

     

    On CLI:

    root@kim> op memory
    line 1:
    line 2:

     

    OK
    44 degrees C / 111 degrees F
    48 degrees C / 118 degrees F
    1024
    645
    63
    594
    327
    55
    430
    318
    74
    1
    16
    1
    82
    RE-J2320-2000
    XXXXXX
    2016-09-06 00:41:51 UTC
    1 day, 16 hours, 14 minutes, 17 seconds
    0x1:power cycle/failure
    0.01
    0.04
    0.01

     

    I suspect there is a difference between these two outputs and that's the cause, but how can I select only a single value from "show chassis routing-engine"? As I won't be able to match a keyword, I'll need to grab the Xth line from the output, but $result[X] also shows empty value:

     

    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.2R4/junos">
    <route-engine-information xmlns="http://xml.juniper.net/junos/10.2R4/junos-chassis">
    <route-engine>
    <status>OK</status>
    <temperature junos:celsius="44">44 degrees C / 111 degrees F</temperature>
    <cpu-temperature junos:celsius="48">48 degrees C / 118 degrees F</cpu-temperature>
    <memory-system-total>1024</memory-system-total>
    <memory-system-total-used>645</memory-system-total-used>
    <memory-system-total-util>63</memory-system-total-util>
    <memory-control-plane>594</memory-control-plane>
    <memory-control-plane-used>327</memory-control-plane-used>
    <memory-control-plane-util>55</memory-control-plane-util>
    <memory-data-plane>430</memory-data-plane>
    <memory-data-plane-used>318</memory-data-plane-used>
    <memory-data-plane-util>74</memory-data-plane-util>
    <cpu-user>0</cpu-user>
    <cpu-real-time>12</cpu-real-time>
    <cpu-system>6</cpu-system>
    <cpu-idle>82</cpu-idle>
    <model>RE-J2320-2000</model>
    <serial-number>XXXXXX</serial-number>
    <start-time junos:seconds="1473122511">2016-09-06 00:41:51 UTC</start-time>
    <up-time junos:seconds="144707">1 day, 16 hours, 11 minutes, 47 seconds</up-time>
    <last-reboot-reason>0x1:power cycle/failure </last-reboot-reason>
    <load-average-one>0.07</load-average-one>
    <load-average-five>0.06</load-average-five>
    <load-average-fifteen>0.02</load-average-fifteen>
    </route-engine>
    </route-engine-information>
    <cli>
    <banner></banner>
    </cli>
    </rpc-reply>

     

    vs.

     

    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.2R4/junos">
    <output>
    6/519/525 mbufs in use (current/cache/total)
    4/306/310/20640 mbuf clusters in use (current/cache/total/max)
    0/128 mbuf+clusters out of packet secondary zone in use (current/cache)
    0/0/0/0 4k (page size) jumbo clusters in use (current/cache/total/max)
    0/0/0/0 9k jumbo clusters in use (current/cache/total/max)
    0/0/0/0 16k jumbo clusters in use (current/cache/total/max)
    9K/741K/751K bytes allocated to network (current/cache/total)
    0/0/0 requests for mbufs denied (mbufs/clusters/mbuf+clusters)
    0/0/0 requests for jumbo clusters denied (4k/9k/16k)
    0/3/640 sfbufs in use (current/peak/max)
    0 requests for sfbufs denied
    0 requests for sfbufs delayed
    0 requests for I/O initiated by sendfile
    0 calls to protocol drain routines
    </output>
    <cli>
    <banner></banner>
    </cli>
    </rpc-reply>

     

    Thanks,

    Roberts

     



  • 2.  RE: How to get a value from "show chassis routing-engine"?
    Best Answer

    Posted 09-07-2016 07:58

    Hi

     

    Most of Junos commands (RPCs) are able to produce native XML output, so no need for parsing text as with "show system buffers" (this seems to be one of exceptions).

     

    Consider the following script that sloves your initial task

     

    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";
    
    match / {
      <op-script-results> {
        var $rpc = <command> "show chassis routing-engine"; 
        var $result = jcs:invoke($rpc);
          <output> "RE memory utlization: " _ $result/route-engine/memory-control-plane-util;
      }
    }
    

    Running:

    lab@vSRX-1> show chassis routing-engine    
    Routing Engine status:
        Total memory              2048 MB Max   799 MB used ( 39 percent)
          Control plane memory    1150 MB Max   368 MB used ( 32 percent)
          Data plane memory        898 MB Max   440 MB used ( 49 percent)
        CPU utilization:
          User                       1 percent
          Background                 0 percent
          Kernel                     0 percent
          Interrupt                  0 percent
          Idle                      99 percent
        Model                          FIREFLY-PERIMETER RE
        Start time                     2016-08-29 02:49:10 MSK
        Uptime                         9 days, 18 hours, 50 minutes, 47 seconds
        Last reboot reason             Router rebooted after a normal shutdown.
        Load averages:                 1 minute   5 minute  15 minute
                                           0.00       0.00       0.00
    
    lab@vSRX-1> op url /var/db/scripts/op/re.slax    
    RE memory utlization: 32

    Tell me if you have questions.

     

     



  • 3.  RE: How to get a value from "show chassis routing-engine"?

     
    Posted 09-07-2016 08:01

    Rather than trying to screen scrape the values by selecting the Xth line, it is better to make use of the XML structure that is available.

     

    So, as a starting point you could try:

    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";
    
    match / {
        <op-script-results> {
            var $conn = jcs:open();
            var $rpc = <get-route-engine-information>;
            var $result = jcs:execute($conn, $rpc);
            expr jcs:close($conn);
            <output> $result/route-engine/memory-control-plane-util;
        }
    }

    So, rather than use a command rpc to execute the command, I"ve used the natiive rpc <get-route-engine-information>, this can be found by performing a "show chassis routing-engine | display xml rpc" command.

     

    In this scenario, there isnt much difference from using an invoke vs an open,execute,close.  However if you ever need to execute multiple RPC's then it is far better to use open/execute/close, as invoke will create and tear down a session each time that it is called which is slow.

     

    Finally, rather than parse each line of the rpc reply to print the value, it is better to just use the path to the data that you wish to display.

     

    Anyway, a starting point at least.

     

    Regards,

    Andy

     

     



  • 4.  RE: How to get a value from "show chassis routing-engine"?

    Posted 09-07-2016 12:56

    Thank you guys! That was exactly what I was looking for! And nice tips for me as newbie in this topic.

     

    Thanks,

    Roberts