use Net::SNMP;
use Data::Dumper;
+############ basic plugin data & argument handling ############
my $np = Nagios::Plugin->new(
plugin => "check_mem_ucd_snmp",
version => "0.1",
# parse arguments
$np->getopts;
-# care for the unit parameter
+############ check & handle the unit parameter ############
my $unitstr;
my $unitdiv;
if (uc($np->opts->get("unit")) eq "KB")
$np->nagios_die("illegal unit requested");
}
-# sanity-check the snmp-version
+############ sanity-check the snmp-version ############
my $snmpversion=undef;
if ($np->opts->get("snmpv1"))
$snmpversion=2;
}
-# create the SNMP session
+############ create the SNMP session ############
my %snmpsessionparam = (
-hostname => $np->opts->get("hostname"),
-port => $np->opts->get("port"),
$np->nagios_die("Error opening SNMP session: $snmperror");
}
-# prepare & execute the snmp request
+############ prepare & execute the snmp request ############
my $oid_memTotalSwap = "1.3.6.1.4.1.2021.4.3.0";
my $oid_memAvailSwap = "1.3.6.1.4.1.2021.4.4.0";
my $oid_memTotalReal = "1.3.6.1.4.1.2021.4.5.0";
$session->close();
-# check if the essential oids are there
+############ check if the essential oids are there ############
foreach my $oid (@essential_oidlist)
{
if (!defined $result->{$oid} || $result->{$oid} eq "noSuchObject")
}
}
-# interpret the results: use only OIDs listed as essential here!
+############ interpret the results ############
+# use only OIDs listed as essential here!
my $realmem=$result->{$oid_memTotalReal};
my $realavail=$result->{$oid_memAvailReal}+$result->{$oid_memBuffer}+$result->{$oid_memCached};
my $swap=$result->{$oid_memTotalSwap};
my $swapused=$swap-$result->{$oid_memAvailSwap};
my $totalavail=$realavail+$result->{$oid_memAvailSwap};
+############ convert the results to the desired unit ############
my @resultvar=(\$realmem, \$realavail, \$swap, \$swapused, \$totalavail);
foreach my $varref (@resultvar)
{
$$varref/=$unitdiv;
}
-# check the thresholds: do this BEFORE the rounding
+############ check the thresholds ############
+# do this BEFORE the rounding
my @results = ();
push (@results, $np->check_threshold(
critical => $np->opts->get("realavail-critical")
));
-# rounding: show decimals only if value less than limit
+############ rounding ############
+# show decimals only if value less than limit
foreach my $varref (@resultvar)
{
if ($$varref < 20)
}
}
-# output the performance data
+############ output the performance data ############
$np->add_perfdata(
label => "total_avail",
value => $totalavail,
max => $swap
);
-# compose message
+############ compose message ############
$np->nagios_exit(
$np->max_state(@results),
"Real av: $realavail $unitstr, Total av: $totalavail $unitstr, Swapped: $swapused $unitstr",