Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Monitor-Simple CPAN distribution.

Report information
The Basics
Id: 77097
Status: patched
Priority: 0/
Queue: Monitor-Simple

People
Owner: Nobody in particular
Requestors: GWS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.2.5
Fixed in: (no value)



Subject: Patch to make plugin check-mem.pl run under Windows
Some of the supplied plugins (and maybe notifiers?) presuppose a Unix environment, although these do not show up in the tests. (Maybe not so easy to do.) If you’re interested, please find enclosed a modified version of check-mem.pl which does run under Windows. I have taken care for it to be a drop-in replacement in the sense that it should run unchanged under Unices, but I have not tested this. (Note that I have slightly re-vamped the code in the process.) I have called this check-mem2.pl, only to prevent file name clashes. Not having access to a Unix box here, I am only unsure what kind of memory is being reported by vmstat: physical, or all that is (virtually) available? check-mem2.pl will, under Windows, report physical memory, but this can easily be changed if needed.
Subject: check_mem2.pl
#!/usr/bin/env perl -w # check_mem2.pl Copyright (C) 2012 Gisbert W. Selke <gws@cpan.org> # Modelled after # check_mem.pl Copyright (C) 2000 Dan Larsson <dl@tyfon.net> # # 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 (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA # Tell Perl what we need to use use strict; use warnings; use Getopt::Long qw(:config bundling); BEGIN { eval('require Win32::SystemInfo') if ($^O =~ /Win/i); } my $PROGNAME = 'check_mem2.pl'; my $VERSION = '1.1'; my ($check_free, $check_used, $level_warn, $level_crit, $verbose); # Predefined exit codes for Nagios my %exit_codes = ('UNKNOWN' => -1, 'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, ); # Get the options GetOptions('critical|c=f' => \$level_crit, 'warning|w=f' => \$level_warn, 'free|f!' => \$check_free, 'used|u!' => \$check_used, 'verbose|v!' => \$verbose, ); my $opt_count = 0; $opt_count++ if $check_free; $opt_count++ if $check_used; if ($opt_count != 1) { print '*** You must select to monitor either USED or FREE memory!' if $verbose; usage(); } # Check the levels if (($level_warn <= 0) || ($level_crit <= 0)) { print '*** You must define positive WARN and CRITICAL levels!' if $verbose; usage(); } # Check if levels are sane if ($check_free && ($level_warn <= $level_crit)) { print '*** WARN level must not be less than or equal to CRITICAL when checking FREE memory!' if $verbose; usage(); } if ($check_used && ($level_warn >= $level_crit)) { print '*** WARN level must not be greater than or equal to CRITICAL when checking USED memory or PROCESSOR load!' if $verbose; usage(); } my($memory, $percent); if ($^O !~ /Win/i) { # This the unix command string that brings Perl the data my $command_line = `vmstat | tail -1`; if (!$command_line) { print "*** System command vmstat not found or yielded no result!"; exit $exit_codes{'UNKNOWN'}; } my @memlist = split(/\s+/, $command_line); my $total_memory = $memlist[3] + $memlist[4]; $memory = $memlist[$check_used ? 3 : 4]; $percent = $memory/$total_memory * 100; } else { my %info; Win32::SystemInfo::MemoryStatus(%info); my $total_memory = $info{'TotalPhys'}; # Or TotalVirtual?? $percent = $check_used ? $info{'MemLoad'} : (100 - $info{'MemLoad'}); $memory = sprintf '%d', $total_memory*$percent*0.01; } my $state = 'OK'; if ($check_used) { $state = 'WARNING' if ($percent >= $level_warn); $state = 'CRITICAL' if ($percent >= $level_crit); } else { $state = 'WARNING' if ($percent <= $level_warn); $state = 'CRITICAL' if ($percent <= $level_crit); } printf "Memory %s - %1.1f%% (%d kB) %s\n", $state, $percent, $memory, ($check_used ? 'used' : 'free'); exit $exit_codes{$state}; # Show usage sub usage { print "\n$PROGNAME $VERSION - Nagios Plugin\n\n"; print "usage:\n"; print " $PROGNAME -<f|u> -w <warnlevel> -c <critlevel> [-v]\n\n"; print "options:\n"; print " --free Check FREE memory\n"; print " --used Check USED memory\n"; print " --warning PERCENT Percent free/used/load when to warn\n"; print " --critical PERCENT Percent free/used/load when critical\n"; print " --verbose Show verbose error messages\n"; print "All options may be abbreviated.\n"; print "\nCopyright (C) 2012 Dan Larsson <dl\@tyfon.net> / Gisbert W. Selke <gws\@cpan.org)\n"; print "$PROGNAME comes with absolutely NO WARRANTY either implied or explicit\n"; print "This program is licensed under the terms of the\n"; print "GNU General Public License (check source code for details)\n"; exit $exit_codes{'UNKNOWN'}; }
Thank you a lot. I have added your check_mem2.pl into the version 0.2.7. Martin
Subject: AW: [rt.cpan.org #77097] Patch to make plugin check-mem.pl run under Windows
Date: Tue, 4 Jun 2013 10:37:54 +0200
To: <bug-Monitor-Simple [...] rt.cpan.org>
From: "Selke, Gisbert W." <gisbert.selke [...] wido.bv.aok.de>
Again, thanks, Martin! In my original report there was stilkl an oben question regarding the kind of memory size that you want returned (physical vs. (virtually) available)? If interested/needed, I can change that. Also, please note that check-mem2.pl should really replace check-mem.pl and not go additionally -- it does not add functionality,just Windows-compatibility. \Gisbert Show quoted text
> -----Ursprüngliche Nachricht----- > Von: Martin Senger via RT [mailto:bug-Monitor-Simple@rt.cpan.org] > Gesendet: Montag, 3. Juni 2013 09:59 > An: GWS@cpan.org > Betreff: [rt.cpan.org #77097] Patch to make plugin check-mem.pl run under > Windows > > <URL: https://rt.cpan.org/Ticket/Display.html?id=77097 > > > Thank you a lot. I have added your check_mem2.pl into the version 0.2.7. > Martin
Hi, Show quoted text
> In my original report there was stilkl an oben question regarding the kind of memory > size that you want returned (physical vs. (virtually) available)? If interested/needed, > I can change that.
I notice that question. But I do not have any answer because I have not written myself the "check-mem.pl" - it came directly from the Nagious plugins. I have put it in the distribution as an illustration that a standard Nagios plugins can be directly used in Monitor::Simple module. Show quoted text
> Also, please note that check-mem2.pl should really replace check-mem.pl and not go > additionally -- it does not add functionality,just Windows-compatibility.
Yes, I know it. But again, I wanted to keep the original script as a "proof" of compatibility with Nagios. I think (I hope :-) ) that the script is not used in the test suites, at all. Therefore, I thought that keeping them both (and to mention the new one and its author in the acknowledgement) may be a good idea. Martin
Subject: AW: [rt.cpan.org #77097] Patch to make plugin check-mem.pl run under Windows
Date: Tue, 4 Jun 2013 19:36:12 +0200
To: <bug-Monitor-Simple [...] rt.cpan.org>
From: "Selke, Gisbert W." <gisbert.selke [...] wido.bv.aok.de>
Show quoted text
> -----Ursprüngliche Nachricht----- > Von: Martin Senger via RT [mailto:bug-Monitor-Simple@rt.cpan.org] > Gesendet: Dienstag, 4. Juni 2013 10:50 > I notice that question. But I do not have any answer because I have not > written myself the "check-mem.pl" - it came directly from the Nagious > plugins. I have put it in the distribution as an illustration that a standard > Nagios plugins can be directly used in Monitor::Simple module.
Ah, I see & agree -- thanks! Show quoted text
> Yes, I know it. But again, I wanted to keep the original script as a "proof" of > compatibility with Nagios. I think (I hope :-) ) that the script is not used in the > test suites, at all. Therefore, I thought that keeping them both (and to > mention the new one and its author in the acknowledgement) may be a > good idea.
No claim to fame from my side! My changes certainly lack "sufficient level of inventiveness", as German patent law has it in "beautiful" parlance :-) \Gisbert