Info/Layer2/Netgear.pm untested

filter: Statementstmt 0.0% 0 / 76 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 169 CC 15 SCAR 29.7
CC
15
Cov
0%
serial
30.0
interfaces
30.0
os_ver
30.0
CRAP 19.4
1 # SNMP::Info::Layer2::Netgear
2 #
3 # Copyright (c) 2008 Bill Fenner
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::Layer2::Netgear;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer2;
36  
37 @SNMP::Info::Layer2::Netgear::ISA = qw/SNMP::Info::Layer2 Exporter/;
38 @SNMP::Info::Layer2::Netgear::EXPORT_OK = qw//;
39  
40 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 # This will be filled in with the device's index into the EntPhysicalEntry
45 # table by the serial() function.
46 our $index = undef;
47  
48 %MIBS = ( %SNMP::Info::Layer2::MIBS, );
49  
50 %GLOBALS = (
51 %SNMP::Info::Layer2::GLOBALS,
52 ng_fsosver => '.1.3.6.1.4.1.4526.11.11.1.0',
53 ng_gsmserial => '.1.3.6.1.4.1.4526.10.1.1.1.4.0',
54 ng_gsmosver => '.1.3.6.1.4.1.4526.10.1.1.1.13.0',
55 );
56  
57 %FUNCS = ( %SNMP::Info::Layer2::FUNCS, );
58  
59 %MUNGE = ( %SNMP::Info::Layer2::MUNGE, );
60  
61 sub vendor {
62 return 'netgear';
63 }
64  
65 sub os {
66 return 'netgear';
67 }
68  
69 # We will attempt to use Entity-MIB if present. In that case, we will
70 # also set the shared variable $index, which is used by other functions
71 # to index within Entity-MIB tables. This assumes, of course, that there
72 # is only one serial number (entPhysicalSerialNum) present in the table.
73 sub serial {
74 my $netgear = shift;
75 my $serial = undef;
76  
77 my $e_serial = $netgear->e_serial();
78 if (defined($e_serial)) { # This unit sports the Entity-MIB
79 # Find entity table entry for this unit
80 foreach my $e ( keys %$e_serial ) {
81 if (defined ($e_serial->{$e}) and $e_serial->{$e} !~ /^\s*$/) {
82 $index = $e;
83 last;
84 }
85 }
86 return $e_serial->{$index} if defined $index;
87 }
88  
89 # Without Entity-MIB, we've got to work our way through a bunch of
90 # different locales...
91 return $netgear->ng_gsmserial() if defined $netgear->model and $netgear->model =~ m/[FG]SM\d/i;;
92 return 'none';
93 }
94  
95 # If device supports Entity-MIB, index into that to divine model and
96 # hardware version, otherwise default to sysDescr.
97 sub model {
98 my $netgear = shift;
99 if (defined($index)) {
100 my $model = $netgear->e_descr();
101 my $e_hwver = $netgear->e_hwver();
102  
103 $model = "$model->{$index} $e_hwver->{$index}";
104 return $model;
105 }
106 return $netgear->description();
107 }
108  
109 # ifDescr is the same for all interfaces in a class, but the ifName is
110 # unique, so let's use that for port name. If all else fails,
111 # concatenate ifDesc and ifIndex.
112 sub interfaces {
113 my $netgear = shift;
114 my $partial = shift;
115  
116 my $interfaces = $netgear->i_index($partial) || {};
117 my $i_descr = $netgear->i_description($partial) || {};
118 my $i_name = $netgear->orig_i_name($partial);
119 my $i_isset = ();
120 # Replace the description with the ifName field, if set
121 foreach my $iid ( keys %$i_name ) {
122 my $name = $i_name->{$iid};
123 next unless defined $name;
124 if (defined $name and $name !~ /^\s*$/) {
125 $interfaces->{$iid} = $name;
126 $i_isset->{$iid} = 1;
127 }
128 }
129 # Replace the Index with the ifDescr field, appended with index
130 # number, to deal with devices with non-unique ifDescr.
131 foreach my $iid ( keys %$i_descr ) {
132 my $port = $i_descr->{$iid} . '-' . $iid;
133 next unless defined $port;
134 next if (defined $i_isset->{$iid} and $i_isset->{$iid} == 1);
135 $interfaces->{$iid} = $port;
136 }
137  
138 return $interfaces;
139 }
140  
141 # these seem to work for GSM/FSM models but not GS
142 # https://sourceforge.net/tracker/?func=detail&aid=3085413&group_id=70362&atid=527529
143 sub os_ver {
144 my $netgear = shift;
145 my $serial = $netgear->serial(); # Make sure that index gets primed
146 if (defined($index)) {
147 my $os_ver = $netgear->e_swver();
148 return $os_ver->{$index} if defined $os_ver;
149 }
150 return $netgear->ng_gsmosver() if defined $netgear->model and $netgear->model =~ m/[FG]SM\d/i;
151 return $netgear->ng_fsosver() if defined $netgear->model and $netgear->model =~ m/FS\d/i;
152 }
153  
154 # Port descriptions are configured in ifAlias; fall back to ifName
155 sub i_name {
156 my $netgear = shift;
157 my $partial = shift;
158  
159 my $names = $netgear->orig_i_name($partial) || {};
160 my $aliases = $netgear->i_alias($partial) || {};
161  
162 my %i_name;
163 foreach my $iid ( keys %$names ) {
164 my $alias = $aliases->{$iid};
165 $i_name{$iid}
166 = ( defined $alias and $alias !~ /^\s*$/ )
167 ? $alias
168 : $names->{$iid};
169 }
170 return \%i_name;
171 }
172  
173 1;
174  
175 __END__