Info/Layer7/Stormshield.pm untested

filter: Statementstmt 0.0% 0 / 121 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 257 CC 3 SCAR 9.4
CC
3
Cov
0%
_ifindex_conversion
6.0
_map_table
6.0
vendor
2.0
CRAP 2.6
1 # SNMP::Info::Layer7::Stormshield
2 #
3 # Copyright (c) 2025 snmp-info Developers
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::Layer7::Stormshield;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer7;
36 use Data::Dumper;
37  
38 @SNMP::Info::Layer7::Stormshield::ISA = qw/SNMP::Info::Layer7 Exporter/;
39 @SNMP::Info::Layer7::Stormshield::EXPORT_OK = qw//;
40  
41 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
42  
43 $VERSION = '3.985003';
44  
45 %MIBS = (
46 %SNMP::Info::Layer7::MIBS,
47 'STORMSHIELD-HA-MIB' => 'snsFwSerial',
48 'STORMSHIELD-IF-MIB' => 'snsifUserName',
49 'STORMSHIELD-PROPERTY-MIB' => 'snsSerialNumber',
50 );
51  
52  
53 # use qualified names to avoid leaf conflicts. There is PROPERTY, HA and some DEPRECATED mibs
54 # with identical symbols
55  
56 %GLOBALS = (
57 %SNMP::Info::Layer7::GLOBALS,
58 'propmib_serial' => 'STORMSHIELD_PROPERTY_MIB__snsSerialNumber',
59 'propmib_model' => 'STORMSHIELD_PROPERTY_MIB__snsModel',
60 'propmib_version' => 'STORMSHIELD_PROPERTY_MIB__snsVersion',
61 'propmib_systemname' => 'STORMSHIELD_PROPERTY_MIB__snsSystemName',
62 );
63  
64 %FUNCS = (
65 %SNMP::Info::Layer7::FUNCS,
66 # HA MIB
67 'hamib_serial' => 'STORMSHIELD_HA_MIB__snsFwSerial',
68 'hamib_model' => 'STORMSHIELD_HA_MIB__snsModel',
69 'hamib_version' => 'STORMSHIELD_HA_MIB__snsVersion',
70 'hamib_halicense' => 'STORMSHIELD_HA_MIB__snsHALicence',
71 # can't use, MAX-ACCESS not-accessible
72 #'hamib_nodeindex' => 'STORMSHIELD_HA_MIB__snsNodeIndex',
73  
74 # use STORMSHIELD_IF_MIB
75 # it uses different indexes than ifXEntry so we need to take care
76 # of not mixing things up.
77 'ifmib_interfaces' => 'STORMSHIELD_IF_MIB__snsifDrvName',
78 'i_name' => 'STORMSHIELD_IF_MIB__snsifName',
79 'i_alias' => 'STORMSHIELD_IF_MIB__snsifName',
80 'i_description' => 'STORMSHIELD_IF_MIB__snsifUserName',
81 'i_type' => 'STORMSHIELD_IF_MIB__snsifType',
82 'i_index' => 'STORMSHIELD_IF_MIB__snsifIndex',
83  
84 # regular interface tables
85 '_mib2_i_description' => 'IF-MIB__ifDescr',
86  
87 );
88  
89 %MUNGE = (
90 %SNMP::Info::Layer7::MUNGE
91 );
92  
93 sub _ifindex_conversion {
94 my $Stormshield = shift;
95  
96 # return a table that maps ifTable indexes to snsifTable indexes, so we can look up STORMSHIELD_IF_MIB data using standard IF-MIB indexes
97  
98 # .iso.org.dod.internet.private.enterprises.stormshield.stormshieldMIB.snsif.snsifTable.snsifEntry.snsifDrvName.1 = STRING: "tun0"
99 # .iso.org.dod.internet.private.enterprises.stormshield.stormshieldMIB.snsif.snsifTable.snsifEntry.snsifDrvName.4 = STRING: "igc7"
100 # .iso.org.dod.internet.private.enterprises.stormshield.stormshieldMIB.snsif.snsifTable.snsifEntry.snsifDrvName.5 = STRING: "igc6"
101  
102 # .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifDescr.7 = STRING: "igc6"
103 # .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifDescr.8 = STRING: "igc7"
104 # .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifDescr.12 = STRING: "tun0"
105  
106 my $snsif = $Stormshield->ifmib_interfaces() || {};
107 my $mib2if_desc = $Stormshield->_mib2_i_description() || {};
108 my $mib2if = {reverse %$mib2if_desc};
109 my $map_m2s = {};
110  
111 foreach my $si ( keys %$snsif ) {
112 my $sv = $snsif->{$si};
113 my $mib_index = $mib2if->{$sv};
114 if (defined $mib_index) {
115 $map_m2s->{$mib_index} = $si;
116 }
117 }
118  
119 # now for e.g. ifDescr.8 (igc7):
120 # this will return $map_m2s->{8} = 4, the STORMSHIELD_IF_MIB index for igc7
121 return $map_m2s;
122 }
123  
124 sub _map_table {
125 # get STORMSHIELD_IF_MIB data and map it to standard IF-MIB indexes
126 my ($Stormshield, $snsif_method) = @_;
127 my $map_m2s = $Stormshield->_ifindex_conversion();
128
129 # Map method names to their SNMP attribute names
130 my %method_to_attr = (
131 'i_name' => 'snsifName',
132 'i_alias' => 'snsifName',
133 'i_description' => 'snsifUserName',
134 'i_type' => 'snsifType',
135 'i_index' => 'snsifIndex',
136 );
137
138 my $attr_name = $method_to_attr{$snsif_method};
139
140 # Get the raw SNMP data by calling the attribute method directly
141 my $snsif_data = {};
142 if ($attr_name && $Stormshield->can($attr_name)) {
143 $snsif_data = $Stormshield->$attr_name() || {};
144 }
145
146 my $out = {};
147  
148 foreach my $mib_index ( keys %$map_m2s ) {
149 my $snsif_index = $map_m2s->{$mib_index};
150 $out->{$mib_index} = $snsif_data->{$snsif_index};
151 }
152 return $out;
153 }
154  
155  
156 sub vendor {
157 return 'stormshield';
158 }
159  
160 sub os {
161 return 'SNS';
162 }
163  
164 sub name {
165 my $Stormshield = shift;
166 return $Stormshield->propmib_systemname() || $Stormshield->SUPER::name();
167 }
168  
169 sub serial {
170  
171 my $Stormshield = shift;
172 return $Stormshield->propmib_serial() // '';
173 }
174  
175  
176 sub model {
177 my $Stormshield = shift;
178 return $Stormshield->propmib_model() // '';
179 }
180  
181  
182 sub os_ver {
183 my $Stormshield = shift;
184 return $Stormshield->propmib_version() // '';
185 }
186  
187  
188 sub e_index {
189  
190 my $Stormshield = shift;
191 my $hamib_serials = $Stormshield->hamib_serial() || ();
192 my %e_index;
193 foreach my $iid (keys %$hamib_serials) {
194 $e_index{$iid} = $iid;
195 }
196  
197 return \%e_index;
198 }
199  
200 sub e_class {
201  
202 my $Stormshield = shift;
203 my $hamib_serials = $Stormshield->hamib_serial() || ();
204 my %e_index;
205 foreach my $iid (keys %$hamib_serials) {
206 $e_index{$iid} = "chassis";
207 }
208  
209 return \%e_index;
210 }
211  
212 sub e_name {
213  
214 my $Stormshield = shift;
215 my $hamib_serials = $Stormshield->hamib_serial() || ();
216 my %e_index;
217 foreach my $iid (keys %$hamib_serials) {
218 $e_index{$iid} = "chassis." . $iid;
219 }
220  
221 return \%e_index;
222 }
223  
224 sub e_vendor {
225  
226 my $Stormshield = shift;
227 my $hamib_serials = $Stormshield->hamib_serial() || ();
228 my %e_index;
229 foreach my $iid (keys %$hamib_serials) {
230 $e_index{$iid} = $Stormshield->vendor();
231 }
232  
233 return \%e_index;
234 }
235  
236 sub e_descr {
237  
238 my $Stormshield = shift;
239 my $hamib_models = $Stormshield->hamib_model() || ();
240 my $hamib_halicense = $Stormshield->hamib_halicense() || ();
241 my $hamib_serials = $Stormshield->hamib_serial() || ();
242 my $hamib_version = $Stormshield->hamib_version() || ();
243 my %e_index;
244 foreach my $iid (keys %$hamib_models) {
245 $e_index{$iid} = $hamib_models->{$iid} . " " . $hamib_halicense->{$iid} . " " . $hamib_serials->{$iid} . " " . $hamib_version->{$iid};
246 }
247  
248 return \%e_index;
249 }
250  
251 sub e_model {
252  
253 my $Stormshield = shift;
254 my $hamib_models = $Stormshield->hamib_model() || ();
255 my %e_index;
256 foreach my $iid (keys %$hamib_models) {
257 $e_index{$iid} = $hamib_models->{$iid};
258 }
259  
260 return \%e_index;
261 }
262  
263 sub e_swver {
264  
265 my $Stormshield = shift;
266 my $hamib_version = $Stormshield->hamib_version() || ();
267 my %e_index;
268 foreach my $iid (keys %$hamib_version) {
269 $e_index{$iid} = $hamib_version->{$iid};
270 }
271  
272 return \%e_index;
273 }
274  
275  
276 sub e_serial {
277  
278 my $Stormshield = shift;
279 my $hamib_serials = $Stormshield->hamib_serial() || ();
280 my %e_index;
281 foreach my $iid (keys %$hamib_serials) {
282 $e_index{$iid} = $hamib_serials->{$iid};
283 }
284  
285 return \%e_index;
286 }
287  
288 # Interface methods - all grouped together
289 sub interfaces {
290 # return standard IF-MIB interface names keyed by standard IF-MIB indexes
291 my $Stormshield = shift;
292 return $Stormshield->_mib2_i_description();
293 }
294  
295  
296 # STORMSHIELD_IF_MIB specific methods that map to standard IF-MIB indexes
297 sub i_name {
298 my $Stormshield = shift;
299 return $Stormshield->_map_table('i_name');
300 }
301  
302 sub i_alias {
303 my $Stormshield = shift;
304 return $Stormshield->_map_table('i_alias');
305 }
306  
307 sub i_description {
308 my $Stormshield = shift;
309 return $Stormshield->_map_table('i_description');
310 }
311  
312 sub i_type {
313 my $Stormshield = shift;
314 return $Stormshield->_map_table('i_type');
315 }
316  
317 sub i_index {
318 my $Stormshield = shift;
319 return $Stormshield->_map_table('i_index');
320 }
321  
322 1;
323  
324 __END__