lib/Power/Outlet/Common/IP/SNMP.pm

filter: Statementstmt 35.8% 19 / 53 Branchbran 11.5% 3 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 6 / 14 Podpod 100% 7 / 7 totaltotal 35.0% 35 / 100 CC 14 SCAR 25.4
CC
14
Cov
28%
snmp_multiset
30.0
snmp_session
20.0
snmp_multiget
20.0
CRAP 12.7
« lib/Power/Outlet/iBootBarGroup.pm ↑ Summary lib/Power/Outlet/Kauf.pm »
1 package Power::Outlet::Common::IP::SNMP;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base qw{Power::Outlet::Common::IP};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Net::SNMP qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.54';
8  
9 =head1 NAME
10  
11 Power::Outlet::Common::IP::SNMP - Power::Outlet base class for SNMP power outlet
12  
13 =head1 SYNOPSIS
14  
15 use base qw{Power::Outlet::Common::IP::SNMP};
16  
17 =head1 DESCRIPTION
18
19 Power::Outlet::Common::IP::SNMP is a package for controlling and querying an SNMP-based network attached power outlet.
20  
21 =head1 USAGE
22  
23 use base qw{Power::Outlet::Common::IP::SNMP};
24  
25 =head1 PROPERTIES
26  
27 =head2 community
28  
29 Sets and returns the SNMP community.
30  
31 my $community=$outlet->community("private"); #read/write
32 my $community=$outlet->community("public"); #read only features
33  
34 =cut
35  
36 4 ▶sub community {
Subroutine community: called CC=3 SCAR=11.0
Pod documented
37 4 my $self=shift;
38 4 ▶ $self->{"community"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
39 4 ▶ $self->{"community"}=$self->_community_default unless defined $self->{"community"}; #MFG Default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"community"} 2 2 4
40 4 return $self->{"community"};
41 }
42  
43 =head2 snmp_version
44  
45 Returns 1
46  
47 =cut
48  
49 0 ▶sub snmp_version {1}; #iBootBar
Subroutine snmp_version: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub _host_default {"192.168.0.254"}; #iBootBar
Subroutine _host_default: not called CC=1 SCAR=6.9
51 2 ▶sub _port_default {"161"}; #SNMP
Subroutine _port_default: called CC=1 SCAR=0.0
52 0 ▶sub _community_default {"private"}; #iBootBar
Subroutine _community_default: not called CC=1 SCAR=6.9
53  
54 =head1 METHODS
55  
56 =head2 snmp_session
57  
58 Returns a cached L<Net::SNMP> session object
59  
60 =cut
61  
62 0 ▶sub snmp_session {
Subroutine snmp_session: not called CC=4 SCAR=30.0
Pod documented
63 0 my $self=shift;
64 0 ▶ $self->{"snmp_session"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
65 0 ▶ unless (defined $self->{"snmp_session"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"snmp_session"}) 0 0 0
66 0 my ($session, $error) = Net::SNMP->session(
67 -version => $self->snmp_version,
68 -hostname => $self->host,
69 -port => $self->port,
70 -community => $self->community,
71 );
72 0 ▶ die("Error $error") if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
73 0 $self->{"snmp_session"}=$session;
74 }
75 0 return $self->{"snmp_session"};
76 }
77  
78 =head2 snmp_get
79  
80 my $value = $self->snmp_get($oid);
81  
82 =cut
83  
84 0 ▶sub snmp_get {
Subroutine snmp_get: not called CC=1 SCAR=6.9
Pod documented
85 0 my $self = shift;
86 0 my $oid = shift;
87 0 return $self->snmp_multiget([$oid])->{$oid};
88 }
89  
90 =head2 snmp_multiget
91  
92 my $oid_values = $self->snmp_multiget(\@oids); #isa HASH
93 my %oid_values = $self->snmp_multiget(\@oids); #isa ()
94  
95 =cut
96  
97 0 ▶sub snmp_multiget {
Subroutine snmp_multiget: not called CC=4 SCAR=30.0
Pod documented
98 0 my $self = shift;
99 0 my $oids = shift; #isa ARRAY
100 0 ▶ die("Error: parameter must be array reference") unless ref($oids) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oids eq "ARRAY" 0 0 0
101 0 my $session = $self->snmp_session;
102 0 ▶ my $result = $session->get_request(-varbindlist=>$oids) or die(sprintf("Error: %s", $session->error)); #isa HASH
Branch: 1 branch
BranchTrueFalseTotal
my $result = $session->get_request("-varbindlist", $oids) or die sprintf("Error: %s", $session->error) 0 0 0
103 0 ▶ return wantarray ? %$result : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
104 }
105  
106 =head2 snmp_set
107  
108 $self->snmp_set($oid, $value); #type INTEGER
109 $self->snmp_set($oid, $value, $type); #type from Net::SNMP types
110  
111 =cut
112  
113 0 ▶sub snmp_set {
Subroutine snmp_set: not called CC=2 SCAR=17.9
Pod documented
114 0 my $self = shift;
115 0 my $oid = shift;
116 0 ▶ die("Error: parameter oid required") unless defined $oid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $oid 0 0 0
117 0 return $self->snmp_multiset([$oid], @_);
118 }
119  
120 =head2 snmp_multiset
121  
122 $self->snmp_multiset(\@oids, $value); #type INTEGER
123 $self->snmp_multiset(\@oids, $value, $type); #type from Net::SNMP types
124  
125 =cut
126  
127 0 ▶sub snmp_multiset {
Subroutine snmp_multiset: not called CC=5 SCAR=34.0
Pod documented
128 0 my $self = shift;
129 0 my $oids = shift;
130 0 ▶ die("Error: parameter oids must be an array reference") unless ref($oids) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oids eq "ARRAY" 0 0 0
131 0 my $value = shift;
132 0 ▶ die("Error: parameter values required") unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
133 0 my $type = shift;
134 0 ▶ $type = Net::SNMP::INTEGER unless defined($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
135 0 my $session = $self->snmp_session;
136 0 ▶ $session->set_request(-varbindlist=>[map {$_, $type, $value} @$oids]) or die(sprintf("Error: %s", $session->error));
Branch: 1 branch
BranchTrueFalseTotal
$session->set_request("-varbindlist", [map({$_, $type, $value;} @$oids)]) or die sprintf("Error: %s", $session->error) 0 0 0
137 0 return "SUCCESS";
138 }
139  
140 =head1 BUGS
141  
142 Please log on RT and send an email to the author.
143  
144 =head1 SUPPORT
145  
146 DavisNetworks.com supports all Perl applications including this package.
147  
148 =head1 AUTHOR
149  
150 Michael R. Davis
151 CPAN ID: MRDVT
152 DavisNetworks.com
153  
154 =head1 COPYRIGHT
155  
156 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
157  
158 The full text of the license can be found in the LICENSE file included with this module.
159  
160 =head1 SEE ALSO
161  
162 =cut
163  
164 3 1;
« lib/Power/Outlet/iBootBarGroup.pm ↑ Summary lib/Power/Outlet/Kauf.pm »