Info/Layer3/DLink.pm untested

filter: Statementstmt 0.0% 0 / 88 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 194 CC 16 SCAR 24.3
CC
16
Cov
0%
model
20.0
serial
20.0
_dlink_descr_fields
12.0
CRAP 11.4
1 # SNMP::Info::Layer3::DLink - SNMP Interface to DLink Devices
2 #
3 # Copyright (c) 2019 by The Netdisco Developer Team.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the University of California, Santa Cruz nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28  
29 package SNMP::Info::Layer3::DLink;
30  
31 use strict;
32 use warnings;
33 use Exporter;
34 use SNMP::Info::Layer3;
35  
36 @SNMP::Info::Layer3::DLink::ISA = qw/SNMP::Info::Layer3 Exporter/;
37 @SNMP::Info::Layer3::DLink::EXPORT_OK = qw//;
38  
39 our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE);
40  
41 $VERSION = '3.985003';
42  
43 %MIBS = (
44 %SNMP::Info::Layer3::MIBS,
45 'DLINK-ID-REC-MIB' => 'dlink',
46 'SWPRIMGMT-DES3200-MIB' => 'dlink-des3200SeriesProd',
47 'SWPRIMGMT-DES30XXP-MIB' => 'dlink-des30xxproductProd',
48 'SWPRIMGMT-DES1228ME-MIB' => 'dlink-des1228MEproductProd',
49 'SWDES3528-52PRIMGMT-MIB' => 'dlink-Des3500Series',
50 'DES-1210-28-AX' => 'des-1210-28ax',
51 'DES-1210-10MEbx' => 'des-1210-10mebx',
52 'DES-1210-26MEbx' => 'des-1210-26mebx',
53 'DES-1210-52-BX' => 'des-1210-52bx',
54 'DES-1210-52-CX' => 'des-1210-52-cx',
55 'DGS-1210-24-AX' => 'dgs-1210-24ax',
56 );
57  
58 %GLOBALS = (
59 %SNMP::Info::Layer3::GLOBALS,
60 );
61  
62 %FUNCS = (
63 %SNMP::Info::Layer3::FUNCS,
64 'dlink_fw' => 'probeSoftwareRev',
65 'dlink_hw' => 'probeHardwareRev',
66 # Replaced with OID since these MIBs are no longer in the netdisco-mibs
67 # collection. Commit reference of MIB removal in netdisco-mibs:
68 # d6ec3f15861e28d220a681e7fa3b222c21664fda
69 'dlink_stp_i_root_port' => '.1.3.6.1.4.1.171.12.15.2.3.1.18',
70 'dlink_serial_no' => '.1.3.6.1.4.1.171.12.1.1.12',
71 # TODO: hardcoded OIDs using get() in method calls below should be
72 # replaced similarly and use the library getter methods
73 );
74  
75 %MUNGE = ( %SNMP::Info::Layer3::MUNGE, );
76  
77 sub layers {
78 my $dlink = shift;
79  
80 # Force at least L2 and L3, also when sysServices is not served
81 my $layers = $dlink->SUPER::layers() || '00000000';
82 substr $layers, 5, 1, "1";
83 substr $layers, 6, 1, "1";
84  
85 return $layers;
86 }
87  
88 # The DGS-F3008P reports a sysObjectID outside D-Link's enterprise and names
89 # its model, firmware and serial only in sysDescr:
90 # "D-LINK DGS-F3008P-4S HW V1 Firmware V5.2.10.1-g7578559a6 SerialNo
91 # H3008P200400127, L2 Ethernet PoE Switch"
92 sub _dlink_descr_fields {
93 my $dlink = shift;
94 my $descr = $dlink->description();
95  
96 return {} unless defined $descr;
97 return {} unless $descr =~ m/^D-Link\s+(\S+)\s+HW\s+\S+\s+
98 Firmware\s+V?(\S+)\s+SerialNo\s+([^\s,]+)/ix;
99 return { model => $1, os_ver => $2, serial => $3 };
100 }
101  
102 sub model {
103 my $dlink=shift;
104 my $descr_model = $dlink->_dlink_descr_fields()->{model};
105 return $descr_model if defined $descr_model;
106  
107 my $id = $dlink->id();
108 my $model = &SNMP::translateObj($id);
109 return $id unless defined $model;
110 if (defined $model && $model !~ /dlink-products/) {
111 return $model;
112 } else {
113 #If don't have a device MIB
114 return $dlink->description();
115 }
116 }
117  
118 # ifDescr is the same for all interfaces in a class, but the ifName is
119 # unique, so let's use that for port name. Some units return no ifName,
120 # so keep the ifDescr name from SUPER for those ports.
121 sub interfaces {
122 my $dlink = shift;
123 my $partial = shift;
124  
125 my $interfaces = $dlink->SUPER::interfaces($partial);
126 my $i_name = $dlink->orig_i_name($partial) || {};
127  
128 foreach my $iid ( keys %$i_name ) {
129 my $name = $i_name->{$iid};
130 next unless defined $name and $name =~ /\S/;
131 $interfaces->{$iid} = $name;
132 }
133 return $interfaces;
134 }
135  
136  
137 sub vendor {
138 return 'dlink';
139 }
140  
141 sub os_ver {
142 my $dlink = shift;
143 return $dlink->_dlink_descr_fields()->{os_ver};
144 }
145  
146 sub serial {
147 my $dlink = shift;
148 my $descr_serial = $dlink->_dlink_descr_fields()->{serial};
149 return $descr_serial if defined $descr_serial;
150  
151 my $model = $dlink->model();
152 my $id = $dlink->id();
153 my $serial;
154 if ($model =~ /1210/) {
155 #Due to the zoo of MIB from DLink by 1210 series
156 $serial->{0} = $dlink->session()->get($id.'.1.30.0');
157 } else {
158 $serial = $dlink->dlink_serial_no();
159 }
160  
161 return $serial->{0} if ( defined $serial->{0} and $serial->{0} !~ /^\s*$/ and $serial->{0} !~ 'NOSUCHOBJECT' );
162 return $dlink->SUPER::serial();
163 }
164  
165 sub fwver {
166 my $dlink=shift;
167 my $model = $dlink->model();
168 my $id = $dlink->id();
169 my $fw;
170 if ($model =~ /1210/) {
171 #Due to the zoo of MIB from DLink by 1210 series
172 $fw->{0} = $dlink->session()->get($id.'.1.3.0');
173 } else {
174 $fw = $dlink->dlink_fw();
175 }
176 return $fw->{0} if ( defined $fw->{0} and $fw->{0} !~ /^\s*$/ and $fw->{0} !~ 'NOSUCHOBJECT');
177 }
178  
179 sub hwver {
180 my $dlink=shift;
181 my $model = $dlink->model();
182 my $id = $dlink->id();
183 my $hw;
184 if ($model =~ /1210/) {
185 #Due to the zoo of MIB from DLink by 1210 series
186 $hw->{0} = $dlink->session()->get($id.'.1.2.0');
187 } else {
188 $hw = $dlink->dlink_hw();
189 }
190 return $hw->{0} if ( defined $hw->{0} and $hw->{0} !~ /^\s*$/ and $hw->{0} !~ 'NOSUCHOBJECT');
191 }
192  
193 sub stp_i_root_port {
194 my $dlink=shift;
195 my $model = $dlink->model();
196 my $id = $dlink->id();
197 my $stp_i_root_port;
198 if ($model =~ /1210-(?:10|26)/) {
199 #Due to the zoo of MIB from DLink by 1210 series
200 $stp_i_root_port->{0} = $dlink->session()->get($id.'.6.1.13.0');
201 } else {
202 $stp_i_root_port = $dlink->dlink_stp_i_root_port();
203 }
204 return $stp_i_root_port if ( defined $stp_i_root_port->{0} and $stp_i_root_port->{0} !~ /^\s*$/ and $stp_i_root_port->{0} !~ 'NOSUCHOBJECT');
205 return $dlink->SUPER::stp_i_root_port();
206 }
207  
208 1;
209 __END__