#!/usr/local/bin/perl # nagios: +epn =pod =head1 NAME check_net_snmp_mem.pl - Check memory utilization on a Net-SNMP enabled device. =head1 SYNOPSIS Check memory used, free, shared, buffered, and cached. Specify the type of threshold you will be checking by passing one of '%', 'K', 'M', or 'G' to the script using the --convert-to options. If you do not explicitly choose a conversion type, '%' will be assumed. Pass in one or more thresholds, separated by ':' to the -w and -c switches to specify warning and critical thresholds e.g. check_net_snmp_mem.pl [ .. options .. ] --convert-to '%' -w 'free,lt,1:system,gt,30' -c 'used,gt,99' Where lt == <, gt == >, lte == <=, and gte == >= The plugin will output a list of all thresholds that have been breached and all that are ok; the most critical status becomes the return status of the plugin. For perfdata the plugin will output all metrics checked by the script. Output is in the conversion type you specified for all perfdata metrics. e.g. check_net_snmp_mem.pl [ .. options .. ] --warning 'free,lt,5' --critical 'free,lt,1' NET-SNMP-MEM OK - buffered 4.36%, cached 1.47%, free 94.17%, shared 0.00% | 'buffered'=4.36%;0;0 'cached'=1.47%;0;0 'free'=94.17%;5;2 'shared'=0.00%;0;0 =cut sub check_net_snmp_mem { use strict; use FindBin; use lib "$FindBin::Bin/lib"; use Nagios::Plugin::Threshold; use Nagios::Plugin::SNMP; use Nenm::Utils; my $USAGE = <,number:metric[%|k|m|g]?,,number'] \\ --critical 'metric[%|k|m|g]?,,number:metric[%|k|m|g]?,,number' \\ [--convert-to \%|K|G|M] EOF my $LABEL = 'NET-SNMP-MEM'; my $plugin = Nagios::Plugin::SNMP->new( 'shortname' => $LABEL, 'usage' => $USAGE ); $plugin->add_arg( 'spec' => 'convert-to|T=s', 'required' => 0, 'help' => "-T, --convert-to\n" . " Specify how to convert returned agent memory metrics\n" . " (%, b, K, M, or G). Values from agent will be " . " converted\n" . " to this type, threshold values will be considered to\n" . " be of this type, and perfdata values will use this \n" . " type. Default conversion type is \% if option is \n" . " not present", 'default' => '%' ); $plugin->getopts; $Nenm::Utils::DEBUG = $plugin->opts->get('snmp-debug'); my %mem = ( 'free' => {qw(oid .1.3.6.1.4.1.2021.4.11.0 raw 0 value 0)}, 'shared' => {qw(oid .1.3.6.1.4.1.2021.4.13.0 raw 0 value 0)}, 'buffered' => {qw(oid .1.3.6.1.4.1.2021.4.14.0 raw 0 value 0)}, 'cached' => {qw(oid .1.3.6.1.4.1.2021.4.15.0 raw 0 value 0)} ); my ($wthr, $werrs)= ([], []); if (defined $plugin->opts->warning) { ($wthr, $werrs) = Nenm::Utils::parse_multi_threshold($plugin->opts->warning, \%mem); } if (scalar(@$werrs) > 0) { $plugin->nagios_die("Errors found in warning thresholds specified:" . "\n " . join("\n ", @$werrs)); } my ($cthr, $cerrs) = Nenm::Utils::parse_multi_threshold( $plugin->opts->critical, \%mem); if (scalar(@$cerrs) > 0) { $plugin->nagios_die("Errors found in critical thresholds specified:" . "\n " . join("\n ", @$cerrs)); } my @oids; for my $metric (keys %mem) { push(@oids, $mem{$metric}->{'oid'}); } my $snmp_results = $plugin->get(@oids); $plugin->close(); $mem{'free'}->{'raw'} = $snmp_results->{$mem{'free'}->{'oid'}}; $mem{'shared'}->{'raw'} = $snmp_results->{$mem{'shared'}->{'oid'}}; $mem{'buffered'}->{'raw'} = $snmp_results->{$mem{'buffered'}->{'oid'}}; $mem{'cached'}->{'raw'} = $snmp_results->{$mem{'cached'}->{'oid'}}; my $CONVERT_TO = $plugin->opts->get('convert-to'); Nenm::Utils::convert_to($CONVERT_TO, \%mem); my $results = Nenm::Utils::check_multi_thresholds(\%mem, $wthr, $cthr, $CONVERT_TO); return Nenm::Utils::output_multi_results($LABEL, $results); } exit check_net_snmp_mem();