lib/Cisco/SNMP/Entity.pm

filter: Statementstmt 49.0% 25 / 51 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 46.4% 33 / 71 CC 7 SCAR 28.9
CC
7
Cov
43%
entity_info
42.0
__ANON__
4.9
_entityOID
2.0
CRAP 18.0
« lib/Cisco/SNMP/Memory.pm ↑ Summary lib/Cisco/SNMP/System.pm »
1 package Cisco::SNMP::Entity;
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 _entityOID {
Subroutine _entityOID: not called CC=1 SCAR=6.9
23 0 return '1.3.6.1.2.1.47.1.1.1.1';
24 }
25  
26 6 ▶sub entityOIDs {
Subroutine entityOIDs: called CC=1 SCAR=0.0
Pod documented
27 6 return qw(Descr VendorType ContainedIn Class ParentRelPos Name
28 HardwareRev FirmwareRev SoftwareRev SerialNum MfgName ModelName
29 Alias AssetID IsFRU);
30 }
31  
32 0 ▶sub entity_info {
Subroutine entity_info: not called CC=6 SCAR=37.4
Pod documented
33 0 my $self = shift;
34 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
35  
36 0 my $session = $self->{_SESSION_};
37  
38 0 my @ENTITYKEYS = entityOIDs();
39 0 my %ret;
40 0 for my $oid ( 0 .. $#ENTITYKEYS ) {
41 0 $ret{$ENTITYKEYS[$oid]} = Cisco::SNMP::_snmpwalk( $session,
42 _entityOID() . '.' . ( $oid + 2 ) );
43 0 ▶ if ( not defined $ret{$ENTITYKEYS[$oid]} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ret{$ENTITYKEYS[$oid]}) 0 0 0
44 0 $Cisco::SNMP::LASTERROR
45 = "Cannot get entity `$ENTITYKEYS[$oid]' info";
46 0 return undef;
47 }
48 }
49  
50 0 my @Entity;
51 0 for my $unit ( 0 .. $#{$ret{$ENTITYKEYS[5]}} ) {
52 0 my %EntityHash;
53 0 for ( 0 .. $#ENTITYKEYS ) {
54 0 $EntityHash{$ENTITYKEYS[$_]} = $ret{$ENTITYKEYS[$_]}->[$unit];
55 }
56 0 push @Entity, \%EntityHash;
57 }
58 0 return bless \@Entity, $class;
59 }
60  
61 3 for ( entityOIDs() ) {
62 45 Cisco::SNMP::_mk_accessors_array_1( 'entity', $_ );
63 }
64  
65 3 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 # get_ direct
68 3 my @OIDS = entityOIDs();
69 3 for my $o ( 0 .. $#OIDS ) {
70 45 ▶ *{"get_entity" . $OIDS[$o]} = sub {
Subroutine __ANON__: not called CC=2 SCAR=15.9
71 0 my $self = shift;
72 0 my ($val) = @_;
73  
74 0 ▶ if ( not defined $val ) { $val = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
75 0 my $s = $self->session;
76 0 my $r = $s->get_request(
77 varbindlist => [_entityOID() . '.' . ( $o + 2 ) . '.' . $val] );
78 0 return $r->{_entityOID() . '.' . ( $o + 2 ) . '.' . $val};
79 }
80 45 }
81  
82 ##################################################
83 # End Public Module
84 ##################################################
85  
86 3 1;
87  
88 __END__
« lib/Cisco/SNMP/Memory.pm ↑ Summary lib/Cisco/SNMP/System.pm »