| 1 | # SNMP::Info::CiscoStats | ||
| 2 | # | ||
| 3 | # Changes since Version 0.7 Copyright (c) 2008-2009 Max Baker and SNMP::Info Developers | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # Copyright (c) 2003 Regents of the University of California | ||
| 7 | # All rights reserved. | ||
| 8 | # | ||
| 9 | # Redistribution and use in source and binary forms, with or without | ||
| 10 | # modification, are permitted provided that the following conditions are met: | ||
| 11 | # | ||
| 12 | # * Redistributions of source code must retain the above copyright notice, | ||
| 13 | # this list of conditions and the following disclaimer. | ||
| 14 | # * Redistributions in binary form must reproduce the above copyright | ||
| 15 | # notice, this list of conditions and the following disclaimer in the | ||
| 16 | # documentation and/or other materials provided with the distribution. | ||
| 17 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 18 | # names of its contributors may be used to endorse or promote products | ||
| 19 | # derived from this software without specific prior written permission. | ||
| 20 | # | ||
| 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 25 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 31 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 32 | |||
| 33 | package SNMP::Info::CiscoStats; | ||
| 34 | |||
| 35 | use strict; | ||
| 36 | use warnings; | ||
| 37 | use Exporter; | ||
| 38 | use SNMP::Info; | ||
| 39 | |||
| 40 | @SNMP::Info::CiscoStats::ISA = qw/SNMP::Info Exporter/; | ||
| 41 | @SNMP::Info::CiscoStats::EXPORT_OK = qw//; | ||
| 42 | |||
| 43 | our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE); | ||
| 44 | |||
| 45 | $VERSION = '3.985003'; | ||
| 46 | |||
| 47 | %MIBS = ( | ||
| 48 | 'SNMPv2-MIB' => 'sysDescr', | ||
| 49 | 'CISCO-PROCESS-MIB' => 'cpmCPUTotal5sec', | ||
| 50 | 'CISCO-MEMORY-POOL-MIB' => 'ciscoMemoryPoolUsed', | ||
| 51 | 'OLD-CISCO-SYSTEM-MIB' => 'writeMem', | ||
| 52 | 'CISCO-PRODUCTS-MIB' => 'ciscoIGS', | ||
| 53 | 'ENTITY-MIB' => 'entPhysicalSoftwareRev', | ||
| 54 | 'CISCO-IMAGE-MIB' => 'ciscoImageString', | ||
| 55 | |||
| 56 | # some older catalysts live here | ||
| 57 | 'CISCO-STACK-MIB' => 'wsc1900sysID', | ||
| 58 | 'CISCO-ENTITY-VENDORTYPE-OID-MIB' => 'cevChassis', | ||
| 59 | 'CISCO-FLASH-MIB' => 'ciscoFlashDeviceSize', | ||
| 60 | ); | ||
| 61 | |||
| 62 | %GLOBALS = ( | ||
| 63 | 'description' => 'sysDescr', | ||
| 64 | 'ent_physical_software_rev' => 'entPhysicalSoftwareRev.1', | ||
| 65 | |||
| 66 | # We will use the numeric OID's so that we don't require people | ||
| 67 | # to install v1 MIBs, which can conflict. | ||
| 68 | # OLD-CISCO-CPU-MIB:avgBusyPer | ||
| 69 | 'ios_cpu' => '1.3.6.1.4.1.9.2.1.56.0', | ||
| 70 | 'ios_cpu_1min' => '1.3.6.1.4.1.9.2.1.57.0', | ||
| 71 | 'ios_cpu_5min' => '1.3.6.1.4.1.9.2.1.58.0', | ||
| 72 | |||
| 73 | # CISCO-PROCESS-MIB | ||
| 74 | 'cat_cpu' => 'cpmCPUTotal5sec.9', | ||
| 75 | 'cat_cpu_1min' => 'cpmCPUTotal1min.9', | ||
| 76 | 'cat_cpu_5min' => 'cpmCPUTotal5min.9', | ||
| 77 | |||
| 78 | # OLD-CISCO-SYSTEM-MIB | ||
| 79 | 'write_mem' => 'writeMem', | ||
| 80 | 'rom_id' => 'romId', | ||
| 81 | ); | ||
| 82 | |||
| 83 | %FUNCS = ( | ||
| 84 | |||
| 85 | # CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolTable | ||
| 86 | 'cisco_mem_free' => 'ciscoMemoryPoolFree', | ||
| 87 | 'cisco_mem_used' => 'ciscoMemoryPoolUsed', | ||
| 88 | |||
| 89 | # CISCO-FLASH-MIB::ciscoFlashDeviceTable | ||
| 90 | 'cisco_flash_size' => 'ciscoFlashDeviceSize', | ||
| 91 | |||
| 92 | # CISCO-IMAGE-MIB | ||
| 93 | 'ci_images' => 'ciscoImageString', | ||
| 94 | ); | ||
| 95 | |||
| 96 | %MUNGE = (); | ||
| 97 | |||
| 98 | sub vendor { | ||
| 99 | return 'cisco'; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub os { | ||
| 103 | my $l2 = shift; | ||
| 104 | my $descr = $l2->description() || ''; | ||
| 105 | |||
| 106 | # order here matters - there are Catalysts that run IOS and have catalyst | ||
| 107 | # in their description field, as well as Catalysts that run IOS-XE. | ||
| 108 | return 'ios-xe' if ( $descr =~ /Denali/ ); | ||
| 109 | return 'ios-xe' if ( $descr =~ /Fuji/ ); | ||
| 110 | return 'ios-xe' if ( $descr =~ /Everest/ ); | ||
| 111 | return 'ios-xe' if ( $descr =~ /Gibraltar/ ); | ||
| 112 | return 'ios-xe' if ( $descr =~ /Amsterdam/ ); | ||
| 113 | return 'ios-xe' if ( $descr =~ /Bengaluru/ ); | ||
| 114 | return 'ios-xe' if ( $descr =~ /Cupertino/ ); | ||
| 115 | return 'ios-xe' if ( $descr =~ /Dublin/ ); | ||
| 116 | return 'ios-xe' if ( $descr =~ /IOSXE/ ); | ||
| 117 | return 'ios-xe' if ( $descr =~ /IOS-XE/ ); | ||
| 118 | return 'ios-xr' if ( $descr =~ /IOS XR/ ); | ||
| 119 | return 'ios' if ( $descr =~ /IOS/ ); | ||
| 120 | return 'catalyst' if ( $descr =~ /catalyst/i ); | ||
| 121 | return 'css' if ( $descr =~ /Content Switch SW/ ); | ||
| 122 | return 'css-sca' if ( $descr =~ /Cisco Systems Inc CSS-SCA-/ ); | ||
| 123 | return 'pix' if ( $descr =~ /Cisco PIX Security Appliance/ ); | ||
| 124 | return 'asa' if ( $descr =~ /Cisco Adaptive Security Appliance/ ); | ||
| 125 | return 'san-os' if ( $descr =~ /Cisco SAN-OS/ ); | ||
| 126 | |||
| 127 | if ( $descr =~ /Application Control Engine Service Module/ ) { | ||
| 128 | # Only the admin context implements the entity MIB | ||
| 129 | return 'ace-admin' if defined $l2->ent_physical_software_rev(); | ||
| 130 | return 'ace-context'; | ||
| 131 | } | ||
| 132 | |||
| 133 | # Pre-version 3 FWSMs | ||
| 134 | return 'fwsm' if ( $descr =~ /Cisco Secure FWSM Firewall/ ); | ||
| 135 | |||
| 136 | # Version 3+ FWSMs (currently untested against version 4) | ||
| 137 | if ( $descr =~ /Firewall Services Module/ ) { | ||
| 138 | |||
| 139 | my $model = $l2->model(); | ||
| 140 | |||
| 141 | if ( defined $model && $model eq "WsSvcFwm1sc" ) { | ||
| 142 | # Only the admin context implements the entity MIB | ||
| 143 | return 'fwsm-admin' if defined $l2->ent_physical_software_rev(); | ||
| 144 | return 'fwsm-context'; | ||
| 145 | } | ||
| 146 | |||
| 147 | # Non context mode FWSM | ||
| 148 | return 'fwsm'; | ||
| 149 | } | ||
| 150 | |||
| 151 | return; | ||
| 152 | } | ||
| 153 | |||
| 154 | sub os_ver { | ||
| 155 | my $l2 = shift; | ||
| 156 | my $os = $l2->os(); | ||
| 157 | my $descr = $l2->description(); | ||
| 158 | |||
| 159 | # Older Catalysts | ||
| 160 | if ( defined $os | ||
| 161 | and $os eq 'catalyst' | ||
| 162 | and defined $descr | ||
| 163 | and $descr =~ m/V(\d{1}\.\d{2}\.\d{2})/ ) | ||
| 164 | { | ||
| 165 | return $1; | ||
| 166 | } | ||
| 167 | |||
| 168 | if ( defined $os | ||
| 169 | and $os eq 'css' | ||
| 170 | and defined $descr | ||
| 171 | and $descr =~ m/Content Switch SW Version ([0-9\.\(\)]+) with SNMPv1\/v2c Agent/ ) | ||
| 172 | { | ||
| 173 | return $1; | ||
| 174 | } | ||
| 175 | |||
| 176 | if ( defined $os | ||
| 177 | and $os eq 'css-sca' | ||
| 178 | and defined $descr | ||
| 179 | and $descr =~ m/Cisco Systems Inc CSS-SCA-2FE-K9, ([0-9\.\(\)]+) Release / ) | ||
| 180 | { | ||
| 181 | return $1; | ||
| 182 | } | ||
| 183 | |||
| 184 | if ( defined $os | ||
| 185 | and $os eq 'pix' | ||
| 186 | and defined $descr | ||
| 187 | and $descr =~ m/Cisco PIX Security Appliance Version ([0-9\.\(\)]+)/ ) | ||
| 188 | { | ||
| 189 | return $1; | ||
| 190 | } | ||
| 191 | |||
| 192 | if ( defined $os | ||
| 193 | and $os eq 'asa' | ||
| 194 | and defined $descr | ||
| 195 | and $descr =~ m/Cisco Adaptive Security Appliance Version ([0-9\.\(\)]+)/ ) | ||
| 196 | { | ||
| 197 | return $1; | ||
| 198 | } | ||
| 199 | |||
| 200 | if ( defined $os | ||
| 201 | and $os =~ /^ace/ ) | ||
| 202 | { | ||
| 203 | return $l2->ent_physical_software_rev(); | ||
| 204 | } | ||
| 205 | |||
| 206 | if ( defined $os | ||
| 207 | and $os =~ /^fwsm/ | ||
| 208 | and defined $descr | ||
| 209 | and $descr =~ m/Version (\d+\.\d+(\(\d+\)){0,1})/ ) | ||
| 210 | { | ||
| 211 | return $1; | ||
| 212 | } | ||
| 213 | |||
| 214 | if ( defined $os | ||
| 215 | and $os eq 'ios-xr' | ||
| 216 | and defined $descr | ||
| 217 | and $descr =~ m/Version (\d+[\.\d]+)/ ) | ||
| 218 | { | ||
| 219 | return $1; | ||
| 220 | } | ||
| 221 | |||
| 222 | # Newer Catalysts and IOS/IOS-XE devices | ||
| 223 | if ( defined $descr | ||
| 224 | and $descr =~ m/Version (\d+\.\d+(?:\([^)]+\)|\.\d+)[^,\s]*)(?:,|\s)+/ ) | ||
| 225 | { | ||
| 226 | return $1; | ||
| 227 | } | ||
| 228 | |||
| 229 | # Generic fallback: try to determine running image from CISCO-IMAGE-MIB | ||
| 230 | my $image_info = $l2->ciscoImageString() || {}; | ||
| 231 | foreach my $row (keys %$image_info) { | ||
| 232 | my $info_string = $image_info->{$row}; | ||
| 233 | if ($info_string =~ /CW_VERSION\$([^\$]+)\$/) { | ||
| 234 | return $1; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | return; | ||
| 239 | } | ||
| 240 | |||
| 241 | sub os_bin { | ||
| 242 | my $self = shift; | ||
| 243 | my $rom_id = $self->rom_id(); | ||
| 244 | if ($rom_id =~ m/Version ([^,]+),/) { | ||
| 245 | return $1; | ||
| 246 | } | ||
| 247 | return; | ||
| 248 | } | ||
| 249 | |||
| 250 | sub cpu { | ||
| 251 | my $self = shift; | ||
| 252 | my $ios_cpu = $self->ios_cpu(); | ||
| 253 | return $ios_cpu if defined $ios_cpu; | ||
| 254 | my $cat_cpu = $self->cat_cpu(); | ||
| 255 | return $cat_cpu; | ||
| 256 | } | ||
| 257 | |||
| 258 | sub cpu_1min { | ||
| 259 | my $self = shift; | ||
| 260 | my $ios_cpu_1min = $self->ios_cpu_1min(); | ||
| 261 | return $ios_cpu_1min if defined $ios_cpu_1min; | ||
| 262 | my $cat_cpu_1min = $self->cat_cpu_1min(); | ||
| 263 | return $cat_cpu_1min; | ||
| 264 | } | ||
| 265 | |||
| 266 | sub cpu_5min { | ||
| 267 | my $self = shift; | ||
| 268 | my $ios_cpu_5min = $self->ios_cpu_5min(); | ||
| 269 | return $ios_cpu_5min if defined $ios_cpu_5min; | ||
| 270 | my $cat_cpu_5min = $self->cat_cpu_5min(); | ||
| 271 | return $cat_cpu_5min; | ||
| 272 | } | ||
| 273 | |||
| 274 | sub mem_free { | ||
| 275 | my $self = shift; | ||
| 276 | |||
| 277 | my $mem_free; | ||
| 278 | |||
| 279 | my $cisco_mem_free = $self->cisco_mem_free() || {}; | ||
| 280 | |||
| 281 | foreach my $mem_free_val ( values %$cisco_mem_free ) { | ||
| 282 | $mem_free += $mem_free_val; | ||
| 283 | } | ||
| 284 | |||
| 285 | return $mem_free; | ||
| 286 | } | ||
| 287 | |||
| 288 | sub mem_used { | ||
| 289 | my $self = shift; | ||
| 290 | |||
| 291 | my $mem_used; | ||
| 292 | |||
| 293 | my $cisco_mem_used = $self->cisco_mem_used() || {}; | ||
| 294 | |||
| 295 | foreach my $mem_used_val ( values %$cisco_mem_used ) { | ||
| 296 | $mem_used += $mem_used_val; | ||
| 297 | } | ||
| 298 | |||
| 299 | return $mem_used; | ||
| 300 | } | ||
| 301 | |||
| 302 | sub mem_total { | ||
| 303 | my $self = shift; | ||
| 304 | |||
| 305 | my $mem_total; | ||
| 306 | |||
| 307 | my $cisco_mem_free = $self->cisco_mem_free() || {}; | ||
| 308 | my $cisco_mem_used = $self->cisco_mem_used() || {}; | ||
| 309 | |||
| 310 | foreach my $mem_entry ( keys %$cisco_mem_free ) { | ||
| 311 | my $mem_free = $cisco_mem_free->{$mem_entry} || 0; | ||
| 312 | my $mem_used = $cisco_mem_used->{$mem_entry} || 0; | ||
| 313 | $mem_total += ( $mem_free + $mem_used ); | ||
| 314 | } | ||
| 315 | return $mem_total; | ||
| 316 | } | ||
| 317 | |||
| 318 | sub flashmem_total { | ||
| 319 | my $self = shift; | ||
| 320 | |||
| 321 | my $flashmem_total; | ||
| 322 | |||
| 323 | my $flash_sizes = $self->cisco_flash_size; | ||
| 324 | |||
| 325 | foreach my $flash_index ( keys %$flash_sizes ) { | ||
| 326 | $flashmem_total += $flash_sizes->{$flash_index}; | ||
| 327 | } | ||
| 328 | |||
| 329 | return $flashmem_total; | ||
| 330 | } | ||
| 331 | |||
| 332 | 1; | ||
| 333 | __END__ |