1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #!/usr/bin/perl -w
#########################################################################
#
# File: check_fs_readable.pl
#
# Description:
# This nagios plugin is a very simple minded check to determine
# if a mounted file system is writable. This was written in reaction
# to chronic issues with my VPS provider having SAN issues that
# manifested themselves in the root file system suddenly becoming
# read only. Since the VPSes in question were all built with
# a singular file system having root go read only caused all the
# applications on the box to come to a screaching halt.
#
# This plugin is meant to be run locally on a system or from nrpe.
#
# Logic: Attempt to cwd to /tmp and attempt to open a file for writing.
# If either fail, sound the alarm.
#
# Version: 0.5
#
# Author: Peter L. Berghold <salty.cowdawg@gmail.com>
#
# License: GPL
#
# CAVEATS: optionally you can provide an alternative directory to check. Make
# certain that whatever userid nagios is running as can write to that
# directory so you do not get false positives.
#
########################################################################
use strict;
use Getopt::Long;
use constant {
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3
};
use constant RETCODES => qw ( OK WARNING CRITICAL UNKNOWN ) ;
my $testdir = "/tmp";
my $res = GetOptions("dir=s" => \$testdir );
chdir $testdir or crap_out(CRITICAL,"Could not cwd to $testdir");
my $fname = "foo.$$.txt";
open FOUT,"> $fname" or crap_out(CRITICAL,"Could not to write to file system");
close FOUT;
unlink($fname);
printf "OK: File System Normal\n";
exit(OK);
sub crap_out{
my ($rc,$msg)=@_;
} |
Partager