- renamed to monitoring-plugins-contentage

- license update: BSD-3-Clause
  See check_contentage file

- update to 0.6: added performance data

- update to 0.4: added timeout option

- update to 0.3 (changes see below)

- print revision
- use hash for values

- initial package

OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-contentage?expand=0&rev=2
This commit is contained in:
Lars Vogdt 2014-07-30 15:04:51 +00:00 committed by Git OBS Bridge
commit 337e8a800d
5 changed files with 337 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

207
check_contentage Normal file
View File

@ -0,0 +1,207 @@
#!/usr/bin/perl -w
# nagios: -epn
#
# check_contentage - nagios plugin
#
# Copyright (C) 2012, SUSE Linux Products GmbH
# Author: Lars Vogdt
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the Novell nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# 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};
use Time::HiRes qw{time alarm};
use strict;
use warnings;
use Getopt::Long;
use File::Basename;
use File::stat;
use POSIX qw(strftime);
our $version="0.4";
our $time_warn=1440;
our $time_crit=4880;
our @pathnames=qw();
our $help=0;
our $rev=0;
our $recursive=0;
our $errorstr="";
our $DEBUG=0;
our %status;
# nagios requires a 3 for unknown errors.
$SIG{__DIE__} = sub {
print @_;
exit 3;
};
# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
print "UNKNOWN - Plugin timed out\n";
exit $ERRORS{"UNKNOWN"};
};
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 "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";
}
sub print_help {
my $exitcode=shift || 1;
print "Copyright (c) 2009, Novell, Inc.\n\n";
print_usage();
print "\n";
exit $exitcode;
}
sub print_error {
my $error=shift || '';
print STDERR "\nERROR: $error\n\n";
&print_usage;
exit $ERRORS{'UNKNOWN'};
}
sub check_dir($$$){
my $dir = shift;
my $secwarn = shift;
my $seccrit = shift;
my %res;
my $count=0;
my $futurecount=0;
my $oldcount=0;
my $warncount=0;
$res{'level'}=$ERRORS{'OK'};
$res{'errorstr'}="";
if (opendir(DIR,"$dir")){
print "Working in $dir\n" if ($DEBUG);
for (readdir(DIR)) {
# if ($recursive){
# &check_dir("$dir/$_",$secwarn,$seccrit) if (-d "$dir/$_");
# }
$count++;
next if (! -f "$dir/$_");
my $mtime=stat("$dir/$_")->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{'level'}=$ERRORS{'CRITICAL'};
$futurecount++;
} elsif ( $age >= $seccrit ){
$res{'errorstr'}.="$dir/$_ was last modified on $time\n";
$res{'level'}=$ERRORS{'CRITICAL'};
$oldcount++;
} elsif ( $age >= $secwarn ){
$res{'errorstr'}.="$dir/$_ was last modified on $time\n";
$res{'level'}=$ERRORS{'WARNING'} if ($res{'level'} < $ERRORS{'WARNING'});
$warncount++;
}
}
} else {
$res{'level'}=$ERRORS{'WARNING'};
$res{'errorstr'}="$dir not found or not readable";
}
$res{'count'}=$count;
$res{'futurecount'}=$futurecount;
$res{'oldcount'}=$oldcount;
$res{'warncount'}=$warncount;
return \%res;
}
Getopt::Long::Configure('bundling');
if(!GetOptions( 'w|warning=i' => \$time_warn,
'c|critical=i' => \$time_crit,
'p|pathname=s' => \@pathnames,
'r|recursive' => \$recursive,
't|timeout=i' => \$TIMEOUT,
'h|help' => \$help,
'v|version' => \$rev,
)){
&print_help(1);
}
&print_help(0) if ($help);
if ($rev){
&print_revision(basename($0),$version);
exit $ERRORS{'UNKNOWN'};
}
print_error("warning must be greater than 0") if ($time_warn <= 0);
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));
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);
foreach my $path (@pathnames){
$status{"$path"}=check_dir("$path",$secwarn, $seccrit);
}
our $exitcode=0;
our ($total_count,$future_count,$old_count,$warncount)=0;
foreach my $path (sort(keys %status)){
if ((defined($status{$path}{'level'})) && ($status{$path}{'level'} > $exitcode)){
$exitcode=$status{$path}{'level'};
}
if ((defined($status{$path}{'errorstr'})) && ($status{$path}{'errorstr'} ne '')){
$errorstr .= $status{$path}{'errorstr'};
}
$total_count+=$status{$path}{'count'};
$future_count+=$status{$path}{'futurecount'};
$old_count+=$status{$path}{'oldcount'};
$warncount+=$status{$path}{'warncount'}
}
if ($exitcode){
if ( $exitcode == $ERRORS{'WARNING'}){
print "WARNING: Found files older than $time_warn minutes ";
} elsif ( $exitcode == $ERRORS{'CRITICAL'}){
print "CRITICAL: Found files older than $time_crit minutes ";
}
print "$errorstr";
print "| total_files=$total_count;;;old_files=$old_count;;;warn_files=$warncount;;;files_with_future_timestamp=$future_count;;;\n";
exit $exitcode;
} else {
print "OK: Tested ".join(" ",@pathnames)." - no files older than $time_warn minutes found ";
print "| total_files=$total_count;;;old_files=$old_count;;;warn_files=$warncount;;;files_with_future_timestamp=$future_count;;;\n";
exit $ERRORS{"OK"};
}

View File

@ -0,0 +1,37 @@
-------------------------------------------------------------------
Wed Jul 30 15:04:04 UTC 2014 - lars@linux-schulserver.de
- renamed to monitoring-plugins-contentage
-------------------------------------------------------------------
Thu Jan 17 21:01:07 UTC 2013 - cfarrell@suse.com
- license update: BSD-3-Clause
See check_contentage file
-------------------------------------------------------------------
Thu May 3 18:52:42 UTC 2012 - lrupp@suse.de
- update to 0.6: added performance data
-------------------------------------------------------------------
Wed Jun 17 12:10:02 CEST 2009 - lrupp@suse.de
- update to 0.4: added timeout option
-------------------------------------------------------------------
Tue Jun 16 18:03:34 CEST 2009 - lrupp@suse.de
- update to 0.3 (changes see below)
-------------------------------------------------------------------
Tue Jun 16 17:33:56 CEST 2009 - lrupp@suse.de
- print revision
- use hash for values
-------------------------------------------------------------------
Mon Jun 15 18:49:04 CEST 2009 - lrupp@suse.de
- initial package

View File

@ -0,0 +1,69 @@
#
# spec file for package monitoring-plugins-contentage
#
# Copyright (c) 2012-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# 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/
#
Name: monitoring-plugins-contentage
Version: 0.6
Release: 1
License: BSD-3-Clause
Summary: Check age of files in a directory
Url: http://en.opensuse.org/Monitoring-plugins-contentage
Group: System/Monitoring
Source0: check_contentage
BuildRequires: nagios-rpm-macros
Provides: nagios-plugins-contentage = %{version}-%{release}
Obsoletes: nagios-plugins-contentage < %{version}-%{release}
Requires: perl(File::Basename)
Requires: perl(File::stat)
Requires: perl(Getopt::Long)
Requires: perl(POSIX)
Requires: perl(Time::HiRes)
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%description
This plugin checks one or more directory for files older than a specified age.
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
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)
%prep
#
%build
#
%install
install -D -m755 %{SOURCE0} %{buildroot}%{nagios_plugindir}/check_contentage
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root)
# avoid build dependecy of nagios - own the dirs
%dir %{nagios_libdir}
%dir %{nagios_plugindir}
%{nagios_plugindir}/check_contentage
%changelog