| 1 | package Cisco::SNMP::System; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ################################################## | ||||||||||||||||||||||||||||
| 4 | # AUTHOR = Michael Vincent | ||||||||||||||||||||||||||||
| 5 | # www.VinsWorld.com | ||||||||||||||||||||||||||||
| 6 | ################################################## | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Net::SNMP qw(:asn1); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Cisco::SNMP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = $Cisco::SNMP::VERSION; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | our @ISA = qw(Cisco::SNMP); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ################################################## | ||||||||||||||||||||||||||||
| 19 | # Start Public Module | ||||||||||||||||||||||||||||
| 20 | ################################################## | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub _sysOID { | ||||||||||||||||||||||||||
|
Subroutine
_sysOID: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 0 | return '1.3.6.1.2.1.1'; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | sub sysOIDs { | ||||||||||||||||||||||||||
|
Subroutine
sysOIDs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 3 | return qw(Descr ObjectID UpTime Contact Name Location Services | |||||||||||||||||||||||||||
| 28 | ORLastChange); | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub system_info { | ||||||||||||||||||||||||||
|
Subroutine
system_info: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $session = $self->{_SESSION_}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $response = Cisco::SNMP::_snmpwalk( $session, _sysOID() ); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( defined $response ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $sysinfo; | |||||||||||||||||||||||||||
| 41 | 0 | my @SYSKEYS = sysOIDs(); | |||||||||||||||||||||||||||
| 42 | 0 | for ( 0 .. $#SYSKEYS ) { | |||||||||||||||||||||||||||
| 43 | 0 | $sysinfo->{$SYSKEYS[$_]} = $response->[$_]; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | return bless $sysinfo, $class; | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 0 | $Cisco::SNMP::LASTERROR = "Cannot read system MIB"; | |||||||||||||||||||||||||||
| 48 | 0 | return undef; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub sysDescr { | ||||||||||||||||||||||||||
|
Subroutine
sysDescr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 0 | return $self->{Descr}; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub sysObjectID { | ||||||||||||||||||||||||||
|
Subroutine
sysObjectID: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | 0 | return $self->{ObjectID}; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub sysUpTime { | ||||||||||||||||||||||||||
|
Subroutine
sysUpTime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 0 | return $self->{UpTime}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub sysContact { | ||||||||||||||||||||||||||
|
Subroutine
sysContact: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 0 | return $self->{Contact}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub sysName { | ||||||||||||||||||||||||||
|
Subroutine
sysName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 0 | return $self->{Name}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub sysLocation { | ||||||||||||||||||||||||||
|
Subroutine
sysLocation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 0 | return $self->{Location}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub sysORLastChange { | ||||||||||||||||||||||||||
|
Subroutine
sysORLastChange: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 0 | return $self->{ORLastChange}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub sysServices { | ||||||||||||||||||||||||||
|
Subroutine
sysServices: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( defined($arg) && ( $arg >= 1 ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $arg and $arg >= 1
MC/DC0%0/2
defined $arg and $arg >= 1
defined $arg
$arg >= 1
Truth table0%0/3
A and B
A= defined $argB= $arg >= 1
| |||||||||||||||||||||||||||||
| 91 | 0 | return $self->{Services}; | |||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||
| 93 | 0 | my %Services = ( | |||||||||||||||||||||||||||
| 94 | 1 => 'Physical', | ||||||||||||||||||||||||||||
| 95 | 2 => 'Datalink', | ||||||||||||||||||||||||||||
| 96 | 4 => 'Network', | ||||||||||||||||||||||||||||
| 97 | 8 => 'Transport', | ||||||||||||||||||||||||||||
| 98 | 16 => 'Session', | ||||||||||||||||||||||||||||
| 99 | 32 => 'Presentation', | ||||||||||||||||||||||||||||
| 100 | 64 => 'Application' | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | 0 | my @Svcs; | |||||||||||||||||||||||||||
| 103 | 0 | for ( sort { $b <=> $a } ( keys(%Services) ) ) { | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | push @Svcs, $Services{$_} if ( $self->{Services} & int($_) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 0 | return \@Svcs; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub sysOSVersion { | ||||||||||||||||||||||||||
|
Subroutine
sysOSVersion: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( $self->{Descr} =~ /Version ([^ ,\n\r]+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | return $1; | |||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | 0 | return "Cannot determine OS Version"; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # get_ direct | ||||||||||||||||||||||||||||
| 123 | 3 | my @OIDS = sysOIDs(); | |||||||||||||||||||||||||||
| 124 | 3 | for my $o ( 0 .. $#OIDS ) { | |||||||||||||||||||||||||||
| 125 | 24 | ▶ | *{"get_sys" . $OIDS[$o]} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $s = $self->session; | |||||||||||||||||||||||||||
| 129 | 0 | my $r = $s->get_request( | |||||||||||||||||||||||||||
| 130 | varbindlist => [_sysOID() . '.' . ( $o + 1 ) . '.0'] ); | ||||||||||||||||||||||||||||
| 131 | 0 | return $r->{_sysOID() . '.' . ( $o + 1 ) . '.0'}; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 24 | } | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # set_ direct | ||||||||||||||||||||||||||||
| 136 | 3 | for my $o ( 3 .. 5 ) { | |||||||||||||||||||||||||||
| 137 | 9 | ▶ | *{"set_sys" . $OIDS[$o]} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=23.3
| |||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 0 | my ($val) = @_; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( not defined $val ) { $val = '' } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | my $s = $self->session; | |||||||||||||||||||||||||||
| 143 | 0 | my $r = $s->set_request( _sysOID() . '.' . ( $o + 1 ) . '.0', | |||||||||||||||||||||||||||
| 144 | OCTET_STRING, $val ); | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ( not defined $r ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | $Cisco::SNMP::LASTERROR = $s->error; | |||||||||||||||||||||||||||
| 147 | 0 | return; | |||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||
| 149 | 0 | return $r->{_sysOID() . '.' . ( $o + 1 ) . '.0'}; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 9 | } | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | ################################################## | ||||||||||||||||||||||||||||
| 155 | # End Public Module | ||||||||||||||||||||||||||||
| 156 | ################################################## | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 3 | 1; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | __END__ | ||||||||||||||||||||||||||||