perltidy
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
# SNMP::Info::CiscoStats
|
||||
# $Id$
|
||||
#
|
||||
# Changes since Version 0.7 Copyright (c) 2008 Max Baker
|
||||
# All rights reserved.
|
||||
# Changes since Version 0.7 Copyright (c) 2008 Max Baker
|
||||
# All rights reserved.
|
||||
#
|
||||
# Copyright (c) 2003 Regents of the University of California
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the University of California, Santa Cruz nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# * Neither the name of the University of California, Santa Cruz nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
@@ -37,59 +37,65 @@ use strict;
|
||||
use Exporter;
|
||||
use SNMP::Info;
|
||||
|
||||
@SNMP::Info::CiscoStats::ISA = qw/SNMP::Info Exporter/;
|
||||
@SNMP::Info::CiscoStats::ISA = qw/SNMP::Info Exporter/;
|
||||
@SNMP::Info::CiscoStats::EXPORT_OK = qw//;
|
||||
|
||||
use vars qw/$VERSION %MIBS %FUNCS %GLOBALS %MUNGE/;
|
||||
|
||||
$VERSION = '1.09';
|
||||
|
||||
%MIBS = (
|
||||
'SNMPv2-MIB' => 'sysDescr',
|
||||
'CISCO-PROCESS-MIB' => 'cpmCPUTotal5sec',
|
||||
'CISCO-MEMORY-POOL-MIB' => 'ciscoMemoryPoolUsed',
|
||||
'OLD-CISCO-SYSTEM-MIB' => 'writeMem',
|
||||
'CISCO-PRODUCTS-MIB' => 'sysName',
|
||||
# some older catalysts live here
|
||||
'CISCO-STACK-MIB' => 'wsc1900sysID',
|
||||
'CISCO-ENTITY-VENDORTYPE-OID-MIB' => 'cevChassis',
|
||||
'CISCO-FLASH-MIB' => 'ciscoFlashDeviceSize',
|
||||
);
|
||||
%MIBS = (
|
||||
'SNMPv2-MIB' => 'sysDescr',
|
||||
'CISCO-PROCESS-MIB' => 'cpmCPUTotal5sec',
|
||||
'CISCO-MEMORY-POOL-MIB' => 'ciscoMemoryPoolUsed',
|
||||
'OLD-CISCO-SYSTEM-MIB' => 'writeMem',
|
||||
'CISCO-PRODUCTS-MIB' => 'sysName',
|
||||
|
||||
# some older catalysts live here
|
||||
'CISCO-STACK-MIB' => 'wsc1900sysID',
|
||||
'CISCO-ENTITY-VENDORTYPE-OID-MIB' => 'cevChassis',
|
||||
'CISCO-FLASH-MIB' => 'ciscoFlashDeviceSize',
|
||||
);
|
||||
|
||||
%GLOBALS = (
|
||||
'description' => 'sysDescr',
|
||||
# We will use the numeric OID's so that we don't require people
|
||||
# to install v1 MIBs, which can conflict.
|
||||
# OLD-CISCO-CPU-MIB:avgBusyPer
|
||||
'ios_cpu' => '1.3.6.1.4.1.9.2.1.56.0',
|
||||
'ios_cpu_1min' => '1.3.6.1.4.1.9.2.1.57.0',
|
||||
'ios_cpu_5min' => '1.3.6.1.4.1.9.2.1.58.0',
|
||||
# CISCO-PROCESS-MIB
|
||||
'cat_cpu' => 'cpmCPUTotal5sec.9',
|
||||
'cat_cpu_1min' => 'cpmCPUTotal1min.9',
|
||||
'cat_cpu_5min' => 'cpmCPUTotal5min.9',
|
||||
# OLD-CISCO-SYSTEM-MIB
|
||||
'write_mem' => 'writeMem',
|
||||
);
|
||||
'description' => 'sysDescr',
|
||||
|
||||
%FUNCS = (
|
||||
# CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolTable
|
||||
'cisco_mem_free' => 'ciscoMemoryPoolFree',
|
||||
'cisco_mem_used' => 'ciscoMemoryPoolUsed',
|
||||
# CISCO-FLASH-MIB::ciscoFlashDeviceTable
|
||||
'cisco_flash_size' => 'ciscoFlashDeviceSize',
|
||||
);
|
||||
# We will use the numeric OID's so that we don't require people
|
||||
# to install v1 MIBs, which can conflict.
|
||||
# OLD-CISCO-CPU-MIB:avgBusyPer
|
||||
'ios_cpu' => '1.3.6.1.4.1.9.2.1.56.0',
|
||||
'ios_cpu_1min' => '1.3.6.1.4.1.9.2.1.57.0',
|
||||
'ios_cpu_5min' => '1.3.6.1.4.1.9.2.1.58.0',
|
||||
|
||||
%MUNGE = (
|
||||
);
|
||||
# CISCO-PROCESS-MIB
|
||||
'cat_cpu' => 'cpmCPUTotal5sec.9',
|
||||
'cat_cpu_1min' => 'cpmCPUTotal1min.9',
|
||||
'cat_cpu_5min' => 'cpmCPUTotal5min.9',
|
||||
|
||||
# OLD-CISCO-SYSTEM-MIB
|
||||
'write_mem' => 'writeMem',
|
||||
);
|
||||
|
||||
%FUNCS = (
|
||||
|
||||
# CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolTable
|
||||
'cisco_mem_free' => 'ciscoMemoryPoolFree',
|
||||
'cisco_mem_used' => 'ciscoMemoryPoolUsed',
|
||||
|
||||
# CISCO-FLASH-MIB::ciscoFlashDeviceTable
|
||||
'cisco_flash_size' => 'ciscoFlashDeviceSize',
|
||||
);
|
||||
|
||||
%MUNGE = ();
|
||||
|
||||
sub os {
|
||||
my $l2 = shift;
|
||||
my $descr = $l2->description() || '';
|
||||
|
||||
# order here matters - there are Catalysts that run IOS and have catalyst in their description field.
|
||||
return 'ios' if ($descr =~ /IOS/);
|
||||
return 'catalyst' if ($descr =~ /catalyst/i);
|
||||
# order here matters - there are Catalysts that run IOS and have catalyst
|
||||
# in their description field.
|
||||
return 'ios' if ( $descr =~ /IOS/ );
|
||||
return 'catalyst' if ( $descr =~ /catalyst/i );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,21 +103,27 @@ sub os_ver {
|
||||
my $l2 = shift;
|
||||
my $os = $l2->os();
|
||||
my $descr = $l2->description();
|
||||
|
||||
|
||||
# Older Catalysts
|
||||
if (defined $os and $os eq 'catalyst' and defined $descr and $descr =~ m/V(\d{1}\.\d{2}\.\d{2})/){
|
||||
if ( defined $os
|
||||
and $os eq 'catalyst'
|
||||
and defined $descr
|
||||
and $descr =~ m/V(\d{1}\.\d{2}\.\d{2})/ )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
|
||||
|
||||
# Newer Catalysts and IOS devices
|
||||
if (defined $descr and $descr =~ m/Version (\d+\.\d+\([^)]+\)[^,\s]*)(,|\s)+/ ){
|
||||
if ( defined $descr
|
||||
and $descr =~ m/Version (\d+\.\d+\([^)]+\)[^,\s]*)(,|\s)+/ )
|
||||
{
|
||||
return $1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub cpu {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my $ios_cpu = $self->ios_cpu();
|
||||
return $ios_cpu if defined $ios_cpu;
|
||||
my $cat_cpu = $self->cat_cpu();
|
||||
@@ -119,7 +131,7 @@ sub cpu {
|
||||
}
|
||||
|
||||
sub cpu_1min {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my $ios_cpu_1min = $self->ios_cpu_1min();
|
||||
return $ios_cpu_1min if defined $ios_cpu_1min;
|
||||
my $cat_cpu_1min = $self->cat_cpu_1min();
|
||||
@@ -127,7 +139,7 @@ sub cpu_1min {
|
||||
}
|
||||
|
||||
sub cpu_5min {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my $ios_cpu_5min = $self->ios_cpu_5min();
|
||||
return $ios_cpu_5min if defined $ios_cpu_5min;
|
||||
my $cat_cpu_5min = $self->cat_cpu_5min();
|
||||
@@ -141,7 +153,7 @@ sub mem_free {
|
||||
|
||||
my $cisco_mem_free = $self->cisco_mem_free() || {};
|
||||
|
||||
foreach my $mem_free_val (values %$cisco_mem_free) {
|
||||
foreach my $mem_free_val ( values %$cisco_mem_free ) {
|
||||
$mem_free += $mem_free_val;
|
||||
}
|
||||
|
||||
@@ -154,8 +166,8 @@ sub mem_used {
|
||||
my $mem_used;
|
||||
|
||||
my $cisco_mem_used = $self->cisco_mem_used() || {};
|
||||
|
||||
foreach my $mem_used_val (values %$cisco_mem_used) {
|
||||
|
||||
foreach my $mem_used_val ( values %$cisco_mem_used ) {
|
||||
$mem_used += $mem_used_val;
|
||||
}
|
||||
|
||||
@@ -170,10 +182,10 @@ sub mem_total {
|
||||
my $cisco_mem_free = $self->cisco_mem_free() || {};
|
||||
my $cisco_mem_used = $self->cisco_mem_used() || {};
|
||||
|
||||
foreach my $mem_entry (keys %$cisco_mem_free){
|
||||
foreach my $mem_entry ( keys %$cisco_mem_free ) {
|
||||
my $mem_free = $cisco_mem_free->{$mem_entry} || 0;
|
||||
my $mem_used = $cisco_mem_used->{$mem_entry} || 0;
|
||||
$mem_total += ($mem_free + $mem_used);
|
||||
$mem_total += ( $mem_free + $mem_used );
|
||||
}
|
||||
return $mem_total;
|
||||
}
|
||||
@@ -185,7 +197,7 @@ sub flashmem_total {
|
||||
|
||||
my $flash_sizes = $self->cisco_flash_size;
|
||||
|
||||
foreach my $flash_index (keys %$flash_sizes) {
|
||||
foreach my $flash_index ( keys %$flash_sizes ) {
|
||||
$flashmem_total += $flash_sizes->{$flash_index};
|
||||
}
|
||||
|
||||
@@ -197,7 +209,8 @@ __END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
SNMP::Info::CiscoStats - Perl5 Interface to CPU and Memory stats for Cisco Devices
|
||||
SNMP::Info::CiscoStats - Perl5 Interface to CPU and Memory stats for Cisco
|
||||
Devices
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
@@ -207,13 +220,13 @@ Max Baker
|
||||
|
||||
# Let SNMP::Info determine the correct subclass for you.
|
||||
my $ciscostats = new SNMP::Info(
|
||||
AutoSpecify => 1,
|
||||
Debug => 1,
|
||||
# These arguments are passed directly on to SNMP::Session
|
||||
DestHost => 'myswitch',
|
||||
Community => 'public',
|
||||
Version => 2
|
||||
)
|
||||
AutoSpecify => 1,
|
||||
Debug => 1,
|
||||
# These arguments are passed directly on to SNMP::Session
|
||||
DestHost => 'myswitch',
|
||||
Community => 'public',
|
||||
Version => 2
|
||||
)
|
||||
or die "Can't connect to DestHost.\n";
|
||||
|
||||
my $class = $ciscostats->class();
|
||||
@@ -221,8 +234,8 @@ Max Baker
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
SNMP::Info::CiscoStats is a subclass of SNMP::Info that provides cpu, memory, os and
|
||||
version information about Cisco Devices.
|
||||
SNMP::Info::CiscoStats is a subclass of SNMP::Info that provides cpu, memory,
|
||||
os and version information about Cisco Devices.
|
||||
|
||||
Use or create in a subclass of SNMP::Info. Do not use directly.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user