Info/Layer3/F5.pm untested

filter: Statementstmt 0.0% 0 / 143 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 243 CC 16 SCAR 23.8
CC
16
Cov
0%
i_vlan
20.0
i_vlan_membership_untagged
20.0
_convert_f5id_stdid
12.0
CRAP 10.8
1 # SNMP::Info::Layer3::F5
2 #
3 # Copyright (c) 2012 Eric Miller
4 # All Rights Reserved
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29  
30 package SNMP::Info::Layer3::F5;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer3;
36  
37 @SNMP::Info::Layer3::F5::ISA = qw/SNMP::Info::Layer3 Exporter/;
38 @SNMP::Info::Layer3::F5::EXPORT_OK = qw//;
39  
40 our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45 %SNMP::Info::Layer3::MIBS,
46 'F5-BIGIP-SYSTEM-MIB' => 'sysAttrArpMaxEntries',
47 );
48  
49 %GLOBALS = (
50 %SNMP::Info::Layer3::GLOBALS,
51 'os_ver' => 'sysProductVersion',
52 'mkt_name' => 'sysPlatformInfoMarketingName',
53 'ps1_status' => 'sysChassisPowerSupplyStatus.1',
54 'ps2_status' => 'sysChassisPowerSupplyStatus.2',
55  
56 # Named serial1 to override serial1 in L3 serial method
57 'serial1' => 'sysGeneralChassisSerialNum',
58 'qb_vlans' => 'sysVlanNumber',
59 'ports' => 'sysInterfaceNumber',
60  
61 );
62  
63 %FUNCS = (
64 %SNMP::Info::Layer3::FUNCS,
65  
66 # sysInterfaceTable
67 'sys_i_description' => 'sysInterfaceName',
68 'sys_i_mtu' => 'sysInterfaceMtu',
69 'sys_i_speed' => 'sysInterfaceMediaActiveSpeed',
70 'sys_i_up_admin' => 'sysInterfaceEnabled',
71 'sys_i_up' => 'sysInterfaceStatus',
72 'sys_i_duplex' => 'sysInterfaceMediaActiveDuplex',
73  
74 # sysChassisFanTable
75 'fan_state' => 'sysChassisFanStatus',
76  
77 # sysVlanTable
78 'sys_v_id' => 'sysVlanId',
79 'sys_v_name' => 'sysVlanVname',
80  
81 # sysVlanMemberTable
82 'sys_vm_tagged' => 'sysVlanMemberTagged',
83 'sys_vm_name' => 'sysVlanMemberVmname',
84 'sys_vmp_name' => 'sysVlanMemberParentVname',
85 );
86  
87 %MUNGE = ( %SNMP::Info::Layer3::MUNGE, );
88  
89 sub _convert_f5id_stdid {
90 my $f5 = shift;
91 my $partial = shift;
92 my $id = shift;
93 my $sys_i_description = $f5->sys_i_description($partial) || {};
94 my $i_name = $f5->i_name($partial) || {};
95
96 if (exists($sys_i_description->{$id})) {
97 my @result = grep { $i_name->{$_} eq $sys_i_description->{$id} } keys %$i_name;
98 if (scalar @result eq 1) {
99 return $result[0];
100 }
101 }
102 return $id;
103 };
104  
105 sub vendor {
106 return 'f5';
107 }
108  
109 sub os {
110 return 'f5';
111 }
112  
113 sub fan {
114 my $f5 = shift;
115 my $fan_state = $f5->fan_state();
116 my $ret = "";
117 my $s = "";
118 foreach my $i ( sort { $a <=> $b } keys %$fan_state ) {
119 $ret .= $s . $i . ': ' . $fan_state->{$i};
120 $s = ', ';
121 }
122 return if ( $s eq "" );
123 return $ret;
124 }
125  
126 sub model {
127 my $f5 = shift;
128  
129 my $name = $f5->mkt_name();
130  
131 if ( defined $name ) { return $name; }
132  
133 my $id = $f5->id();
134 my $model = &SNMP::translateObj($id);
135 if ( !defined $model ) { return $id; }
136  
137 return $model;
138 }
139  
140 # Override L3 i_mtu
141 sub i_mtu {
142 my $f5 = shift;
143 my $partial = shift;
144  
145 my $mtu = $f5->sys_i_mtu($partial) || {};
146 my $i_mtu = {};
147 while (my ($iid,$value) = each( %$mtu )) {
148 $i_mtu->{$f5->_convert_f5id_stdid($partial,$iid)} = $value;
149 }
150
151 return $i_mtu;
152 }
153  
154 # Override L3 i_duplex
155 sub i_duplex {
156 my $f5 = shift;
157 my $partial = shift;
158  
159 my $duplexes = $f5->sys_i_duplex() || {};
160  
161 my $i_duplex = {};
162 while (my ($iid,$duplex) = each( %$duplexes )) {
163 next unless defined $duplex;
164 next if ( $duplex eq 'none' );
165  
166 $i_duplex->{$f5->_convert_f5id_stdid($partial,$iid)} = $duplex;
167 }
168 return $i_duplex;
169 }
170  
171 # Override Bridge v_index
172 sub v_index {
173 my $f5 = shift;
174 my $partial = shift;
175  
176 my $v_idx = $f5->sys_v_id($partial);
177 my $v_index = {};
178 while (my ($vid,$value) = each( %$v_idx )) {
179 $v_index->{$vid =~ s/\.//gr} = $value;
180 }
181  
182 return $v_index;
183 }
184  
185 # Override Bridge v_name
186 sub v_name {
187 my $f5 = shift;
188 my $partial = shift;
189  
190 my $vlan_names = $f5->sys_v_name($partial) || {};
191 my $v_name = {};
192 while (my ($vid,$value) = each( %$vlan_names )) {
193 $v_name->{$vid =~ s/\.//gr} = $value;
194 }
195  
196 return $v_name;
197 }
198  
199 sub i_vlan {
200 my $f5 = shift;
201 my $partial = shift;
202  
203 my $index = $f5->interfaces($partial) || {};
204 my $tagged = $f5->sys_vm_tagged() || {};
205 my $vlans = $f5->v_index() || {};
206  
207 my $i_vlan = {};
208 foreach my $iid ( keys %$tagged ) {
209 my $tag = $tagged->{$iid};
210 next if ( $tag eq 'true' );
211  
212 # IID is length.vlan name index.length.interface index
213 # Split out and use as the IID to get the VLAN ID and ifIndex
214 my @iid_array = split(/\./, $iid);
215 my $len = $iid_array[0];
216 my $v_idx = join('', ( splice @iid_array, 0, $len + 1 ));
217 my $idx = $f5->_convert_f5id_stdid($partial,join('.', @iid_array));
218  
219 # Check to make sure we can map to a port
220 my $p_idx = $index->{$idx};
221 next unless $p_idx;
222  
223 my $vlan = $vlans->{$v_idx};
224 next unless $vlan;
225  
226 $i_vlan->{$idx} = $vlan;
227 }
228 return $i_vlan;
229 }
230  
231 sub i_vlan_membership {
232 my $f5 = shift;
233 my $partial = shift;
234  
235 my $index = $f5->interfaces($partial) || {};
236 my $tagged = $f5->sys_vm_tagged() || {};
237 my $vlans = $f5->v_index() || {};
238  
239 my $i_vlan_membership = {};
240 foreach my $iid ( keys %$tagged ) {
241  
242 # IID is length.vlan name index.length.interface index
243 # Split out and use as the IID to get the VLAN ID and ifIndex
244 my @iid_array = split (/\./, $iid);
245 my $len = $iid_array[0];
246 my $v_idx = join ('.', ( splice @iid_array, 0, $len + 1 ));
247 my $idx = $f5->_convert_f5id_stdid($partial,join ('.', @iid_array));
248  
249 # Check to make sure we can map to a port
250 my $p_idx = $index->{$idx};
251 next unless $p_idx;
252  
253 my $vlan = $vlans->{$v_idx};
254 next unless $vlan;
255  
256 push( @{ $i_vlan_membership->{$idx} }, $vlan );
257 }
258 return $i_vlan_membership;
259 }
260  
261 sub i_vlan_membership_untagged {
262 my $f5 = shift;
263 my $partial = shift;
264  
265 my $index = $f5->interfaces($partial) || {};
266 my $tagged = $f5->sys_vm_tagged() || {};
267 my $vlans = $f5->v_index() || {};
268  
269 my $i_vlan_membership = {};
270 foreach my $iid ( keys %$tagged ) {
271  
272 next unless $tagged->{$iid} eq 'false';
273 # IID is length.vlan name index.length.interface index
274 # Split out and use as the IID to get the VLAN ID and ifIndex
275 my @iid_array = split (/\./, $iid);
276 my $len = $iid_array[0];
277 my $v_idx = join ('.', ( splice @iid_array, 0, $len + 1 ));
278 my $idx = $f5->_convert_f5id_stdid($partial,join ('.', @iid_array));
279  
280 # Check to make sure we can map to a port
281 my $p_idx = $index->{$idx};
282 next unless $p_idx;
283  
284 my $vlan = $vlans->{$v_idx};
285 next unless $vlan;
286  
287 push( @{ $i_vlan_membership->{$idx} }, $vlan );
288 }
289 return $i_vlan_membership;
290 }
291  
292 1;
293 __END__