Build precise queries to find exactly what you need
Press ESC to close
Join our next live webinar: “Advanced Nagios Monitoring Techniques” – Register Now
Your review has been submitted and is pending approval.
Check to see if a file system is writable.
Current Version
0.5b
Last Release Date
2012-02-29
Owner
Peter L. Berghold
License
GPL
Compatible With
Perl script; check file system writability
######################################################################### # # 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 # # 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. # ########################################################################
It seems strange that half of the script is just comments. I replaced it with this script: #!/usr/bin/perl -w use strict; use Getopt::Long; use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 }; use constant RETCODES => qw ( OK WARNING CRITICAL UNKNOWN ) ; use File::Temp qw/ tempfile tempdir /; sub error { my ($rc,$msg)=@_; printf "%s: %s ",(RETCODES)[$rc],$msg; exit($rc); } my $dir; if($ARGV[0]){ $dir = $ARGV[0]; }else{ error(UNKNOWN,"No input, specify a directory") } my $tmp = File::Temp->new( DIR => $dir ); chdir $dir or error(CRITICAL,"Could not cwd to $dir"); open FOUT,"> $tmp" or error(CRITICAL,"Could to write to $dir"); close FOUT; printf "OK: $dir is writable. "; exit(OK);
You must be logged in to submit a review.
To:
From: