commit bc787d10711674b666a3b9c16bcb3cea282879154f625a38a8a8959718397315 Author: Lars Vogdt Date: Wed Jul 30 19:14:41 2014 +0000 osc copypac from project:server:monitoring package:nagios-plugins-count_file revision:1 OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-count_file?expand=0&rev=1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/count_file.pl b/count_file.pl new file mode 100644 index 0000000..f595c6a --- /dev/null +++ b/count_file.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl -w +## $Id: count_file.pl 232 2006-10-01 15:23:55Z touche $ +## julien.touche@touche.fr.st +## +## modified from http://answers.tveasy.co.uk/c.l.p.misc/count-fd.htm + +use strict; + +$ENV{'PATH'}=''; +$ENV{'BASH_ENV'}=''; +$ENV{'ENV'}=''; + +#use lib "/usr/local/libexec/nagios"; +#use lib "T:\\sysshare\\unattended\\install\\packages\\admin\\nrpe_nt\\bin\\utils.pm"; +#use utils qw(%ERRORS); + +if($#ARGV+1!=3 || ! -d $ARGV[0]){ + print "Usage: \"Filename\" \"Critical number of files\" \"Warning number of files\"\n"; + print " examples: $0 1 10\n"; + print " examples: $0 3:10 1:3\n"; + exit 0; +} +my $exit=0; +my ($dir,$maxwarn,$maxcrit,$minwarn,$mincrit); +$dir = $ARGV[0]; +$maxcrit = $ARGV[1]; +if ($maxcrit =~ m/([0-9].+):([0-9].+)/) { + $mincrit = $1; + $maxcrit = $2; +} +$maxwarn = $ARGV[2]; +if ($maxwarn =~ m/([0-9].+):([0-9].+)/) { + $minwarn = $1; + $maxwarn = $2; +} + + +my ($count); + +opendir DIR, $dir or die "Could not opendir $dir; Reason: $!"; + +my @files = grep !/^\.\.?$/ => readdir DIR; + +$count = @files ; + +closedir DIR; + +if ($count>$maxcrit) { + print "Critical: Filecount of '$dir' too large $count > $maxcrit.\n";$exit=2; +} elsif (defined($mincrit) && $count < $mincrit) { + print "Critical: Filecount of '$dir' too small $count < $mincrit.\n";$exit=2; +} elsif ($count>$maxwarn) { + print "Warning: Filecount of '$dir' $count > $maxwarn.\n";$exit=1; +} elsif (defined($minwarn) && $count < $minwarn) { + print "Warning: Filecount of '$dir' $count < $minwarn.\n";$exit=1; +} else { + print "OK: Filecount of '$dir' $count.\n"; $exit = 0; +} +exit $exit; + diff --git a/nagios-plugins-count_file.changes b/nagios-plugins-count_file.changes new file mode 100644 index 0000000..6e87ed7 --- /dev/null +++ b/nagios-plugins-count_file.changes @@ -0,0 +1,5 @@ +------------------------------------------------------------------- +Sun Jan 12 15:40:50 UTC 2014 - lars@linux-schulserver.de + +- initial version 232 + diff --git a/nagios-plugins-count_file.spec b/nagios-plugins-count_file.spec new file mode 100644 index 0000000..46d7d4b --- /dev/null +++ b/nagios-plugins-count_file.spec @@ -0,0 +1,61 @@ +# +# spec file for package nagios-plugins-count_file +# +# Copyright (c) 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: nagios-plugins-count_file +Version: 232 +Release: 0 +License: BSD-4-Clause +Summary: Counts the number of files in a directory +Url: https://www.monitoringexchange.org/inventory/Check-Plugins/Operating-Systems/Linux/count_file +Group: System/Monitoring +Source0: count_file.pl +BuildRequires: nagios-rpm-macros +Requires: perl +BuildArch: noarch +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +Use this plugin to count the number of files in a directory and +issue a warning or critical state if the number exceeds a limit. + +Useful if you want to monitor for example: +* a directory which contains error files and must stay empty +* a tmp dir which have to stay under a practical limit + +Usage: + +Examples: count_file.pl 1 10 +Examples: count_file.pl 3:10 1:3 + +%prep +# +%build +# +%install +install -Dm755 %{SOURCE0} %buildroot/%{nagios_plugindir}/count_file.pl + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root) +# avoid build dependecy of nagios - own the dirs +%dir %{nagios_libdir} +%dir %{nagios_plugindir} +%{nagios_plugindir}/count_file.pl + +%changelog