[j-nsp] junosscript call to get negotiated speed/duplex?

Thomas Burnett thomas at intervision.com
Fri Jan 21 12:35:11 EST 2011


Sebastian,

I have used:
    var $command-eth = <command> "show ethernet-switching interfaces detail";
    var $show-eth = jcs:invoke( $command-eth );

to get link status.


/* 
 *  iv-link.slax
 *
 *  Thomas S. Burnett (thomas at intervision.com)
 *  Intervision Systems Technologies inc.
 *  Network PSO
 *  2009 Feb 06
 *
 *  Version History
 *  ===============
 *  v0.1         2009 Feb 06 Initial release.
 *  v0.2         2009 Mar 06 Added remote switch link status
 *  v0.3         2009 Mar 08 cleanup on partner-status and time
 *
 * installation:
 * copy the script to /var/db/scripts/op/iv-link.slax
 *
 * add this line to your config:
 * set system scripts op file iv-link.slax
 * 
 * a better solution is to install your scripts on a server and load them from it.
 *
 * set system scripts op file iv-link.slax source http://junosscript-server/iv-link.slax
 *
 * usage: 
 * you can get data on all interface by running without any arguments
 * 
 * # op iv-link         
 *                            Admin  Oper                                     Bytes      Bytes      Errors     Errors     Partner Partner Partner   
 * Port       Description     Status Status Vlan            Speed      Duplex Input      Output     Input      Output     Status  Duplex  Speed     
 * ge-0/0/0                   up     up     vlan32          Auto       Auto   17520      12903163   0          0          Error   unkn    10 Mbps  
 * ge-0/0/1                   up     down   default         Auto       Auto   0          0          0          0                                    
 * ge-0/0/2                   up     up     vlan32          Auto       Auto   2460       12906541   0          0          OK      full    100 Mbps  
 * 
 * you can get data on one interface by running with an interface <physical-interface> argument
 * 
 * # op iv-link interface ge-0/0/1    
 *                            Admin  Oper                                     Bytes      Bytes      Errors     Errors     Partner Partner Partner   
 * Port       Description     Status Status Vlan            Speed      Duplex Input      Output     Input      Output     Status  Duplex  Speed     
 * ge-0/0/0                   up     up     vlan32          Auto       Auto   17520      12903163   0          0          Error   unkn    10 Mbps  
 * 
 */

/*
*  the next 5 lines are standard junosscript boilerplate, must have it.
*/
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";

/* 
*  get command line arguments
*/
var $arguments = { 
    <argument> { 
        <name> "interface"; 
        <description> "Name of physical interface (e.g. ge-0/0/0)"; 
    }
    <argument> {
        <name> "title";
        <description> "Enter 'no' if you do not want to see the title.";
    } 
} 
 
/* 
*  make command-line argument global
*/ 
param $interface; 
param $title; 

match / {
  <op-script-results> {

    /* 
    *  get interface data to parse
    */
    var $command-int = <command> "show interfaces extensive";
    var $show-int = jcs:invoke( $command-int );

    /* 
    *  get interface vlan data to parse
    */
    var $command-eth = <command> "show ethernet-switching interfaces detail";
    var $show-eth = jcs:invoke( $command-eth );

    /* 
    *  get vlan data to parse
    */
    var $command-time = <command> "show system uptime";
    var $show-time = jcs:invoke( $command-time );
        
    /* 
    *  print title header
    */
    if ( not ($title )) {
      <output> "* " _ $script;
      <output> "* InterVision Systems Technologies, Inc.";
      <output> "* www.intervision.com";
      <output> "* ";
      <output> "* Thomas S. Burnett";
      <output> "* thomas\@intervision.com";
 
      /*
      *  found that time from multi-RE's needed to be treated a bit differently
      */
      if ( $show-time/current-time/date-time ) {
        <output> "* System time: " _ $show-time/current-time/date-time;
      }
      else {
        <output> "* System time: " _ $show-time/multi-routing-engine-item/system-uptime-information/current-time/date-time;
      }
      <output> "* ";
    }

    /* 
    *  print output header
    */
    <output> jcs:printf("%-10.9s %-15.15s %-6s %-6s %-15.14s %-10s %-6s %10s %10s %10s %10s %-7s %-7s %10s", 
       "", "", "Admin", "Oper", "", "", "", "Bytes", "Bytes", "Errors", "Errors", "Partner", "Partner", "Partner" );
    <output> jcs:printf("%-10.9s %-15.15s %-6s %-6s %-15.14s %-10s %-6s %10s %10s %10s %10s %-7s %-7s %10s", 
       "Port", "Description", "Status", "Status", "Vlan", "Speed", "Duplex", "Input", "Output", "Input", "Output", "Status", "Duplex", "Speed");

    /*
    *  extract the data i want from the show interface command and assign it to variables
    */
    for-each ( $show-int/physical-interface ) { 
      var $physical     = name;
      var $logical-name = logical-interface/name;
      var $phy-des      = description;
      var $admin-stat   = admin-status;
      var $oper-status  = oper-status;
      var $rawspeed     = speed;
      var $speed = {
        if ( $rawspeed == "Unspecified" ) {
          <output> "xxxmbps";
        }
        else {
          <output> $rawspeed;
        }
      }
      var $duplex = { 
        if ( duplex ) { 
          <output> duplex;
        }
        else {
          <output> "na";
        }
      }
      var $in-bytes     = logical-interface/local-traffic-statistics/input-bytes;
      var $out-bytes    = logical-interface/local-traffic-statistics/output-bytes;
      var $in-err       = input-error-list/input-errors;
      var $out-err      = output-error-list/output-errors;
      var $partner-statu = ethernet-autonegotiation/link-partner-status;
      var $partner-duplex = ethernet-autonegotiation/link-partner-duplexity;
      var $partner-speed = {
        if ( ethernet-autonegotiation/link-partner-speed ) {
          <output> ethernet-autonegotiation/link-partner-speed;
        }
        else {
          <output> "na";
        }
      }
      var $partner-status = { 
        if ( $partner-statu == "Negotiation error" ) {
          <output> "Error";
        }
        else {
          <output> $partner-statu;
        }
      }

      /* 
      *  ignore interfaces i don't want to print data on
      */
      if ( ( not ( $physical == "bme0"     ) ) and
           ( not ( $physical == ".local."  ) ) and
           ( not ( jcs:empty ( $logical-name ) ) ) ) {

        /*
        *  extract trunk, inet or vlan data 
        */
        var $family = { 

          /* 
          *  is this interface a trunk 
          */ 
          if ( logical-interface/address-family/address-family-flags/ifff-port-mode-trunk ) {
            <output> "TRUNK";
          } 

          /* 
          *  is this a family inet interface 
          */
          else if ( logical-interface/address-family/interface-address/ifa-local ) {
            <output> "INET";
          }
          else { 

          /* 
          *  get interface vlan id 
          */
            for-each ( $show-eth/interface [ interface-name == $logical-name ] ) {
              var $vlan = interface-vlan-member-list/interface-vlan-member/interface-vlan-name; 
              <output> $vlan;
            }
          }
        }

        /* 
        *  print the merged data to the screen for all interfaces
        */
        if ( not ( $interface ) ) {
          <output> jcs:printf("%-10.9s %-15.15s %-6s %-6s %-15.14s %-10.9s %-6.4s %10s %10s %10s %10.8s %-7.6s %-7.4s %10s", 
            $physical, $phy-des, $admin-stat, $oper-status, $family, $speed, $duplex, $in-bytes, $out-bytes, $in-err, $out-err, $partner-status, $partner-duplex, $partner-speed );
        }

        /* 
        *  print merged data to the screen for interfaces provided in the cli
        */
        else if ( $physical == $interface ) {
          <output> jcs:printf("%-10.9s %-15.15s %-6s %-6s %-15.14s %-10.9s %-6.4s %10s %10s %10s %10.8s %-7.6s %-7.4s %10s",
            $physical, $phy-des, $admin-stat, $oper-status, $family, $speed, $duplex, $in-bytes, $out-bytes, $in-err, $out-err, $partner-status, $partner-duplex, $partner-speed );
        }
      } /* if output */
    } /* for-each show-int */
  }
}




Thomas Burnett | Director of Networking and Security | direct 408.567.4245 | cell 408.476.8242

-----Original Message-----
From: juniper-nsp-bounces at puck.nether.net [mailto:juniper-nsp-bounces at puck.nether.net] On Behalf Of Sebastian Wiesinger
Sent: Friday, January 21, 2011 9:21 AM
To: Juniper NSP
Subject: [j-nsp] junosscript call to get negotiated speed/duplex?

Hello,

I'm trying to find a junosscript RPC call to get the negotiated
speed/duplex on a link.

I tried

jcs:invoke( "get-interface-information extensive" );

which doesn't include the information. Oddly enough the CLI command
"show interface extensive | display xml" does:

   <ethernet-autonegotiation>
        <autonegotiation-status>complete</autonegotiation-status>
        <link-partner-status>OK</link-partner-status>
        <link-partner-duplexity>full-duplex</link-partner-duplexity>
        <link-partner-speed>100 Mbps</link-partner-speed>
        <flow-control>None</flow-control>
        <local-info>
            <local-flow-control>Symmetric</local-flow-control>
            <local-remote-fault>Link OK</local-remote-fault>
        </local-info>
    </ethernet-autonegotiation>

Any help in getting this information with the script API would be appreciated.

Kind Regards,

Sebastian

-- 
New GPG Key: 0x93A0B9CE (F4F6 B1A3 866B 26E9 450A  9D82 58A2 D94A 93A0 B9CE)
Old GPG Key-ID: 0x76B79F20 (0x1B6034F476B79F20)
'Are you Death?' ... IT'S THE SCYTHE, ISN'T IT? PEOPLE ALWAYS NOTICE THE SCYTHE.
            -- Terry Pratchett, The Fifth Elephant
_______________________________________________
juniper-nsp mailing list juniper-nsp at puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp



More information about the juniper-nsp mailing list