From 5ee9f53df3cbfe3138ac18623d31fad43dac578724935a565a38a360883ce7e5 Mon Sep 17 00:00:00 2001 From: Lars Vogdt Date: Sat, 4 Jan 2020 22:19:05 +0000 Subject: [PATCH] - update to 0.7: + add debug output option + add option to ignore specific files + updated copyright notice OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-contentage?expand=0&rev=7 --- check_contentage | 42 +++++++++++++++++---------- monitoring-plugins-contentage.changes | 8 +++++ monitoring-plugins-contentage.spec | 18 +++++++----- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/check_contentage b/check_contentage index 68eeb53..5159b14 100644 --- a/check_contentage +++ b/check_contentage @@ -4,6 +4,7 @@ # check_contentage - nagios plugin # # Copyright (C) 2012, SUSE Linux Products GmbH +# Copyright (C) 2020, SUSE LCC # Author: Lars Vogdt # # All rights reserved. @@ -34,8 +35,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# $Id$ -# use lib "/usr/lib/nagios/plugins"; use utils qw{$TIMEOUT %ERRORS print_revision}; @@ -47,11 +46,12 @@ use File::Basename; use File::stat; use POSIX qw(strftime); -our $version="0.4"; +our $version="0.7"; our $time_warn=1440; our $time_crit=4880; our @pathnames=qw(); our $help=0; +our @ignores=qw(); our $rev=0; our $recursive=0; our $errorstr=""; @@ -74,20 +74,22 @@ alarm($TIMEOUT); sub print_usage { print "This plugin checks one or more directory for files older than a specified age.\n"; print "You can define the age of files for warning and critical states.\n\n"; - print "Usage: ".basename($0)." -w $time_warn -c $time_crit -p /tmp\n"; + print "Usage: ".basename($0)." -w $time_warn -c $time_crit -p /tmp,/var/tmp -i /tmp/foo,/tmp/bar\n"; print "Options:\n"; print " -w|--warning : time for warnings (minutes)\n"; print " -c|--critical : time for critical warnings (minutes)\n"; print " -p|--pathnames : absolute path to the folders, split mutliple pathnames with commata\n"; # print " -r|--recursive : dive into subfolders\n"; print " -t|--timeout : timeout (default: $TIMEOUT)\n"; + print " -i|--ignore : ignore filenames (comma separated)\n"; + print " -d|--debug : print debug output\n"; } sub print_help { my $exitcode=shift || 1; - print "Copyright (c) 2009, Novell, Inc.\n\n"; + print "Copyright (c) 2020, SUSE LCC\n\n"; print_usage(); - print "\n"; + print "\n"; exit $exitcode; } @@ -98,10 +100,11 @@ sub print_error { exit $ERRORS{'UNKNOWN'}; } -sub check_dir($$$){ +sub check_dir($$$$){ my $dir = shift; my $secwarn = shift; my $seccrit = shift; + my $ignores_ref = shift; my %res; my $count=0; my $futurecount=0; @@ -111,26 +114,30 @@ sub check_dir($$$){ $res{'errorstr'}=""; if (opendir(DIR,"$dir")){ print "Working in $dir\n" if ($DEBUG); - for (readdir(DIR)) { + for my $file (readdir(DIR)) { # if ($recursive){ -# &check_dir("$dir/$_",$secwarn,$seccrit) if (-d "$dir/$_"); +# &check_dir("$dir/$file",$secwarn,$seccrit) if (-d "$dir/$_"); # } $count++; - next if (! -f "$dir/$_"); - my $mtime=stat("$dir/$_")->mtime; + next if (! -f "$dir/$file"); + if (grep(/\Q$dir\/$file\E/, @$ignores_ref)){ + print "$dir/$file is in ignores\n" if ($DEBUG); + next; + } + my $mtime=stat("$dir/$file")->mtime; my $age = time() - $mtime; my $time=strftime("%a %b %e %H:%M:%S %Y",localtime($mtime)); print "$_ : $mtime : $age sec\n" if ($DEBUG); if ( $age < 0 ){ - $res{'errorstr'}.="$dir/$_ was modified in the future!\n"; + $res{'errorstr'}.="$dir/$file was modified in the future!\n"; $res{'level'}=$ERRORS{'CRITICAL'}; $futurecount++; } elsif ( $age >= $seccrit ){ - $res{'errorstr'}.="$dir/$_ was last modified on $time\n"; + $res{'errorstr'}.="$dir/$file was last modified on $time\n"; $res{'level'}=$ERRORS{'CRITICAL'}; $oldcount++; } elsif ( $age >= $secwarn ){ - $res{'errorstr'}.="$dir/$_ was last modified on $time\n"; + $res{'errorstr'}.="$dir/$file was last modified on $time\n"; $res{'level'}=$ERRORS{'WARNING'} if ($res{'level'} < $ERRORS{'WARNING'}); $warncount++; } @@ -149,6 +156,8 @@ sub check_dir($$$){ Getopt::Long::Configure('bundling'); if(!GetOptions( 'w|warning=i' => \$time_warn, 'c|critical=i' => \$time_crit, + 'd|debug' => \$DEBUG, + 'i|ignore=s' => \@ignores, 'p|pathname=s' => \@pathnames, 'r|recursive' => \$recursive, 't|timeout=i' => \$TIMEOUT, @@ -168,12 +177,13 @@ print_error("critical must be greater than 0") if ($time_crit <= 0); print_error("critical ($time_crit) must be greater than warning ($time_warn)") if ($time_crit <= $time_warn); print_error("Please provide at least one pathname") if (!defined($pathnames[0]) || ( $pathnames[0] eq "" )); @pathnames=split(/,/,join(',',@pathnames)); +@ignores=split(/,/,join(',',@ignores)); our $secwarn = $time_warn * 60; our $seccrit = $time_crit * 60; -print STDERR "TIMEOUT: $TIMEOUT\nWARN: $time_warn\nCRIT: $time_crit\nPATHNAMES: ".join(" ",@pathnames)."\n" if ($DEBUG); +print STDERR "TIMEOUT: $TIMEOUT\nWARN: $time_warn\nCRIT: $time_crit\nPATHNAMES: ".join(" ",@pathnames)."\nIGNORES: ".join(" ",@ignores)."\n" if ($DEBUG); foreach my $path (@pathnames){ - $status{"$path"}=check_dir("$path",$secwarn, $seccrit); + $status{"$path"}=check_dir("$path",$secwarn, $seccrit, \@ignores); } our $exitcode=0; diff --git a/monitoring-plugins-contentage.changes b/monitoring-plugins-contentage.changes index 138c8ab..f637879 100644 --- a/monitoring-plugins-contentage.changes +++ b/monitoring-plugins-contentage.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Sat Jan 4 22:18:08 UTC 2020 - Lars Vogdt + +- update to 0.7: + + add debug output option + + add option to ignore specific files + + updated copyright notice + ------------------------------------------------------------------- Wed Jul 30 23:17:29 UTC 2014 - lars@linux-schulserver.de diff --git a/monitoring-plugins-contentage.spec b/monitoring-plugins-contentage.spec index a83cb9d..b04f03b 100644 --- a/monitoring-plugins-contentage.spec +++ b/monitoring-plugins-contentage.spec @@ -1,7 +1,7 @@ # # spec file for package monitoring-plugins-contentage # -# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,18 +12,17 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # - Name: monitoring-plugins-contentage -Version: 0.6 -Release: 1 -License: BSD-3-Clause +Version: 0.7 +Release: 0 Summary: Check age of files in a directory -Url: http://en.opensuse.org/Monitoring-plugins-contentage +License: BSD-3-Clause Group: System/Monitoring +Url: http://en.opensuse.org/Monitoring-plugins-contentage Source0: check_contentage BuildRequires: nagios-rpm-macros Provides: nagios-plugins-contentage = %{version}-%{release} @@ -42,12 +41,15 @@ You can define the age of files for warning and critical states. Note: the plugin checks the mtime of files, not the ctime. -Usage: check_dircontent.pl -w 24 -c 48 -p /tmp +Usage: check_dircontent.pl -w 24 -c 48 -p /tmp,/var/tmp -i foo,bar Options: -w|--warning : time for warnings (minutes) -c|--critical : time for critical warnings (minutes) -p|--pathnames : absolute path to the folders, split mutliple pathnames with commata -t|--timeout : timeout (default: 15) + -i|--ignore : ignore filenames (comma separated) + -d|--debug : print debug output + %prep #