Sunday, January 10, 2010

crinv (Create Inventory Report)

Some months ago i was searching for a simple inventory management tool, that could catalogue my company's devices, mainly for updating our support contracts.

I tried quite a few of free ones, some demos of commercial ones, but i didn't find what i was looking for. Most of them were bloated with features i didn't need and i had to dig very deeply in order to customize them. So i decided (once more) to write my own.

crinv (Create Inventory Report is the full name) is a very simple script written in perl, that produces a csv file containing the most basic attributes you would need from your inventory management tool. Then you can load the csv file in Excel and produce whatever reports you like.

crinv takes as an argument a text file where you have to put your devices, one per line.


# Format of devices' file
# -----------------------
# - The general format of each line is "device|community"
# - Only device is required, community is optional
# - All white spaces are removed before processing each line
# - Lines starting with # are comments and will be ignored
# - Lines starting with | are ignored
# - The | character must be used on each line for seperation between device and community
# - Devices without a community use the default/cli community
# - Lines without a | character are considered to be devices and use the default/cli community
#
# Output csv filename is created automatically after removing any extension from the
# devices input filename and adding .csv to it


There are quite a few of display filters into the script that you can change, to order to suit your needs. Feel free to experiment with them, although the default values should be fine for most of you. For the hierarchical output, check below:

# In order to make the output kind of hierarchical, you have to change the following two parameters:
#
# my $left_space = " "; # This can be any character(s) you want to use to produce the left indent effect
# # spaces are prefered since tab characters do not show up in Excel
# my $display_level = 1; # This must be 1 for hierarchical output

Usage is quite simple:


E:\perl>crinv.pl -d devices.txt

crinv (Create Inventory Report) v0.9 (10-Jan-2010)
(c) 2009-2010 Tassos (http://ccie-in-3-months.blogspot.com/)
---------------------------------------------------
Found 2 valid devices in 'devices.txt'...
------------------------------
Collecting snmp data...
Getting snmp data from 'router1'...
OK!
Getting snmp data from 'router2'...
OK!
Finished collecting snmp data!
------------------------------
Processing snmp data...
Finished processing snmp data!
------------------------------
Generating report...
Finished generating report 'devices.csv'...
------------------------------

This will process all devices from devices.txt and use the default community name for devices that don't have one. You can check the included readme.txt for more details.

Below you can see screenshots from some generated reports using different display filters (some parts have been intentionally hidden).

1) No hierarchical output


2) Hierarchical minimal output


3) Hierarchical output


In its simplest form, you just have to create a text file with all your devices (one per line) and then run crinv on it by supplying the snmp community as a parameter:


crinv -f devices.txt -c COMMUNITY


You can download crinv from here.

Notes:

1) I have only tested it on Cisco devices and on a limited range of them. If you find it not working on a relatively new Cisco device, please inform me and i'll try to have a look at it. I can't guarantee anything due to my shortage of free time.

From readme.txt:

# Please note that not all Cisco devices support the Entity MIB and those that support it, do not
# always display the correct information.
#
# The following modular devices have been tested (with latest IOS) and seem to return correct values:
# 6500, 7600, 10000, ASR1000, 12000.
#
# The following smaller devices have been tested (with latest IOS) and seem to return correct values:
# 2950, 2960, ME3400, 3750, 3845, 7200/G1, 7200/G2. 7200s may show a different S/N than the actual one.


2) I don't know if there is a limit on the number of devices that can be processed at once (probably it depends on the hardware perl is running on). On a modest SUN workstation, ~500 devices (~50 of them were modular) were processed without any problem in about 20 mins (snmp is taking the most time). Of course, you can always split your devices in smaller parts and process many different files in parallel.

3) Right now i'm not planning of making it a full-blown application. This was created for servicing my own needs mainly (as many other scripts in my job), but i thought others could benefit from it too.

15 comments:

  1. Thanks Tassos!
    I'm sure 'crinv' would come in handy. :-)

    ReplyDelete
  2. I would like to reprint this article in the CCIE Flyer. Please contact me via editor@ccieflyer.com.
    www.ccieflyer.com

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Tassos,
    Nice work, very helpful when updates of support contracts are needed.
    I tried it on Cisco MDS9509 and it worked too (it returns more informations than wanted but all serial numbers are presents.
    Thanks !

    ReplyDelete
  5. Great tool.

    Some of our older 2950 does not return ENVMON-MIB, besides this saved me for days of work.

    Made modification to script to create logfile (same as screen, but to additional file) Made debugging easier.

    ReplyDelete
  6. This tool is very good and helpfull! I have tried with 3550 and me3400, works just fine!
    Is there a way to insert a hostname coloumn next to device name?

    ReplyDelete
  7. Have an issue with 3750, not getting info for SFP inserted... Checked the script, seems ok, not blocking anything related to 3750. Any ideas?

    ReplyDelete
  8. As upmentioned, if PID field is empty in "show inv" for particular SFP, that info would not be in report. Tried with different IOS (newer), it came up with "unspecified" PID info, and then would appear in report. I could not find in script that is stated: if PID field is empty then do not process that data...

    ReplyDelete
  9. > Is there a way to insert a hostname coloumn next to device name?

    I guess you can run an extra snmpget to get the hostname and print that too.
    I'll try to upload a new version around November with some enhancements.

    ReplyDelete
  10. >As upmentioned, if PID field is empty in "show inv" for particular SFP, that info would not be in report. Tried with different IOS (newer), it came up with "unspecified" PID info, and then would appear in report. I could not find in script that is stated: if PID field is empty then do not process that data...

    The default output mode 1, which is to print anything that has a ModelName. Try changing that to 0 in order to print everything.

    ReplyDelete
  11. Excellent Script. Trying to make minor modification to add a SysLocation, once I figure it out it will do everything I need. Does complete network (nearly 500 devices) in less then 35 minutes. Thanks.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. It's simply superb .
    Looking for few more addition on this
    Especially Error reporting .
    If it can generate a reports telling how many devices has been responded properly and how many did not and segregation of both

    ReplyDelete
  14. I try with nexus 5020 but appear some error please suggest me.
    !
    ERROR: Failed to get entPhysicalTable from device '10.x.x.x': Message size exceeded buffer maxMsgSize.
    !

    ReplyDelete
  15. I will uncomment and change maxrepetitions from 10 to 20 it will work
    my $result = $session->get_table(
    -baseoid => $OID_entPhysicalTable,
    -maxrepetitions => 20, # v2c/v3

    but i have a second problem snmp for nexus cannot seen transceiver i cant see any transceiver same command show interface transceiver. please suggest me.

    ReplyDelete

 
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Greece License.