From: Ton Voon Date: Wed, 2 Jul 2003 15:01:22 +0000 (+0000) Subject: Moving check_file_age into core X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7d32d2b5f41662098f444f0f02ab1afccdeb6e41;p=nagiosplug.git Moving check_file_age into core git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@578 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/contrib/check_file_age.pl b/contrib/check_file_age.pl deleted file mode 100755 index ae9311e..0000000 --- a/contrib/check_file_age.pl +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/perl -w -# $Id$ - -# check_file.pl Copyright (C) 2003 Steven Grimm -# -# Checks a file's size and modification time to make sure it's not empty -# and that it's sufficiently recent. -# -# -# 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 - -use strict; -use English; -use Getopt::Long; -use File::stat; -use vars qw($PROGNAME); -use lib utils.pm; -use utils qw (%ERRORS &print_revision &support); - -sub print_help (); -sub print_usage (); - -my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); -my ($result, $message, $age, $size, $st); - -$PROGNAME="check_file"; - -$opt_w = 240; -$opt_c = 600; -$opt_W = 0; -$opt_C = 0; -$opt_f = ""; - -Getopt::Long::Configure('bundling'); -GetOptions( - "V" => \$opt_V, "version" => \$opt_V, - "h" => \$opt_h, "help" => \$opt_h, - "f=s" => \$opt_f, "file" => \$opt_f, - "w=f" => \$opt_w, "warning-age=f" => \$opt_w, - "W=f" => \$opt_W, "warning-size=f" => \$opt_W, - "c=f" => \$opt_c, "critical-age=f" => \$opt_c, - "C=f" => \$opt_C, "critical-size=f" => \$opt_C); - -if ($opt_V) { - print_revision($PROGNAME, '$Id$'); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -$opt_f = shift unless ($opt_f); - -if (! $opt_f) { - print "No file specified\n"; - exit $ERRORS{'UNKNOWN'}; -} - -# Examine the file. -unless (-f $opt_f) { - print "$opt_f: File not found\n"; - exit $ERRORS{'UNKNOWN'}; -} - -$st = File::stat::stat($opt_f); -$age = time - $st->mtime; -$size = $st->size; - - -$result = 'OK'; - -if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { - $result = 'CRITICAL'; -} -elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { - $result = 'WARNING'; -} - -print "$result - $opt_f is $age seconds old and $size bytes\n"; -exit $ERRORS{$result}; - -sub print_usage () { - print "Usage:\n"; - print " $PROGNAME [-w ] [-c ] [-W ] [-C ] -f \n"; - print " $PROGNAME [-h | --help]\n"; - print " $PROGNAME [-V | --version]\n"; -} - -sub print_help () { - print_revision($PROGNAME, '$Id$'); - print "Copyright (c) 2003 Steven Grimm\n\n"; - print_usage(); - print "\n"; - print " File must be no more than this many seconds old\n"; - print " File must be at least this many bytes long\n"; - print "\n"; - support(); -} diff --git a/plugins-scripts/.cvsignore b/plugins-scripts/.cvsignore index 341101f..3066a97 100644 --- a/plugins-scripts/.cvsignore +++ b/plugins-scripts/.cvsignore @@ -16,3 +16,4 @@ check_oracle check_rpc check_sensors check_wave +check_file_age diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am index 411c1a0..5556cf6 100644 --- a/plugins-scripts/Makefile.am +++ b/plugins-scripts/Makefile.am @@ -6,11 +6,13 @@ VPATH=$(top_srcdir) $(top_srcdir)/plugins-scripts $(top_srcdir)/plugins-scripts/ libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ check_log check_ntp check_oracle check_rpc check_sensors check_wave \ - check_ifstatus check_ifoperstatus check_mailq utils.sh utils.pm + check_ifstatus check_ifoperstatus check_mailq check_file_age \ + utils.sh utils.pm EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \ - check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl utils.sh.in utils.pm.in t + check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \ + utils.sh.in utils.pm.in t TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir) diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl new file mode 100755 index 0000000..2ab1a28 --- /dev/null +++ b/plugins-scripts/check_file_age.pl @@ -0,0 +1,113 @@ +#!/bin/perl -w +# $Id$ + +# check_file.pl Copyright (C) 2003 Steven Grimm +# +# Checks a file's size and modification time to make sure it's not empty +# and that it's sufficiently recent. +# +# +# 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 + +use strict; +use English; +use Getopt::Long; +use File::stat; +use vars qw($PROGNAME); +use lib "."; +use utils qw (%ERRORS &print_revision &support); + +sub print_help (); +sub print_usage (); + +my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V); +my ($result, $message, $age, $size, $st); + +$PROGNAME="check_file"; + +$opt_w = 240; +$opt_c = 600; +$opt_W = 0; +$opt_C = 0; +$opt_f = ""; + +Getopt::Long::Configure('bundling'); +GetOptions( + "V" => \$opt_V, "version" => \$opt_V, + "h" => \$opt_h, "help" => \$opt_h, + "f=s" => \$opt_f, "file" => \$opt_f, + "w=f" => \$opt_w, "warning-age=f" => \$opt_w, + "W=f" => \$opt_W, "warning-size=f" => \$opt_W, + "c=f" => \$opt_c, "critical-age=f" => \$opt_c, + "C=f" => \$opt_C, "critical-size=f" => \$opt_C); + +if ($opt_V) { + print_revision($PROGNAME, '$Id$'); + exit $ERRORS{'OK'}; +} + +if ($opt_h) { + print_help(); + exit $ERRORS{'OK'}; +} + +$opt_f = shift unless ($opt_f); + +if (! $opt_f) { + print "No file specified\n"; + exit $ERRORS{'UNKNOWN'}; +} + +# Examine the file. +unless (-f $opt_f) { + print "$opt_f: File not found\n"; + exit $ERRORS{'UNKNOWN'}; +} + +$st = File::stat::stat($opt_f); +$age = time - $st->mtime; +$size = $st->size; + + +$result = 'OK'; + +if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) { + $result = 'CRITICAL'; +} +elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) { + $result = 'WARNING'; +} + +print "$result - $opt_f is $age seconds old and $size bytes\n"; +exit $ERRORS{$result}; + +sub print_usage () { + print "Usage:\n"; + print " $PROGNAME [-w ] [-c ] [-W ] [-C ] -f \n"; + print " $PROGNAME [-h | --help]\n"; + print " $PROGNAME [-V | --version]\n"; +} + +sub print_help () { + print_revision($PROGNAME, '$Id$'); + print "Copyright (c) 2003 Steven Grimm\n\n"; + print_usage(); + print "\n"; + print " File must be no more than this many seconds old\n"; + print " File must be at least this many bytes long\n"; + print "\n"; + support(); +} diff --git a/plugins-scripts/subst.in b/plugins-scripts/subst.in index 7e38e02..2ac4534 100644 --- a/plugins-scripts/subst.in +++ b/plugins-scripts/subst.in @@ -45,7 +45,7 @@ BEGIN { /^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");} # add to libexecdir to INC for perl utils.pm -/^use/ { if (/lib/) { if (/utils.pm/ ) {sub(/utils.pm/,led() )} } } +/^use/ { if (/lib/) { if (/utils.pm|"."/ ) {sub(/utils.pm|"."/,led() )} } } # Trusted path mechanism (deprecated)