line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Power::Outlet::Common::IP::SNMP; |
2
|
3
|
|
|
3
|
|
989
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
84
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
83
|
|
4
|
3
|
|
|
3
|
|
24
|
use base qw{Power::Outlet::Common::IP}; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
1055
|
|
5
|
3
|
|
|
3
|
|
2684
|
use Net::SNMP qw{}; |
|
3
|
|
|
|
|
238570
|
|
|
3
|
|
|
|
|
1705
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
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
|
|
|
|
|
|
|
sub community { |
37
|
4
|
|
|
4
|
1
|
11
|
my $self=shift; |
38
|
4
|
50
|
|
|
|
13
|
$self->{"community"}=shift if @_; |
39
|
4
|
100
|
|
|
|
16
|
$self->{"community"}=$self->_community_default unless defined $self->{"community"}; #MFG Default |
40
|
4
|
|
|
|
|
19
|
return $self->{"community"}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 snmp_version |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Returns 1 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
sub snmp_version {1}; #iBootBar |
50
|
0
|
|
|
0
|
|
0
|
sub _host_default {"192.168.0.254"}; #iBootBar |
51
|
2
|
|
|
2
|
|
6
|
sub _port_default {"161"}; #SNMP |
52
|
0
|
|
|
0
|
|
|
sub _community_default {"private"}; #iBootBar |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 snmp_session |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a cached L session object |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub snmp_session { |
63
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
64
|
0
|
0
|
|
|
|
|
$self->{"snmp_session"}=shift if @_; |
65
|
0
|
0
|
|
|
|
|
unless (defined $self->{"snmp_session"}) { |
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
|
0
|
|
|
|
|
die("Error $error") if $error; |
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
|
|
|
|
|
|
|
sub snmp_get { |
85
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub snmp_multiget { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $oids = shift; #isa ARRAY |
100
|
0
|
0
|
|
|
|
|
die("Error: parameter must be array reference") unless ref($oids) eq "ARRAY"; |
101
|
0
|
|
|
|
|
|
my $session = $self->snmp_session; |
102
|
0
|
0
|
|
|
|
|
my $result = $session->get_request(-varbindlist=>$oids) or die(sprintf("Error: %s", $session->error)); #isa HASH |
103
|
0
|
0
|
|
|
|
|
return wantarray ? %$result : $result; |
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
|
|
|
|
|
|
|
sub snmp_set { |
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my $oid = shift; |
116
|
0
|
0
|
|
|
|
|
die("Error: parameter oid required") unless defined $oid; |
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
|
|
|
|
|
|
|
sub snmp_multiset { |
128
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
129
|
0
|
|
|
|
|
|
my $oids = shift; |
130
|
0
|
0
|
|
|
|
|
die("Error: parameter oids must be an array reference") unless ref($oids) eq "ARRAY"; |
131
|
0
|
|
|
|
|
|
my $value = shift; |
132
|
0
|
0
|
|
|
|
|
die("Error: parameter values required") unless defined($value); |
133
|
0
|
|
|
|
|
|
my $type = shift; |
134
|
0
|
0
|
|
|
|
|
$type = Net::SNMP::INTEGER unless defined($type); |
135
|
0
|
|
|
|
|
|
my $session = $self->snmp_session; |
136
|
0
|
0
|
|
|
|
|
$session->set_request(-varbindlist=>[map {$_, $type, $value} @$oids]) or die(sprintf("Error: %s", $session->error)); |
|
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
|
|
|
|
|
|
|
1; |