Network Change & Configuration Management

Reply
Highlighted

NETMRI gather show version information and export to a file

Posts: 80
7403     0

Hi All,

Our team is very comfortable creating and running scripts within NetMRI.  Here is where we are stuck.  We need the sh ver | inc flash command from all our Cisco devices.

Since the information isn't normally stored in NetMRI because it is not a part of sh run or SNMP information, I need to run a script to get the data.

Once I get the results, how would I approach exporting it to some sort of file.  With thousands of devices I was hopefully for a way to get this information easily and quickly.

Any advice on an approach would be appreciated.

Susan

 

 

You can have a script fire a custom issue

Expert
Posts: 228
7404     0

I'm unclear what you're actually attempting to gather out of "show ver | i flash".  That exact result will vary from nothing, to the boot image filename, depending on the device you choose and what types of memory it has.  Are you trying to get the capacity of flash RAM (" xxxxxK bytes of Flash")?  Note upper case.

Some years ago I needed to get the capacity of both DRAM and flash RAM, and while I was at it, grabbed the IOS version and actual image filename.  The script just shoved those into the arg list for a custom issue.  After the batch completed, the issue details could be sorted in place or exported as a CSV and imported into a spreadsheet.

Does that help?

You could also store it in a

Adviser
Posts: 357
7404     0

You could also store it in a custom field for the device, then you can pull out the list of devices from the UI via a CSV export.

John,

Posts: 80
7404     0

John,

I like the custom field idea, but I am unsure how to take the script results and push those into a custom field.

Marty,

Unlike the OS version, the actual flash filename provides more details about the code and what it supports.

Susan

Susan,

Adviser
Posts: 357
7404     0

Susan,

You'll need to use a Perl script to set custom fields in a script, you can't do it in CCS. There is an example in the API docs in the tutorial section. See the Tools > Network > API Documentation screen.

John

Some time next week I will

Adviser
Posts: 373
7404     0

Some time next week I will post a PERL Script that will accomplish this for you.

I need to clean it up and add some comments to it.

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

I am also interested in this script

GMatos
Techie
Posts: 1
7404     0
We are trying to gather IOS information for all our infrastructure, and so far I have not found an easy way to make that report.

Susan, sorry it took so long

Adviser
Posts: 373
7404     0

Susan, sorry it took so long ot post this but like John stated it's in our API documentation:

 

Updating Custom Fields

 

To demonstrate how to set and update custom fields, we will write a Network Automation script which finds the serial number for a Cisco device and writes that value into a custom field "chasis_serial_number". This script starts with the usual declarations needed by the Perl compiler and the Network Automation Job engine, and opening a connection to the Network Automation by creating an instance of NetMRI_Easy.

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
#     $Vendor eq "Cisco"
#
# END-SCRIPT-BLOCK

use strict;
use warnings;
use NetMRI_Easy;

# Connect to the Network Automation
my $easy = new NetMRI_Easy;

We create the custom field in case it does not already exist using the create_field method on the CustomFields broker.

$easy->broker->custom_fields->create_field({
  model => 'Device',
  name  => 'chasis_serial_number',
  type  => 'string',
});

Determine the serial number for the device. This method may not work on all Cisco devices and there are some caveats, but it should be sufficient as an example.

my $serial_number;

# The method for retrieving the serial number via the
# CLI depends on the type of device.
if($easy->device->DeviceType eq 'Router')
{
  my @inventory = split /\r?\n/, $easy->send_command('show inventory');

  while(my $line = shift @inventory)
  {
    if($line =~ /^NAME: \\?"\d+ chassis\\?"/
    && $inventory[0] =~ /SN:\s*(\S+)\s*$/)
    {
      $serial_number = $1;
      last;
    }
  }
}
else
{
  foreach my $line (split /\r?\n/, $easy->send_command('show version'))
  {
    if($line =~ /^System serial number\s*:\s*(.*)\s*$/)
    {
      $serial_number = $1;
    }
  }
}

Finally, if the serial number was discovered in the execution of this script we use the set_custom_field method on the NetMRI::API::Remote:Smiley Very Happyevice object for the target device. You can also use get_custom_field to retrieve the custom field at a later time.

if(defined $serial_number)
{
  # Note the serial number in the log and update the field
  $easy->log_message('info', "updated chasis serial number $serial_number");
  $easy->device->set_custom_field(chasis_serial_number => $serial_number);
}
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

TFTP Copy to a switch or Router via NetMri using line by line

OBrown
Techie
Posts: 2
7404     0
I would like to simply TFTP and OS upgrade to a router or switch using the following commands copy tftp://10.96.0.140/c2900-universalk9-mz.SPA.153-3.M4.bin flash:c2900-universalk9-mz.SPA.153-3.M4.bin The command runs fine but when the router is waiting for you to enter to accept the name of the file the scirpt/execution fails because it is waiting on a response. How do I get the "enter" response to be a part of the script. I am not a perl expert and I am trying not to use perl, I just don't have the time to learn perl.

ONeil,

Adviser
Posts: 373
7404     0

ONeil, 

Should have started a new post Smiley Happy

This is all you need 

copy tftp://10.96.0.140/c2900-universalk9-mz.SPA.153-3.M4.bin flash:c2900-universalk9-mz.SPA.153-3.M4.bin \r

Reason for that is that NEtMRI does to look that the prompt as a vlaid prompt.

 

Sif

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

Sif Baksh

OBrown
Techie
Posts: 2
7404     0
My apologies I thought i did start a new post. I tried the \r but it did not work. Thanks

Can you post the script or

Adviser
Posts: 373
7404     0

Can you post the script or the error you are seeing?

 

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

Two \r are needed

Expert
Posts: 228
7404     0

Actually two \r are needed -- one for the confirmation of the source and one more for the confirmation of the destination:

copy tftp://10.96.0.140/c2900-universalk9-mz.SPA.153-3.M4.bin flash:c2900-universalk9-mz.SPA.153-3.M4.bin\r\r

But I'm pretty sure that's also going to fail because the file size is much larger than 32MB and that's the limit for TFTP.  You'll need to use FTP or HTTP or HTTPS.

NETMRI gather show version information and export to a file

Authority
Posts: 40
7404     0
Hi John and Sif, I am new to netmri as well and trying to accomplish a similar task. Run script, check for fields etc.. and create a report that you can download as excel. Is there an alternative approach? Setting a device specific custom field and running a report rather seems to be a workaround. And then someone should take care these variables are cleared later. If I can just create a text file per JOB and not just per device, It would work for me. The Archive keyword only retains the values of the last device. The alternative, using dynamic names results in hundreds of files. This is a very simple objective and I believe there is a way. I am unable to find out through documentation. Greatly appreciate it, if you can help. P.S My company policies do not allow me to run an external netMRI script. Thanks, Rahul Shenoy

Rahul,

Adviser
Posts: 373
7404     0

Rahul,

If you use Archive this way:

ARCHIVE ($ipaddress): show version

Run it on 50 devices you will see a ZIP file appear under Job Viewer files Smiley Happy

It will contain 50 files of the "show version" for each device.  You can use any "Well Known" variables($name,$sysname..etc)

You can also take your show command and add them to a List in NetMRI Smiley Happy

So capture the DeviceName or DeviceDottedIPAddress and update a list with that information

Look at the PERL API Guide for List or search getListValue()

 

I hope this helps,

Sif

 

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

Hi Sif,

Authority
Posts: 40
7404     0
Hi Sif, Thanks for your quick reply. Isn't PERL API guide for running external perl scripts? I am writing internal perl scripts. Is there a way to do it? And it appears that the ARCHIVE keyword is applicable only to CCS scripts. Thanks, Rahul Shenoy

I believe you should be able

Adviser
Posts: 357
7404     0

I believe you should be able to just open a file in append mode in Perl and print to that. However, I don't think it would be available for download in the UI, only in the admin shell. Also, if you are in a distributed environment, there will be one per collector.

You could copy it off the sandbox to some location at the end of the script, but this runs into needing to know which device is "last" - you should be able to determine this by looking at the job details status via the API, but it's a little difficult.

 

Hi John,

Authority
Posts: 40
7404     0
Hi John, Thanks for replying. Yes you are right. Although the script doesn't give out any errors, I don't see files. I shall check with the admin. I got custom issue to work for me in perl. I know it works in CCS. I spent the whole day today to get it work. Smiley Happy Thanks, Rahul Shenoy
Showing results for 
Search instead for 
Do you mean 

Recommended for You