Here’s an interesting NetMRI script that shows how to use the API to pull some data so it can be used to look for other data in another application. In this case, we’re grabbing some info out of the Grid View.
This code snippet also shows the very useful technique of using Data Dumper as a way to see what is really being returned in the data call. For many “one off” programs where you are more interested in the data than in how it’s formatted, you can use Data Dumper to display it and grab the pieces you need, saving you the time of trying to write output routines you’re not going to use again… Try the NetMRI Evaluation Here!
use strict; use warnings; use NetMRI::API; use Data::Dumper; $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; # Connet to the NetMRI. my $client = new NetMRI::API({ api_version => '2.8', }); # Grab the entire SPM EndHost Grid my @broker = $client->broker->spm_end_hosts_default_grid->index; #Print the Header print "Device Name\tNeighborMAC\tInterface\tAdmin Status\tOper Status\n"; #Included Dumper to see the output of the Array, thanks John #print Dumper(@broker),"\n"; foreach my $endhost (@broker) { print $endhost->{DeviceName},"\t", $endhost->{NeighborMAC},"\t",$endhost->{ifAlias},"\t", $endhost->{ifAdminStatus},"\t", $endhost->{ifOperStatus},"\n"; }; ####Data Dumper OUTPUT#### # $VAR2 = { # 'device_custom_memory' => undef, # 'InterfaceID' => 74580, # 'NeighborIPNumeric' => undef, # 'device_custom_vendor_support_contact' => 'Robert Davis', # 'device_custom_person_responsible' => undef, # 'VlanIndex' => 900, # 'NeighborName' => undef, # 'VTPDomain' => undef, # 'Packets' => 80255, # 'Network' => 'demo.infoblox.com', # 'InterfaceSort' => 'Ethernet00004/00033', # 'NeighborDeviceID' => undef, # 'DeviceName' => 'dev7k', # 'device_custom_data_center' => undef, # 'ifAlias' => '', # 'interface_custom_room' => undef, # 'OrgUniqueId' => 'Cisco', # 'device_custom_vtpdomain' => undef, # 'interface_custom_reserved' => undef, # 'interface_custom_building' => undef, # 'interface_custom_change_order_number' => undef, # 'device_custom_vtp_pass' => undef, # 'device_custom_vtp_password' => undef, # 'device_custom_rack_number' => undef, # 'VlanName' => 'VLAN0900', # 'interface_custom_application' => undef, # 'Errors' => 0, # 'NeighborType' => undef, # 'Interface' => 'Ethernet4/33 - Ethernet4/33', # 'DeviceID' => 644, # 'ifOperStatus' => 'up', # 'ifAdminStatus' => 'up', # 'device_custom_fastweb_variable' => undef, # 'ifIndex' => 437911552, # 'device_custom_rob' => undef, # 'DeviceType' => 'Switch-Router', # 'id' => 563257, # 'interface_custom_customer' => undef, # 'FirstSeen' => '2013-01-25 17:24:07', # 'NeighborIfIndex' => undef, # 'device_custom_location' => undef, # 'NeighborID' => 401408, # 'interface_custom_jack_name' => undef, # 'ifAdminDuplex' => 'Unsupported', # 'device_custom_deviceserialnum' => undef, # 'device_custom_device_inventory_id' => undef, # 'device_custom_reserved' => undef, # 'ErrorPercentage' => 0, # 'VlanID' => 3282, # 'NeighborIPDotted' => undef, # 'device_custom_sif_memory2' => '2', # 'device_custom_vtp_op_mode' => undef, # 'device_custom_vtp_domain_name' => undef, # 'ifDescr' => 'Ethernet4/33', # 'NeighborMAC' => '00:07:7D:12:65:61', # 'DeviceIPDotted' => '10.120.25.141', # 'interface_custom_name_test' => undef, # 'device_custom_asset_tag_number' => 'ABC123', # 'NetBIOSName' => undef, # 'ifSpeed' => 1000000000, # 'device_custom_vtpmode' => undef, # 'device_custom_gateway' => undef, # 'ifMAC' => 'AC:8A:DB:B6:00:00', # 'LastSeen' => '2013-08-14 11:29:36', # 'interface_custom_riser' => undef, # 'ifDuplex' => 'fullDuplex', # 'DeviceIPNumeric' => 175643021 # };
A sample of the output would look like this:
Output: Device Name NeighborMAC Interface Admin Status Oper Status dev7k 22:22:22:22:22:22 Ethernet4/2_QA1 up down dev7k 00:07:7D:12:65:61 up up