script/cisco-system.pl untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 91 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::Image;
9 use Cisco::SNMP::System;
10  
11 my %opt;
12 my ($opt_help, $opt_man);
13  
14 GetOptions(
15 'community=s' => \$opt{community},
16 'image!' => \$opt{image},
17 'help!' => \$opt_help,
18 'man!' => \$opt_man
19 ) or pod2usage(-verbose => 0);
20  
21 pod2usage(-verbose => 1) if defined $opt_help;
22 pod2usage(-verbose => 2) if defined $opt_man;
23  
24 # Make sure at least one arg was provided
25 if (!@ARGV) {
26 pod2usage(-verbose => 0, -message => "$0: host required\n")
27 }
28  
29 $opt{community} = $opt{community} || 'private';
30  
31 for (@ARGV) {
32 print "\n-- $_ --\n";
33  
34 my $cm;
35 if (!defined($cm = Cisco::SNMP::System->new(
36 hostname => $_,
37 community => $opt{community}
38 ))) {
39 printf "Error: %s\n", Cisco::SNMP::System->error;
40 next
41 }
42  
43 if (defined(my $sysinfo = $cm->system_info())) {
44 printf "Description = %s\n", $sysinfo->sysDescr;
45 printf "ObjectID = %s\n", $sysinfo->sysObjectID;
46 printf "Uptime = %s\n", $sysinfo->sysUpTime;
47 printf "Conctact = %s\n", $sysinfo->sysContact;
48 printf "Name = %s\n", $sysinfo->sysName;
49 printf "Location = %s\n", $sysinfo->sysLocation;
50 printf "OrLastChange = %s\n", $sysinfo->sysORLastChange;
51 printf "OS Version = %s\n", $sysinfo->sysOSVersion;
52 print "Services = ";
53 print "$_ " for (@{$sysinfo->sysServices});
54 print "\n"
55 } else {
56 printf "Error: %s\n", Cisco::SNMP::System->error
57 }
58  
59 if (defined $opt{image}) {
60 my $cmi;
61 if (!defined($cmi = Cisco::SNMP::Image->new(
62 hostname => $_,
63 community => $opt{community}
64 ))) {
65 printf "Error: %s\n", Cisco::SNMP::Image->error;
66 next
67 }
68  
69 if (defined(my $image = $cmi->image_info())) {
70 for my $i (0..$#{$image}) {
71 printf "Image String $i = %s\n", $image->imageString($i)
72 }
73 } else {
74 printf "Error: %s\n", Cisco::SNMP::Image->error
75 }
76  
77 $cmi->close()
78 }
79  
80 $cm->close()
81 }
82  
83 __END__