Reply
Highlighted
Accepted Solution

NetMRI, Perl and Clear Counters on Cisco devices

Authority
Posts: 42
4379     0

Not sure if I have missed something but having trouble with a simple perl script that uses NetMRI_Easy to try to clear the counters on interfaces of Cisco switches.

 

The issue seems to be with the confirm part, when issuing the IOS command "clear counters". The following prompt from the cisco device is asking for confirmation.

I have tried to add \r and \n in combinations to a separate line, but no avail.

I think it may be the fact that it is waiting for the normal IOS prompt - which it never gets since the prompt is now "[confirm]". the script timesout.

I have tried to add \r and \n to the end of the initial line but this just throws up an error - not a timeout this time.

 

 

CCS works fine but am trying to build up a more complex script that requires Perl.

Using NetMRI 7.1.3

 

Thanks

 

 

 

Re: NetMRI, Perl and Clear Counters on Cisco devices

Adviser
Posts: 406
4380     0

Can you post the script or an example of what you are using?

 

Sif

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: NetMRI, Perl and Clear Counters on Cisco devices

Authority
Posts: 42
4380     0

Hi Sif,

Thanks for the reply.

The initial scripts have been stripped down to isolate the cause.

This seems, at first glance, to be similar to the issue I had with an earlier competitive (at the time) product (alterpoint), where the script was waiting for a valid # prompt from the cisco device. Since the prompt changed to [confirm], the script would timeout because it didnt get the # prompt. However it was possible to change this.

Not sure if this is the issue here or if I am missing something else.

 

 

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
#    $Vendor eq "Cisco"
#    and $Type eq "Switch" or $Type eq "Switch-Router"
#    and $sysDescr like /IOS/
# Script-Variables:
#    
# END-SCRIPT-BLOCK
#The above BEGIN-END script block is mandatory in all scripts (including CCS).
#It is possible to filter out the type of device that the script will be run on. This will be useful for scripts that should NOT be run on particular types of devices due to risks. or for scripts that are only on one vendor device e.g. Cisco & not F5 or Aruba.
#Be careful as the Type above may no match the device type. Check with the Inventory to make sure Some are Switch-Router or Router
#You dont need the log_message all the time. This is just useful for debugging.
# Create an instance of NetMRI_Easy
use strict;
use warnings;
use NetMRI_Easy;
use Data:Smiley Very Happyumper;
use DateTime;
#
require "TAE_Util.pm";

my $easy = new NetMRI_Easy;
 my ($site_id, $domain, $hostname, $ip_address, $sysdescr, $IOSversion, $deviceModel, $CabNo, $device_id, $gatewayIP);

openfile();

 # Get the NetMRI Device object
 my $device = $easy->device;

#Get the DeviceID - May require this to get other data through a script.
my $devID = $easy->device_id;
log_message("DeviceID:" . $devID . "\n");


#Get the IP address of the device
 $ip_address = $device->DeviceIPDotted;
 #my $mac_address = $device->DeviceMac;#Doesn't appear to be supported in the Perl Module
#Get the hostname of the device
 $hostname = $device->DeviceName;

log_message("IPAddress:" . $ip_address . "\n");
log_message("Hostname:" .  $hostname . "\n");

my $command_text1 = $easy->send_command("clear counter");

my $command_text1 = $easy->send_command("\r\r");



##########################################################
sub log_message{
#This subroutine prints the output into the status.log
    print("$_[0]\n");
}


##########################################################
sub squirt{

    # Blank the output holder variable (null doesnt work here)
    my $outputHolder;
    
    my $command  = $_[0];
    log_message('sending command: ' . $command);
    $outputHolder = $easy->send_command($command);
#    sleep(1);
    return $outputHolder;
}
##########################################################

Re: NetMRI, Perl and Clear Counters on Cisco devices

Adviser
Posts: 406
4380     0

Change these

my $command_text1 = $easy->send_command("clear counter");

my $command_text1 = $easy->send_command("\r\r");

to

my $command_text1 = $easy->send_command("clear counter\r\r");

 

Smiley Happy

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: NetMRI, Perl and Clear Counters on Cisco devices

Authority
Posts: 42
4380     0

Hi Sif,

Thanks for the reply.

I cant believe it.

I did that earlier in my testing but it flagged up an error.

 

But now looking back at the historical jobs, I see why. I put an extra r on the word. Argh.

my $command_text1 = $easy->send_command("clear counterr\r\r");

I should have spotted it.

Thanks for the help and sorry for wasting your time. :-(

 

 

Rgds

Russ

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You