script/cisco-entity.pl untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 74 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5 use Getopt::Long qw(:config no_ignore_case); #bundling
6 use Pod::Usage;
7  
8 use Cisco::SNMP::Entity;
9  
10 my %opt;
11 my ($opt_help, $opt_man);
12  
13 GetOptions(
14 'all!' => \$opt{all},
15 'community=s' => \$opt{community},
16 'help!' => \$opt_help,
17 'man!' => \$opt_man
18 ) or pod2usage(-verbose => 0);
19  
20 pod2usage(-verbose => 1) if defined $opt_help;
21 pod2usage(-verbose => 2) if defined $opt_man;
22  
23 # Make sure at least one arg was provided
24 if (!@ARGV) {
25 pod2usage(-verbose => 0, -message => "$0: host required\n")
26 }
27  
28 $opt{community} = $opt{community} || 'private';
29 $opt{all} = $opt{all} || 0;
30  
31 for (@ARGV) {
32 print "\n-- $_ --\n";
33  
34 my $cm;
35 if (!defined($cm = Cisco::SNMP::Entity->new(
36 hostname => $_,
37 community => $opt{community}
38 ))) {
39 printf "Error: %s\n", Cisco::SNMP::Entity->error;
40 next
41 }
42  
43 if (defined(my $entity = $cm->entity_info())) {
44 printf "%-25s%-30s%-12s%-12s\n", "MODELNAME", "NAME", "SN", "SOFTREV";
45 print "-"x74 . "\n";
46 for (0..$#{$entity}) {
47 next if (($entity->entitySerialNum($_) eq '') && (!$opt{all}));
48 printf "%-25s%-30s%-12s%-12s\n",
49 $entity->entityModelName($_),
50 $entity->entityName($_),
51 $entity->entitySerialNum($_),
52 $entity->entitySoftwareRev($_)
53 }
54 } else {
55 printf "Error: %s\n", Cisco::SNMP::Entity->error
56 }
57  
58 $cm->close()
59 }
60  
61 __END__