#!/usr/local/bin/perl # nagios: +epn =pod =head1 NAME check_net_snmp_load.pl - Check the load averages on a server =head1 SYNOPSIS Check the 1 minute, 5 minute, and 15 minute loads on a Net-SNMP device using SNMP. specify warning and critical thresholds as comma-separated lists in the format 1 minute : 5 minute : 15 minute e.g. check_net_snmp_load.pl [ .. options .. ] -w 20:15:5 40:30:10 The plugin will output a list of all thresholds that have been breached and all averages that are ok; the most critical status becomes the return status of the plugin. The script will also output perfdata, example: NET-SNMP-LA OK - 1min: 0.04, 5min: 0.03, 15min: 0.00 | '1min'=0.04;1;5 '5min'=0.03;5;10 '15min'=0.00;10;20 =cut sub check_net_snmp_la { use strict; use FindBin; use lib "$FindBin::Bin/lib"; use Nagios::Plugin::Threshold; use Nagios::Plugin::SNMP; my $USAGE = <new( 'shortname' => $LABEL, 'usage' => $USAGE ); $plugin->getopts; use constant LOAD1 => '.1.3.6.1.4.1.2021.10.1.3.1'; use constant LOAD5 => '.1.3.6.1.4.1.2021.10.1.3.2'; use constant LOAD15 => '.1.3.6.1.4.1.2021.10.1.3.3'; my @oids = (LOAD1, LOAD5, LOAD15); my $results = $plugin->get(@oids); $plugin->close(); my %la = ( '1min' => $results->{LOAD1()}, '5min' => $results->{LOAD5()}, '15min' => $results->{LOAD15()} ); my $index = 0; my @warning; my @critical; my @ok; my @wthresh = split(':', $plugin->opts->warning); my @cthresh = split(':', $plugin->opts->critical); my $i = 0; for my $avg (qw(1min 5min 15min)) { my %t; $t{'warning'} = $wthresh[$i] if defined($wthresh[$i]); $t{'critical'} = $cthresh[$i] if defined($cthresh[$i]); if ((defined $t{'critical'}) && ($la{$avg} > $t{'critical'})) { push(@critical, "${avg}: $la{$avg} > $cthresh[$i]"); } elsif ((defined $t{'warning'}) && ($la{$avg} > $t{'warning'})) { push(@warning, "${avg}: $la{$avg} > $wthresh[$i]"); } else { push(@ok, "${avg}: $la{$avg}"); } my $threshold = Nagios::Plugin::Threshold->set_thresholds(%t); $plugin->add_perfdata( 'label' => "'${avg}'", 'value' => $la{$avg}, 'uom' => "", 'threshold' => $threshold ); $i++; } my $level = OK; print "$LABEL "; if (scalar(@critical)) { print "CRITICAL - " . join(', ', @critical) . ' '; $level = CRITICAL; } if (scalar(@warning)) { print "WARNING - " . join(', ', @warning) . ' '; $level = WARNING unless $level == CRITICAL; } if (scalar(@ok)) { print "OK - " . join(', ', @ok) . ' '; } print ' | ' . $plugin->all_perfoutput . "\n"; return $level; } exit check_net_snmp_la();