Skip to content

Commit 2f0ac2f

Browse files
committed
Add some check scripts, make ncpa package name easier to change
1 parent e81e349 commit 2f0ac2f

9 files changed

Lines changed: 1265 additions & 1 deletion

defaults/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
ncpa_packages:
1+
ncpa_package:
22
- ncpa
3+
4+
nagios_plugin_packages:
35
- nagios-plugins
46
- nagios-plugins-disk
57
- nagios-plugins-load
@@ -8,6 +10,8 @@ ncpa_packages:
810
- nagios-plugins-procs
911
- nagios-plugins-swap
1012
- nagios-plugins-users
13+
14+
ncpa_packages: "{{ ncpa_package + nagios_plugin_packages }}"
1115

1216
ncpa_repo_package_url: https://repo.nagios.com/nagios/7/nagios-repo-7-4.el7.noarch.rpm
1317

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
FINDARGS=$1
4+
WARN=$2
5+
CRIT=$3
6+
7+
find_bin=$(which find)
8+
if [ $? -ne 0 ] ; then
9+
echo "UNKNOWN - No find in PATH"
10+
exit 3
11+
fi
12+
# use find...
13+
rc=$($find_bin $FINDARGS |wc -l)
14+
if [ $rc -lt $CRIT ] ; then
15+
echo "CRIT - less than $CRIT files match"
16+
exit 2
17+
elif [ $rc -lt $WARN ] ; then
18+
echo "WARN - less than $WARN files match"
19+
exit 1
20+
fi
21+
22+
echo "OK - $rc files match"
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/perl -w
2+
3+
# check_file_age.pl Copyright (C) 2003 Steven Grimm <koreth-nagios@midwinter.com>
4+
#
5+
# Checks a file's size and modification time to make sure it's not empty
6+
# and that it's sufficiently recent.
7+
#
8+
#
9+
# This program is free software; you can redistribute it and/or
10+
# modify it under the terms of the GNU General Public License
11+
# as published by the Free Software Foundation; either version 2
12+
# of the License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty
16+
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# you should have received a copy of the GNU General Public License
20+
# along with this program (or with Nagios); if not, write to the
21+
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22+
# Boston, MA 02110-1301, USA
23+
24+
use strict;
25+
use English;
26+
use Getopt::Long;
27+
use File::stat;
28+
use vars qw($PROGNAME);
29+
use FindBin;
30+
use lib "$FindBin::Bin";
31+
use lib '/usr/lib64/nagios/plugins';
32+
use utils qw (%ERRORS &print_revision &support);
33+
34+
sub print_help ();
35+
sub print_usage ();
36+
37+
my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V, $opt_i);
38+
my ($result, $message, $age, $size, $st, $perfdata, $output, @filelist, $filename);
39+
40+
$PROGNAME="check_file_age";
41+
42+
$ENV{'PATH'}='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin';
43+
$ENV{'BASH_ENV'}='';
44+
$ENV{'ENV'}='';
45+
46+
$opt_w = 240;
47+
$opt_c = 600;
48+
$opt_W = 0;
49+
$opt_C = 0;
50+
$opt_f = "";
51+
52+
Getopt::Long::Configure('bundling');
53+
GetOptions(
54+
"V" => \$opt_V, "version" => \$opt_V,
55+
"h" => \$opt_h, "help" => \$opt_h,
56+
"i" => \$opt_i, "ignore-missing" => \$opt_i,
57+
"f=s" => \$opt_f, "file" => \$opt_f,
58+
"w=f" => \$opt_w, "warning-age=f" => \$opt_w,
59+
"W=f" => \$opt_W, "warning-size=f" => \$opt_W,
60+
"c=f" => \$opt_c, "critical-age=f" => \$opt_c,
61+
"C=f" => \$opt_C, "critical-size=f" => \$opt_C);
62+
63+
if ($opt_V) {
64+
print_revision($PROGNAME, '2.2.1');
65+
exit $ERRORS{'OK'};
66+
}
67+
68+
if ($opt_h) {
69+
print_help();
70+
exit $ERRORS{'OK'};
71+
}
72+
73+
$opt_f = shift unless ($opt_f);
74+
75+
if (! $opt_f) {
76+
print "FILE_AGE UNKNOWN: No file specified\n";
77+
exit $ERRORS{'UNKNOWN'};
78+
}
79+
80+
$opt_f = '"' . $opt_f . '"' if $opt_f =~ / /;
81+
82+
# Check that file(s) exists (can be directory or link)
83+
$perfdata = "";
84+
$output = "";
85+
@filelist = glob($opt_f);
86+
87+
foreach $filename (@filelist) {
88+
unless (-e $filename) {
89+
if ($opt_i) {
90+
$result = 'OK';
91+
print "FILE_AGE $result: $filename doesn't exist, but ignore-missing was set\n";
92+
exit $ERRORS{$result};
93+
94+
} else {
95+
print "FILE_AGE CRITICAL: File not found - $filename\n";
96+
exit $ERRORS{'CRITICAL'};
97+
}
98+
}
99+
100+
$st = File::stat::stat($filename);
101+
$age = time - $st->mtime;
102+
$size = $st->size;
103+
$perfdata = $perfdata . "age=${age}s;${opt_w};${opt_c} size=${size}B;${opt_W};${opt_C};0 ";
104+
105+
$result = 'OK';
106+
107+
if (($opt_c and $age > $opt_c) or ($opt_C and $size < $opt_C)) {
108+
$result = 'CRITICAL';
109+
}
110+
elsif (($opt_w and $age > $opt_w) or ($opt_W and $size < $opt_W)) {
111+
$result = 'WARNING';
112+
}
113+
114+
$output = $output . "FILE_AGE $result: $filename is $age seconds old and $size bytes ";
115+
116+
}
117+
118+
print "$output | $perfdata\n";
119+
120+
exit $ERRORS{$result};
121+
122+
sub print_usage () {
123+
print "Usage:\n";
124+
print " $PROGNAME [-w <secs>] [-c <secs>] [-W <size>] [-C <size>] [-i] -f <file>\n";
125+
print " $PROGNAME [-h | --help]\n";
126+
print " $PROGNAME [-V | --version]\n";
127+
}
128+
129+
sub print_help () {
130+
print_revision($PROGNAME, '2.2.1');
131+
print "Copyright (c) 2003 Steven Grimm\n\n";
132+
print_usage();
133+
print "\n";
134+
print " -i | --ignore-missing : return OK if the file does not exist\n";
135+
print " <secs> File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n";
136+
print " <size> File must be at least this many bytes long (default: crit 0 bytes)\n";
137+
print "\n";
138+
support();
139+
}

0 commit comments

Comments
 (0)