Wednesday, June 11, 2014

Find and display any and all interface errors easily. Juniper slax script

Whenever I troubleshot a router in a network, I always started at layer 1. However when there were hundreds of links connected to the equipment, narrowing the problem down was difficult.

When there are are many interfaces on your Juniper router, it could take a long time to look at each interface and check to see if there are errors.

Doing a "pipe" and grepping for errors is a mess. You can't find out which interface the counters are associated with.

This simple Juniper slax script will do all the work for you. Saved me many times when I found out the problem was a layer 1 issue.


jnpr@router> op error
Error on input errors:  xe-1/0/2 on input-errors 768
Error on input errors:  xe-1/0/2 on framing-errors 768
Error on input errors:  xe-8/2/3 on input-errors 8
Error on input errors:  xe-8/2/3 on framing-errors 8
Error on input errors:  xe-9/0/1 on input-errors 2
Error on input errors:  xe-9/0/1 on framing-errors 2

---------------

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



match /
{
    <event-op-results> {

        var $interface-info = <command> "show interfaces extensive ";
        var $interface-result = jcs:invoke($interface-info);

        for-each($interface-result/physical-interface)
        {
                var $interface-name = current()/name;
                for-each(current()/input-error-list/*) {
                if(current() != 0)
                {
                        <output>"Error on input errors:  " _ $interface-name _ " on " _ local-name(current()) _ " " _ current();
                }
              }
                for-each(current()/output-error-list/*) {
                if(current() != 0)
                {
                        <output>"Error on output errors:  " _ $interface-name _ " on " _ local-name(current()) _ " " _ current();
                 
                }
              }
        }
      }
}

No comments:

Post a Comment