summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2003-07-02 15:01:22 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2003-07-02 15:01:22 (GMT)
commit7d32d2b5f41662098f444f0f02ab1afccdeb6e41 (patch)
tree10702617d976a93850eef311157b52ce2f60bd43 /plugins-scripts
parent883914b9d89f084c2613e2d36e8f4334b993cc12 (diff)
downloadmonitoring-plugins-7d32d2b5f41662098f444f0f02ab1afccdeb6e41.tar.gz
Moving check_file_age into core
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@578 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/.cvsignore1
-rw-r--r--plugins-scripts/Makefile.am6
-rwxr-xr-xplugins-scripts/check_file_age.pl113
-rw-r--r--plugins-scripts/subst.in2
4 files changed, 119 insertions, 3 deletions
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
16check_rpc 16check_rpc
17check_sensors 17check_sensors
18check_wave 18check_wave
19check_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/
6 6
7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ 7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \
8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \ 8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \
9 check_ifstatus check_ifoperstatus check_mailq utils.sh utils.pm 9 check_ifstatus check_ifoperstatus check_mailq check_file_age \
10 utils.sh utils.pm
10 11
11EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ 12EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
12 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \ 13 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \
13 check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl utils.sh.in utils.pm.in t 14 check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl check_file_age.pl \
15 utils.sh.in utils.pm.in t
14 16
15TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir) 17TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)
16 18
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 @@
1#!/bin/perl -w
2# $Id$
3
4# check_file.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com>
5#
6# Checks a file's size and modification time to make sure it's not empty
7# and that it's sufficiently recent.
8#
9#
10# This program is free software; you can redistribute it and/or
11# modify it under the terms of the GNU General Public License
12# as published by the Free Software Foundation; either version 2
13# of the License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty
17# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# you should have received a copy of the GNU General Public License
21# along with this program (or with Nagios); if not, write to the
22# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23# Boston, MA 02111-1307, USA
24
25use strict;
26use English;
27use Getopt::Long;
28use File::stat;
29use vars qw($PROGNAME);
30use lib ".";
31use utils qw (%ERRORS &print_revision &support);
32
33sub print_help ();
34sub print_usage ();
35
36my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
37my ($result, $message, $age, $size, $st);
38
39$PROGNAME="check_file";
40
41$opt_w = 240;
42$opt_c = 600;
43$opt_W = 0;
44$opt_C = 0;
45$opt_f = "";
46
47Getopt::Long::Configure('bundling');
48GetOptions(
49 "V" => \$opt_V, "version" => \$opt_V,
50 "h" => \$opt_h, "help" => \$opt_h,
51 "f=s" => \$opt_f, "file" => \$opt_f,
52 "w=f" => \$opt_w, "warning-age=f" => \$opt_w,
53 "W=f" => \$opt_W, "warning-size=f" => \$opt_W,
54 "c=f" => \$opt_c, "critical-age=f" => \$opt_c,
55 "C=f" => \$opt_C, "critical-size=f" => \$opt_C);
56
57if ($opt_V) {
58 print_revision($PROGNAME, '$Id$');
59 exit $ERRORS{'OK'};
60}
61
62if ($opt_h) {
63 print_help();
64 exit $ERRORS{'OK'};
65}
66
67$opt_f = shift unless ($opt_f);
68
69if (! $opt_f) {
70 print "No file specified\n";
71 exit $ERRORS{'UNKNOWN'};
72}
73
74# Examine the file.
75unless (-f $opt_f) {
76 print "$opt_f: File not found\n";
77 exit $ERRORS{'UNKNOWN'};
78}
79
80$st = File::stat::stat($opt_f);
81$age = time - $st->mtime;
82$size = $st->size;
83
84
85$result = 'OK';
86
87if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
88 $result = 'CRITICAL';
89}
90elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
91 $result = 'WARNING';
92}
93
94print "$result - $opt_f is $age seconds old and $size bytes\n";
95exit $ERRORS{$result};
96
97sub print_usage () {
98 print "Usage:\n";
99 print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n";
100 print " $PROGNAME [-h | --help]\n";
101 print " $PROGNAME [-V | --version]\n";
102}
103
104sub print_help () {
105 print_revision($PROGNAME, '$Id$');
106 print "Copyright (c) 2003 Steven Grimm\n\n";
107 print_usage();
108 print "\n";
109 print " <secs> File must be no more than this many seconds old\n";
110 print " <size> File must be at least this many bytes long\n";
111 print "\n";
112 support();
113}
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 {
45/^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");} 45/^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");}
46 46
47# add to libexecdir to INC for perl utils.pm 47# add to libexecdir to INC for perl utils.pm
48/^use/ { if (/lib/) { if (/utils.pm/ ) {sub(/utils.pm/,led() )} } } 48/^use/ { if (/lib/) { if (/utils.pm|"."/ ) {sub(/utils.pm|"."/,led() )} } }
49 49
50 50
51# Trusted path mechanism (deprecated) 51# Trusted path mechanism (deprecated)