Extracting Hardware Inventory Information
Problem
You need an up-to-date list of the hardware configurations and IOS levels of all of your routers.
Solution
The Bourne Shell script in Example 1-3 uses SNMP to extract useful version information from a list of routers. By default, the script will store this data in CSV format so you can easily import it into a spreadsheet for analysis. No arguments are required or expected.
Example 1-3. inventory.sh
#!/bin/sh |
Discussion
The inventory.sh script extracts hardware and IOS version information directly from the routers using SNMP. This ensures that the data is up to date. You can even automate this script so it runs periodically to make sure that your inventory information is always accurate. In a large network, this is much easier than keeping track of this information manually.
By default, the script captures the device name, router type, IOS version, and IOS feature set from each router. It stores this information gathered in a CSV format file called RESULT.csv.
This script requires NET-SNMP to gather the information via SNMP. You could use a different SNMP package if you prefer, but then you will need to modify the syntax appropriately. The script expects to find the executable snmpget in the directory / usr/local/bin. Again, if you keep this file in a different location, you will need to define the correct location in the variable snmp. For more information on NET-SNMP, see Chapter 17 or Appendix A.
Before running this script in your network, you will need to modify two variables. The first is the variable called public. This value must contain your read-only SNMP community string. The script assumes that you have the same community string on all of the routers in the list. The second variable that you will need to set is workingdir, which must contain the name of the directory that you wish to run the script from.
Finally, you will need to build a file called RTR_LIST that contains the names of all of your routers, with one name on each line. The script expects to find this file in the working directory.
The output of the script is a CSV file, which you can import into a spreadsheet to analyze and sort the results as required. Table 1-4 shows an example of the script's output as it might look in a spreadsheet.
Router | Router name | Type | IOS version | IOS feature set |
---|---|---|---|---|
Toronto | toronto | C2500 | 12.2(1d) | ENTERPRISE|FIREWALL PLUS IPSEC 56 |
Boston | boston | C2600 | 12.4(10) | IP|VOICE |
Newyork | newyork | C2600 | 12.2(31) | ENTERPRISE PLUS |
Tampa | tampa | C2600 | 12.4(10) | IP|VOICE |
Sanfran | sanfran | C2500 | 12.3(16) | IP PLUS |