From 5458527cf4f949d6f3206671d77f78fd422808aa Mon Sep 17 00:00:00 2001
From: Frederik Lindenaar <frederik@lindenaar.nl>
Date: Sun, 2 Aug 2015 17:47:31 +0200
Subject: [PATCH] updated directory structure, move plugins into a separate directory

---
 README.md            |   4 ++--
 check_memory         | 164 --------------------------------------------------------------------------------------------------------------------------------------------------------------------
 plugins/check_memory | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 166 deletions(-)
 delete mode 100755 check_memory
 create mode 100755 plugins/check_memory

diff --git a/README.md b/README.md
index 721391f..db6eec7 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,8 @@ Copyright (c) 2015 Frederik Lindenaar. free for distribution under the GNU
 License, see [below](#license)
 
 
-check_memory
-------------
+plugins/check_memory
+--------------------
 nagios check script to monitor the memory on Linux systems. Due to changes in
 the output of procps v3.3 (the changelog refers to it as modernizing it), it's
 output changed and breaks the the check_memory script as shipped with many linux
diff --git a/check_memory b/check_memory
deleted file mode 100755
index 7055af6..0000000
--- a/check_memory
+++ /dev/null
@@ -1,164 +0,0 @@
-#!/usr/bin/perl
-#
-# check_memory  -  Check free(1) data against given tresholds
-#
-# Copyright (C) 2007 Thomas Guyot-Sionnest <tguyot@gmail.com>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-
-# patched by JFL on July 26th 2015 to work with new Linux free(1) output. Latest
-# version/issue tracker at: https://gitlab.lindenaar.net/scripts/nagios-plugins
-
-use strict;
-use warnings;
-use vars qw($PROGNAME $VERSION $FREECMD $UNIT);
-use Nagios::Plugin;
-
-$PROGNAME = "check_memory";
-$VERSION = '1.0.1';
-$FREECMD = '/usr/bin/free';
-$UNIT = 'M';
-
-my $np = Nagios::Plugin->new(
-  usage => "Usage: %s [ -w <warning_threshold> ] [ -c <critical_threshold> ]\n"
-    . '   [ -u <unit> ]',
-  version => $VERSION,
-  plugin  => $PROGNAME,
-  blurb => 'Check free(1) data against given tresholds',
-  timeout => 30,
-);
-
-$np->add_arg(
-  spec => 'warning|w=s',
-  help => "-w, --warning=THRESHOLD[%]\n"
-    . "   Warning threshold (in bytes or percent) for free memory. See\n"
-    . "   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n"
-    . "   for the threshold format. Alternatively this can be defined as a percentage\n"
-    . '   of minimum free memory (warning and critical must be in the same format).',
-  required => 0,
-);
-
-$np->add_arg(
-  spec => 'critical|c=s',
-  help => "-c, --critical=THRESHOLD[%]\n"
-    . "   Critical threshold (in bytes or percent) for free memory. See\n"
-    . "   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n"
-    . "   for the threshold format. Alternatively this can be defined as a percentage\n"
-    . '   of minimum free memory (warning and critical must be in the same format).',
-  required => 0,
-);
-
-$np->add_arg(
-  spec => 'unit|u=s',
-  help => "-u, --unit=UNIT\n"
-    . "   Unit to use for human-redeable output. Can be 'b', 'K' 'M' or 'G' for\n"
-    . "   bytes, KiB, MiB or GiB respectively (default: '$UNIT').",
-  default => $UNIT,
-  required => 0,
-);
-
-$np->getopts;
-
-# Assign, then check args
-
-my $multiple;
-my $unit = $np->opts->unit;
-if ($unit eq 'M') {
-  $multiple = 1024 * 1024;
-} elsif ( $unit eq 'K') {
-  $multiple = 1024;
-} elsif ( $unit eq 'b') {
-  $multiple = 1;
-} elsif ( $unit eq 'G') {
-  $multiple = 1024 * 1024 * 1024;
-} else {
-  $np->nagios_exit('UNKNOWN', "Unit must be one of 'b', 'K', 'M' or 'G', case-sensitive.");
-}
-my $verbose = $np->opts->verbose;
-
-# Would better fit later but doing it here validates thresholds
-my $warning = $np->opts->warning;
-my $critical = $np->opts->critical;
-$np->set_thresholds(
-    warning => ((defined($warning) && $warning !~ /^\d+%$/) ? $warning : undef),
-    critical => ((defined($critical) && $critical !~ /^\d+%$/) ? $critical : undef),
-);
-
-# Better safe than sorry
-alarm $np->opts->timeout;
-
-# We always get bytes, then calculate units ourselves
-warn("Running: '$FREECMD -b'\n") if ($verbose);
-open(RESULT, "$FREECMD -b |")
-  or $np->nagios_exit('CRITICAL', "Could not run $FREECMD");
-
-warn("Output from $FREECMD:\n") if ($verbose > 1);
-my ($used, $free);
-while (<RESULT>) {
-  warn("  $_") if ($verbose > 1);
-  if (m#^\-/\+\ buffers/cache:\s*(\d+)\s+(\d+)#) {
-	warn("  detected legacy format free output") if ($verbose > 1);
-	$used = $1;
-	$free = $2;
-	last;
-  } elsif (m#^Mem:\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$#) {
-	warn("  detected new format free output") if ($verbose > 1);
-	$used = $2;
-	$free = $3 + $5;
-	last;
-  }
-}
-
-close(RESULT);
-alarm(0);
-
-$np->nagios_exit('CRITICAL', "Unable to interpret $FREECMD output") if (!defined($free));
-
-my $total = $used + $free;
-if (defined($warning) && $warning =~ /^\d+%$/) {
-  if ($warning) {
-    $warning =~ s/%//;
-    $warning = $total / 100 * $warning;
-    $warning .= ':';
-  }
-  warn("Calculated threshold (from percentage): warn=>$warning\n") if ($verbose);
-}
-
-if (defined($critical) && $critical =~ /^\d+%$/) {
-  if ($critical) {
-    $critical =~ s/%//;
-    $critical = $total / 100 * $critical;
-    $critical .= ':';
-  }
-  warn("Calculated threshold (from percentage): crit=>$critical\n") if ($verbose);
-}
-
-$np->set_thresholds(
-  warning => $warning,
-  critical => $critical,
-);
-
-$np->add_perfdata(
-  label => "free",
-  value => $free,
-  uom => 'b',
-  threshold => $np->threshold,
-);
-
-my $freeprint = int($free/$multiple);
-
-$np->nagios_exit($np->check_threshold($free), "$freeprint$unit free");
-
diff --git a/plugins/check_memory b/plugins/check_memory
new file mode 100755
index 0000000..7055af6
--- /dev/null
+++ b/plugins/check_memory
@@ -0,0 +1,164 @@
+#!/usr/bin/perl
+#
+# check_memory  -  Check free(1) data against given tresholds
+#
+# Copyright (C) 2007 Thomas Guyot-Sionnest <tguyot@gmail.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+# patched by JFL on July 26th 2015 to work with new Linux free(1) output. Latest
+# version/issue tracker at: https://gitlab.lindenaar.net/scripts/nagios-plugins
+
+use strict;
+use warnings;
+use vars qw($PROGNAME $VERSION $FREECMD $UNIT);
+use Nagios::Plugin;
+
+$PROGNAME = "check_memory";
+$VERSION = '1.0.1';
+$FREECMD = '/usr/bin/free';
+$UNIT = 'M';
+
+my $np = Nagios::Plugin->new(
+  usage => "Usage: %s [ -w <warning_threshold> ] [ -c <critical_threshold> ]\n"
+    . '   [ -u <unit> ]',
+  version => $VERSION,
+  plugin  => $PROGNAME,
+  blurb => 'Check free(1) data against given tresholds',
+  timeout => 30,
+);
+
+$np->add_arg(
+  spec => 'warning|w=s',
+  help => "-w, --warning=THRESHOLD[%]\n"
+    . "   Warning threshold (in bytes or percent) for free memory. See\n"
+    . "   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n"
+    . "   for the threshold format. Alternatively this can be defined as a percentage\n"
+    . '   of minimum free memory (warning and critical must be in the same format).',
+  required => 0,
+);
+
+$np->add_arg(
+  spec => 'critical|c=s',
+  help => "-c, --critical=THRESHOLD[%]\n"
+    . "   Critical threshold (in bytes or percent) for free memory. See\n"
+    . "   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT\n"
+    . "   for the threshold format. Alternatively this can be defined as a percentage\n"
+    . '   of minimum free memory (warning and critical must be in the same format).',
+  required => 0,
+);
+
+$np->add_arg(
+  spec => 'unit|u=s',
+  help => "-u, --unit=UNIT\n"
+    . "   Unit to use for human-redeable output. Can be 'b', 'K' 'M' or 'G' for\n"
+    . "   bytes, KiB, MiB or GiB respectively (default: '$UNIT').",
+  default => $UNIT,
+  required => 0,
+);
+
+$np->getopts;
+
+# Assign, then check args
+
+my $multiple;
+my $unit = $np->opts->unit;
+if ($unit eq 'M') {
+  $multiple = 1024 * 1024;
+} elsif ( $unit eq 'K') {
+  $multiple = 1024;
+} elsif ( $unit eq 'b') {
+  $multiple = 1;
+} elsif ( $unit eq 'G') {
+  $multiple = 1024 * 1024 * 1024;
+} else {
+  $np->nagios_exit('UNKNOWN', "Unit must be one of 'b', 'K', 'M' or 'G', case-sensitive.");
+}
+my $verbose = $np->opts->verbose;
+
+# Would better fit later but doing it here validates thresholds
+my $warning = $np->opts->warning;
+my $critical = $np->opts->critical;
+$np->set_thresholds(
+    warning => ((defined($warning) && $warning !~ /^\d+%$/) ? $warning : undef),
+    critical => ((defined($critical) && $critical !~ /^\d+%$/) ? $critical : undef),
+);
+
+# Better safe than sorry
+alarm $np->opts->timeout;
+
+# We always get bytes, then calculate units ourselves
+warn("Running: '$FREECMD -b'\n") if ($verbose);
+open(RESULT, "$FREECMD -b |")
+  or $np->nagios_exit('CRITICAL', "Could not run $FREECMD");
+
+warn("Output from $FREECMD:\n") if ($verbose > 1);
+my ($used, $free);
+while (<RESULT>) {
+  warn("  $_") if ($verbose > 1);
+  if (m#^\-/\+\ buffers/cache:\s*(\d+)\s+(\d+)#) {
+	warn("  detected legacy format free output") if ($verbose > 1);
+	$used = $1;
+	$free = $2;
+	last;
+  } elsif (m#^Mem:\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$#) {
+	warn("  detected new format free output") if ($verbose > 1);
+	$used = $2;
+	$free = $3 + $5;
+	last;
+  }
+}
+
+close(RESULT);
+alarm(0);
+
+$np->nagios_exit('CRITICAL', "Unable to interpret $FREECMD output") if (!defined($free));
+
+my $total = $used + $free;
+if (defined($warning) && $warning =~ /^\d+%$/) {
+  if ($warning) {
+    $warning =~ s/%//;
+    $warning = $total / 100 * $warning;
+    $warning .= ':';
+  }
+  warn("Calculated threshold (from percentage): warn=>$warning\n") if ($verbose);
+}
+
+if (defined($critical) && $critical =~ /^\d+%$/) {
+  if ($critical) {
+    $critical =~ s/%//;
+    $critical = $total / 100 * $critical;
+    $critical .= ':';
+  }
+  warn("Calculated threshold (from percentage): crit=>$critical\n") if ($verbose);
+}
+
+$np->set_thresholds(
+  warning => $warning,
+  critical => $critical,
+);
+
+$np->add_perfdata(
+  label => "free",
+  value => $free,
+  uom => 'b',
+  threshold => $np->threshold,
+);
+
+my $freeprint = int($free/$multiple);
+
+$np->nagios_exit($np->check_threshold($free), "$freeprint$unit free");
+
--
libgit2 0.22.2