lib/Power/Outlet/iBootBar.pm

filter: Statementstmt 44.0% 22 / 50 Branchbran 50.0% 4 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 43.7% 7 / 16 Podpod 100% 5 / 5 totaltotal 46.3% 38 / 82 CC 6 SCAR 12.6
CC
6
Cov
43%
query
12.0
outlet
4.1
_outletIndex
2.0
CRAP 3.5
« lib/Power/Outlet/Common/IP/HTTP.pm ↑ Summary lib/Power/Outlet/Common.pm »
1 package Power::Outlet::iBootBar;
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::SNMP};
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Time::HiRes qw{sleep};
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.54';
8 3 our $_oid_outletEntry = '1.3.6.1.4.1.1418.4.3.1'; #enterprises.dataprobe.iBootBarAgent.outletTable.outletEntry
9  
10 =head1 NAME
11  
12 Power::Outlet::iBootBar - Control and query a Dataprobe iBootBar power outlet
13  
14 =head1 SYNOPSIS
15  
16 my $outlet=Power::Outlet::iBootBar->new(
17 host => "mybar",
18 outlet => 1,
19 community => "private",
20 );
21 print $outlet->query, "\n";
22 print $outlet->on, "\n";
23 print $outlet->off, "\n";
24  
25 =head1 DESCRIPTION
26
27 Power::Outlet::iBootBar is a package for controlling and querying an outlet on a Dataprobe iBootBar network attached power outlet.
28  
29 =head1 USAGE
30  
31 use Power::Outlet::iBootBar;
32 use DateTime;
33 my $lamp=Power::Outlet::iBootBar->new(host=>"mybar", outlet=>1);
34 my $hour=DateTime->now->hour;
35 my $night=$hour > 20 ? 1 : $hour < 06 ? 1 : 0;
36 if ($night) {
37 print $lamp->on, "\n";
38 } else {
39 print $lamp->off, "\n";
40 }
41  
42 =head1 CONSTRUCTOR
43  
44 =head2 new
45  
46 my $outlet=Power::Outlet->new(type=>"iBootBar", "host=>"mylamp");
47 my $outlet=Power::Outlet::iBootBar->new(host=>"mylamp");
48  
49 =head1 PROPERTIES
50  
51 =head2 host
52  
53 Sets and returns the hostname or IP address.
54  
55 Manufacturer Default: 192.168.0.254
56  
57 Note: Set IP address via telnet User Name: admin, Password: admin then "help network"
58  
59 set ipmode dhcp
60  
61 OR
62  
63 set ipmode static
64 set ipaddress 192.168.0.254
65 set subnet 255.255.255.0
66 set gateway 192.168.0.1
67  
68 =cut
69  
70 2 ▶sub _host_default {"192.168.0.254"};
Subroutine _host_default: called CC=1 SCAR=0.0
71  
72 =head2 community
73  
74 Sets and returns the SNMP community.
75  
76 my $community=$outlet->community("private"); #read/write
77 my $community=$outlet->community("public"); #read only features
78  
79 Note: Set SNMP community via telnet User Name: admin, Password: admin then "help snmp"
80  
81 set snmp writecommunity private
82 set snmp readcommunity public
83 set snmp 1 enable yes
84  
85 =cut
86  
87 2 ▶sub _community_default {"private"};
Subroutine _community_default: called CC=1 SCAR=0.0
88  
89 =head2 outlet
90  
91 Sets and returns the outlet number as labeled on the back of the device.
92  
93 Default: 1
94  
95 =cut
96  
97 4 ▶sub outlet {
Subroutine outlet: called CC=4 SCAR=14.1
Pod documented
98 4 my $self=shift;
99 4 ▶ $self->{"outlet"}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
100 4 ▶ $self->{"outlet"}=1 unless defined $self->{"outlet"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"outlet"} 2 2 4
101 4 ▶ die("Error: outlet property must be set from 1 to 8.") unless $self->{"outlet"} =~ m/\A[1-8]\Z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"outlet"} =~ /\A[1-8]\Z/ 0 4 4
102 4 return $self->{"outlet"};
103 }
104  
105 0 ▶sub _outletIndex {shift->outlet - 1};
Subroutine _outletIndex: not called CC=1 SCAR=6.9
106  
107 0 ▶sub _oid_outletStatus {
Subroutine _oid_outletStatus: not called CC=1 SCAR=6.9
108 0 my $self=shift;
109 0 return join(".", $_oid_outletEntry, "3", $self->_outletIndex); #oids so MIB is not required
110 }
111  
112 0 ▶sub _oid_outletCommand {
Subroutine _oid_outletCommand: not called CC=1 SCAR=6.9
113 0 my $self=shift;
114 0 return join(".", $_oid_outletEntry, "4", $self->_outletIndex); #oids so MIB is not required
115 }
116  
117 0 ▶sub _oid_outletName {
Subroutine _oid_outletName: not called CC=1 SCAR=6.9
118 0 my $self=shift;
119 0 return join(".", $_oid_outletEntry, "2", $self->_outletIndex); #oids so MIB is not required
120 }
121  
122 =head2 name
123  
124 Returns the name from the iBootBar outletName via SNMP
125  
126 $ telnet iBootBar
127  
128 iBootBar Rev 1.5d.275
129  
130 User Name: admin
131 Password: *****
132  
133 iBootBar > help outlet
134 ...
135 set outlet <1-8> name <name>
136 ...
137  
138 iBootBar > set outlet 1 name "Bar 1"
139  
140 =cut
141  
142 0 ▶sub _name_default {
Subroutine _name_default: not called CC=1 SCAR=6.9
143 0 my $self=shift;
144 0 my $value=$self->snmp_get($self->_oid_outletName); #this value is cached in the super class
145 0 return $value;
146 }
147  
148 =head1 METHODS
149  
150 =head2 query
151  
152 Sends a TCP/IP message to the iBootBar device to query the current state
153  
154 =cut
155  
156 0 ▶sub query {
Subroutine query: not called CC=3 SCAR=24.8
Pod documented
157 0 my $self=shift;
158 0 ▶ if (defined wantarray) { #scalar and list context
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
159 0 my %status=(0 => "OFF", 1 => "ON", 2 => "REBOOT", 3 => "CYCLE", 4 => "ONPENDING", 5 => "CYCLEPENDING");
160 0 my $value=$self->snmp_get($self->_oid_outletStatus);
161 0 ▶ return $status{$value} || "UNKNOWN($value)";
Condition0%0/2
$status{$value} || "UNKNOWN($value)"
l!l
00
MC/DC0%0/1
$status{$value} || "UNKNOWN($value)"
$status{$value}
Truth table0%0/2
A
A= $status{$value}
Aresult
11
00
162 } else { #void context
163 0 return;
164 }
165 }
166  
167 =head2 on
168  
169 Sends a TCP/IP message to the iBoot device to Turn Power ON
170  
171 =cut
172  
173 0 ▶sub on {
Subroutine on: not called CC=1 SCAR=6.9
Pod documented
174 0 my $self=shift;
175 0 $self->snmp_set($self->_oid_outletCommand, 1);
176 0 sleep 0.1;
177 0 return $self->query;
178 }
179  
180 =head2 off
181  
182 Sends a TCP/IP message to the iBoot device to Turn Power OFF
183  
184 =cut
185  
186 0 ▶sub off {
Subroutine off: not called CC=1 SCAR=6.9
Pod documented
187 0 my $self=shift;
188 0 $self->snmp_set($self->_oid_outletCommand, 0);
189 0 sleep 0.1;
190 0 return $self->query;
191 }
192  
193  
194 =head2 switch
195  
196 Queries the device for the current status and then requests the opposite.
197  
198 =cut
199  
200 #see Power::Outlet::Common->switch
201  
202 =head2 cycle
203  
204 Sends a TCP/IP message to the iBoot device to Cycle Power (ON-OFF-ON or OFF-ON-OFF). Cycle time is determined by Setup.
205  
206 Manufacturer Default Cycle Period: 10 seconds
207  
208 =cut
209  
210 0 ▶sub cycle {
Subroutine cycle: not called CC=1 SCAR=6.9
Pod documented
211 0 my $self=shift;
212 0 $self->snmp_set($self->_oid_outletCommand, 2);
213 0 sleep 0.1;
214 0 return $self->query;
215  
216 }
217  
218 =head1 BUGS
219  
220 Please log on RT and send an email to the author.
221  
222 =head1 SUPPORT
223  
224 DavisNetworks.com supports all Perl applications including this package.
225  
226 =head1 AUTHOR
227  
228 Michael R. Davis
229 CPAN ID: MRDVT
230 DavisNetworks.com
231  
232 =head1 COPYRIGHT
233  
234 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
235  
236 The full text of the license can be found in the LICENSE file included with this module.
237  
238 =head1 SEE ALSO
239  
240 =cut
241  
242 3 1;
« lib/Power/Outlet/Common/IP/HTTP.pm ↑ Summary lib/Power/Outlet/Common.pm »