Info/Layer2/CiscoSB.pm untested

filter: Statementstmt 0.0% 0 / 76 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 147 CC 9 SCAR 22.2
CC
9
Cov
0%
i_duplex
30.0
serial
6.0
os_ver
6.0
CRAP 9.2
1 # SNMP::Info::Layer2::CiscoSB
2 #
3 # Copyright (c) 2013 Nic Bernstein
4 #
5 # Copyright (c) 2008-2009 Max Baker changes from version 0.8 and beyond.
6 #
7 # Copyright (c) 2003 Regents of the University of California
8 # All rights reserved.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are met:
12 #
13 # * Redistributions of source code must retain the above copyright notice,
14 # this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # * Neither the name of the University of California, Santa Cruz nor the
19 # names of its contributors may be used to endorse or promote products
20 # derived from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33  
34 package SNMP::Info::Layer2::CiscoSB;
35  
36 use strict;
37 use warnings;
38 use Exporter;
39 use SNMP::Info::Layer2;
40 use SNMP::Info::EtherLike;
41 use SNMP::Info::CiscoStats;
42 use SNMP::Info::CiscoConfig;
43 use SNMP::Info::CDP;
44  
45 @SNMP::Info::Layer2::CiscoSB::ISA
46 = qw/SNMP::Info::Layer2 SNMP::Info::EtherLike
47 SNMP::Info::CiscoStats SNMP::Info::CiscoConfig SNMP::Info::CDP Exporter/;
48 @SNMP::Info::Layer2::CiscoSB::EXPORT_OK = qw//;
49  
50 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
51  
52 $VERSION = '3.985003';
53  
54 %GLOBALS = (
55 %SNMP::Info::Layer2::GLOBALS,
56 %SNMP::Info::EtherLike::GLOBALS,
57 %SNMP::Info::CiscoStats::GLOBALS,
58 %SNMP::Info::CiscoConfig::GLOBALS,
59 %SNMP::Info::CDP::GLOBALS,
60 'descr' => 'sysDescr',
61 'mac' => 'rndBasePhysicalAddress',
62 );
63  
64 %FUNCS = (
65 %SNMP::Info::Layer2::FUNCS,
66 %SNMP::Info::EtherLike::FUNCS,
67 %SNMP::Info::CiscoStats::FUNCS,
68 %SNMP::Info::CiscoConfig::FUNCS,
69 %SNMP::Info::CDP::FUNCS,
70 'peth_port_power' => 'rlPethPsePortOutputPower',
71 );
72  
73 %MIBS = (
74 %SNMP::Info::Layer2::MIBS,
75 %SNMP::Info::EtherLike::MIBS,
76 %SNMP::Info::CiscoStats::MIBS,
77 %SNMP::Info::CiscoConfig::MIBS,
78 %SNMP::Info::CDP::MIBS,
79 'CISCOSB-POE-MIB' => 'rlPethPsePortOutputPower',
80 'CISCOSB-DEVICEPARAMS-MIB' => 'rndBasePhysicalAddress',
81 );
82  
83 %MUNGE = (
84 %SNMP::Info::Layer2::MUNGE,
85 %SNMP::Info::EtherLike::MUNGE,
86 %SNMP::Info::CiscoStats::MUNGE,
87 %SNMP::Info::CiscoConfig::MUNGE,
88 %SNMP::Info::CDP::MUNGE,
89 );
90  
91 sub vendor {
92 return 'cisco';
93 }
94  
95 sub os {
96 return 'ros';
97 }
98  
99 # Walk the entPhysicalSerialNum table and return the first serial found
100 sub serial {
101 my $ciscosb = shift;
102 my $e_serial = $ciscosb->e_serial();
103  
104 # Find entity table entry for this unit
105 foreach my $e ( sort keys %$e_serial ) {
106 if (defined $e_serial->{$e} and $e_serial->{$e} !~ /^\s*$/) {
107 return $e_serial->{$e};
108 }
109 }
110 }
111  
112 sub os_ver {
113 my $ciscosb = shift;
114 my $e_swver = $ciscosb->e_swver();
115  
116 foreach my $e ( sort keys %$e_swver ) {
117 if (defined $e_swver->{$e} and $e_swver->{$e} !~ /^\s*$/) {
118 return $e_swver->{$e};
119 }
120 }
121 }
122  
123 # Grab e_model from Entity and tag on e_hwver
124 sub model {
125 my $ciscosb = shift;
126 my $e_model = $ciscosb->e_model();
127 my $e_hwver = $ciscosb->e_hwver();
128  
129 foreach my $e ( sort keys %$e_model ) {
130 if (defined $e_model->{$e} and $e_model->{$e} !~ /^\s*$/) {
131 return $e_model->{$e};
132 #my $model = "$e_model->{$e} $e_hwver->{$e}";
133 #return $model;
134 }
135 }
136 return $ciscosb->description();
137 }
138  
139 # CISCOSBinterfaces.mib also contains duplex info if needed
140 sub i_duplex {
141 my $ciscosb = shift;
142 my $partial = shift;
143  
144 my $el_duplex = $ciscosb->el_duplex($partial);
145  
146 if ( defined $el_duplex and scalar( keys %$el_duplex ) ) {
147 my %i_duplex;
148 foreach my $el_port ( keys %$el_duplex ) {
149 my $duplex = $el_duplex->{$el_port};
150 next unless defined $duplex;
151  
152 $i_duplex{$el_port} = 'half' if $duplex =~ /half/i;
153 $i_duplex{$el_port} = 'full' if $duplex =~ /full/i;
154 }
155 return \%i_duplex;
156 }
157 }
158  
159 # ifDescr is the same for all interfaces in a class, but the ifName is
160 # unique, so let's use that for port name.
161 sub interfaces {
162 my $ciscosb = shift;
163 my $partial = shift;
164  
165 my $interfaces = $ciscosb->orig_i_name($partial);
166  
167 return $interfaces;
168 }
169  
170 # Port descriptions are configured in ifAlias; fall back to ifName
171 sub i_name {
172 my $ciscosb = shift;
173 my $partial = shift;
174  
175 my $names = $ciscosb->orig_i_name($partial) || {};
176 my $aliases = $ciscosb->i_alias($partial) || {};
177  
178 my %i_name;
179 foreach my $iid ( keys %$names ) {
180 my $alias = $aliases->{$iid};
181 $i_name{$iid}
182 = ( defined $alias and $alias !~ /^\s*$/ )
183 ? $alias
184 : $names->{$iid};
185 }
186 return \%i_name;
187 }
188  
189 1;
190 __END__