improve documentation
authorGerd v. Egidy <gerd.von.egidy@intra2net.com>
Wed, 11 Nov 2009 21:13:20 +0000 (22:13 +0100)
committerGerd v. Egidy <gerd.von.egidy@intra2net.com>
Wed, 11 Nov 2009 21:13:20 +0000 (22:13 +0100)
check_mem_ucd_snmp/check_mem_ucd_snmp

index ac0be1c..fe49c53 100644 (file)
@@ -23,6 +23,7 @@ use Nagios::Plugin;
 use Net::SNMP;
 use Data::Dumper;
 
+############ basic plugin data & argument handling ############
 my $np = Nagios::Plugin->new(
             plugin  => "check_mem_ucd_snmp",
             version => "0.1",
@@ -147,7 +148,7 @@ $np->add_arg(
 # 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")
@@ -170,7 +171,7 @@ else
     $np->nagios_die("illegal unit requested");
 }
 
-# sanity-check the snmp-version
+############ sanity-check the snmp-version ############
 my $snmpversion=undef;
 
 if ($np->opts->get("snmpv1"))
@@ -205,7 +206,7 @@ if (not defined $snmpversion)
     $snmpversion=2;
 }
 
-# create the SNMP session
+############ create the SNMP session ############
 my %snmpsessionparam = (
                         -hostname   => $np->opts->get("hostname"),
                         -port       => $np->opts->get("port"),
@@ -254,7 +255,7 @@ if (!defined $session)
     $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";
@@ -288,7 +289,7 @@ if (!defined $result)
 
 $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")
@@ -297,20 +298,23 @@ foreach my $oid (@essential_oidlist)
     }
 }
 
-# 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(
@@ -324,7 +328,8 @@ 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)
@@ -337,7 +342,7 @@ foreach my $varref (@resultvar)
     }
 }
 
-# output the performance data
+############ output the performance data ############
 $np->add_perfdata(
         label     => "total_avail",
         value     => $totalavail,
@@ -364,7 +369,7 @@ $np->add_perfdata(
         max       => $swap
      );
 
-# compose message
+############ compose message ############
 $np->nagios_exit(
         $np->max_state(@results),
         "Real av: $realavail $unitstr, Total av: $totalavail $unitstr, Swapped: $swapused $unitstr",