#!/usr/local/bin/perl # nagios: +epn =pod =head1 NAME check_net_snmp_swap.pl - Check the swap space % in use =head1 SYNOPSIS Check the % swap space in used on a server, warning and critical thresholds are upper acceptable limits for swap space utilization. This plugin will output the percent swap space in use as perfdata. =cut sub check_net_snmp_swap { use strict; use FindBin; use lib "$FindBin::Bin/lib"; use Nagios::Plugin::SNMP; my $USAGE = <new( 'shortname' => $LABEL, 'usage' => $USAGE ); $plugin->getopts; $plugin->set_thresholds( 'warning' => $plugin->opts->warning, 'critical' => $plugin->opts->critical, ); use constant TOTAL => '.1.3.6.1.4.1.2021.4.3.0'; use constant AVAIL => '.1.3.6.1.4.1.2021.4.4.0'; my @oids = (TOTAL(), AVAIL()); my $results = $plugin->get(@oids); $plugin->close(); my @warning; my @critical; my @ok; my $total = $results->{TOTAL()}; my $avail = $results->{AVAIL()}; my $pct_used = 0; eval { $pct_used = sprintf("%5.2f", (($total - $avail) / $total) * 100); }; my $code = $plugin->check_threshold(check => $pct_used); my $msg; if ($code == CRITICAL) { $msg = "${pct_used}% > " . $plugin->opts->critical . "%"; } elsif ($code == WARNING) { $msg = "${pct_used}% > " . $plugin->opts->warning . "%"; } else { $msg = "${pct_used}% swap in use"; } $plugin->add_perfdata( 'label' => "'pct_used'", 'value' => $pct_used, 'uom' => "%", 'threshold' => $plugin->threshold ); $plugin->nagios_exit($code, $msg); } check_net_snmp_swap();