#!/usr/local/bin/perl # nagios: +epn =pod =head1 NAME check_snmp_cisco_mem_pool.pl - Check memory pool utilization on a Cisco router or switch =head1 SYNOPSIS Check memory pool utilization on a Cisco device. This script will check each memory pool available on a Cisco switch or router and alert if the % memory utilized is greater than the warning and critical thresholds passed into the script. Perfdata will be output for each pool found; the metrics will be prefixed with the name of the pool as reported by the Cisco device. =cut sub check_snmp_cisco_mem_pool { use strict; use FindBin; use lib "$FindBin::Bin/lib"; use Nagios::Plugin::SNMP; use Nenm::Utils; my $USAGE = <new( 'shortname' => $LABEL, 'usage' => $USAGE ); $plugin->getopts; $Nenm::Utils::DEBUG = $plugin->opts->get('snmp-debug'); my $WARN = $plugin->opts->get('warning'); $plugin->nagios_die("Missing warning threshold!") unless $WARN; my $CRIT = $plugin->opts->get('critical'); $plugin->nagios_die("Missing critical threshold!") unless $CRIT; my %oids = qw( .1.3.6.1.4.1.9.9.48.1.1.1.2 ciscoMemoryPoolName .1.3.6.1.4.1.9.9.48.1.1.1.5 ciscoMemoryPoolUsed .1.3.6.1.4.1.9.9.48.1.1.1.6 ciscoMemoryPoolFree ); my %mem; # Build our memory table, indexed by pool index, from # our metric tables. for my $oid (sort keys %oids) { Nenm::Utils::debug("Walking $oid"); my $results = $plugin->walk($oid); for my $key (keys %{$results->{$oid}}) { my ($oid, $idx) = ($key =~ m/^(.+)\.(\d+)$/); Nenm::Utils::debug("Received $oid, $idx"); $mem{$idx} = {} unless exists $mem{$idx}; my $value = $results->{$oid}->{$key}; $mem{$idx}->{$oids{$oid}} = $value; Nenm::Utils::debug("Pool index $idx - $oids{$oid} - $value"); } } # How calculate % utilization based on free and used memory for # each pool and check for threshold violations. my @critical; my @warn; my @ok; for my $pool (keys %mem) { my $name = $mem{$pool}->{'ciscoMemoryPoolName'}; my $free = $mem{$pool}->{'ciscoMemoryPoolFree'}; my $used = $mem{$pool}->{'ciscoMemoryPoolUsed'}; my $util = sprintf("%.2f", ($used / ($used + $free)) * 100); $mem{$pool}->{'util'} = $util; Nenm::Utils::debug("$name - $util\% memory utilization"); if ($util > $CRIT) { push(@critical, "$name ($util\% > $CRIT\%)"); } elsif ($util > $WARN) { push(@warn, "$name ($util\% > $WARN\%)"); } else { push(@ok, "$name $util\%"); } } my $level = OK; my $output = "$LABEL "; if (scalar(@critical) > 0) { $output .= 'CRITICAL - ' . join(', ', @critical) . ' '; $level = CRITICAL; } if (scalar(@warn) > 0) { $output .= 'WARN - ' . join(', ', @warn) . ' '; $level = WARNING unless $level == CRITICAL; } if (scalar(@ok) > 0) { $output .= 'OK - ' . join(', ', @ok); } $output .= make_perfdata(\%mem, $WARN, $CRIT); print "$output\n"; return $level; sub make_perfdata { my $mem_ref = shift; my $warn = shift; my $critical = shift; my $perfdata = ' | '; for my $pool (sort keys %$mem_ref) { my $name = lc($mem_ref->{$pool}->{'ciscoMemoryPoolName'}); my $util = $mem_ref->{$pool}->{'util'}; $perfdata .= "'$name'=$util\%;$warn;$critical;0;100 "; } return $perfdata; } } exit check_snmp_cisco_mem_pool();