summaryrefslogtreecommitdiffstats
path: root/web/attachments/40514-check_file_age
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-29 22:03:24 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-29 22:03:24 (GMT)
commit0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch)
tree1c2b6b21704a294940f87c7892676998d8371707 /web/attachments/40514-check_file_age
downloadsite-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files.
Diffstat (limited to 'web/attachments/40514-check_file_age')
-rw-r--r--web/attachments/40514-check_file_age112
1 files changed, 112 insertions, 0 deletions
diff --git a/web/attachments/40514-check_file_age b/web/attachments/40514-check_file_age
new file mode 100644
index 0000000..498c650
--- /dev/null
+++ b/web/attachments/40514-check_file_age
@@ -0,0 +1,112 @@
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 utils qw (%ERRORS &print_revision &support);
31
32sub print_help ();
33sub print_usage ();
34
35my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
36my ($result, $message, $age, $size, $st);
37
38$PROGNAME="check_file";
39
40$opt_w = 240;
41$opt_c = 600;
42$opt_W = 0;
43$opt_C = 0;
44$opt_f = "";
45
46Getopt::Long::Configure('bundling');
47GetOptions(
48 "V" => \$opt_V, "version" => \$opt_V,
49 "h" => \$opt_h, "help" => \$opt_h,
50 "f=s" => \$opt_f, "file" => \$opt_f,
51 "w=f" => \$opt_w, "warning-age=f" => \$opt_w,
52 "W=f" => \$opt_W, "warning-size=f" => \$opt_W,
53 "c=f" => \$opt_c, "critical-age=f" => \$opt_c,
54 "C=f" => \$opt_C, "critical-size=f" => \$opt_C);
55
56if ($opt_V) {
57 print_revision($PROGNAME, '$Id$');
58 exit $ERRORS{'OK'};
59}
60
61if ($opt_h) {
62 print_help();
63 exit $ERRORS{'OK'};
64}
65
66$opt_f = shift unless ($opt_f);
67
68if (! $opt_f) {
69 print "No file specified\n";
70 exit $ERRORS{'UNKNOWN'};
71}
72
73# Examine the file.
74unless (-f $opt_f) {
75 print "$opt_f: File not found\n";
76 exit $ERRORS{'UNKNOWN'};
77}
78
79$st = File::stat::stat($opt_f);
80$age = time - $st->mtime;
81$size = $st->size;
82
83
84$result = 'OK';
85
86if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
87 $result = 'CRITICAL';
88}
89elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
90 $result = 'WARNING';
91}
92
93print "$result - $opt_f is $age seconds old and $size bytes\n";
94exit $ERRORS{$result};
95
96sub print_usage () {
97 print "Usage:\n";
98 print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] -f <file>\n";
99 print " $PROGNAME [-h | --help]\n";
100 print " $PROGNAME [-V | --version]\n";
101}
102
103sub print_help () {
104 print_revision($PROGNAME, '$Id$');
105 print "Copyright (c) 2003 Steven Grimm\n\n";
106 print_usage();
107 print "\n";
108 print " <secs> File must be no more than this many seconds old\n";
109 print " <size> File must be at least this many bytes long\n";
110 print "\n";
111 support();
112}