2 |
|
|
3 |
# Nagios probe to verify that a file system is writable |
# Nagios probe to verify that a file system is writable |
4 |
# This is verified by first inspecting the information from /proc/mounts |
# This is verified by first inspecting the information from /proc/mounts |
5 |
# If the file system is mounted rw, then it is attempted to create a file on it and |
# If the file system is mounted rw, then it is attempted to create a file on it |
|
# read the contents of the file back |
|
6 |
|
|
7 |
use strict; |
use strict; |
8 |
use Getopt::Long; |
use Getopt::Long; |
33 |
} |
} |
34 |
my $filesystem = $ARGV[0]; |
my $filesystem = $ARGV[0]; |
35 |
|
|
36 |
|
# remove trailing slashes or the match against /proc/mounts will fail |
37 |
|
$filesystem =~ s!\/*$!!; |
38 |
|
|
39 |
# Just in case of problems, let's not hang Nagios |
# Just in case of problems, let's not hang Nagios |
40 |
$SIG{'ALRM'} = sub { |
$SIG{'ALRM'} = sub { |
41 |
print ("ERROR: No response from $hostname (alarm timeout)\n"); |
print ("ERROR: No response from $hostname (alarm timeout)\n"); |
109 |
$msg = "Cannot write to $file: $!"; |
$msg = "Cannot write to $file: $!"; |
110 |
$res = $ERRORS{CRITICAL}; |
$res = $ERRORS{CRITICAL}; |
111 |
} |
} |
112 |
else { |
# Do not write anything because that may fail if the disk is full! |
|
print WRT "$now"; |
|
|
} |
|
113 |
close WRT; |
close WRT; |
114 |
} |
} |
115 |
|
|
|
# read contents back from file |
|
|
if ( $res == $ERRORS{OK} ) { |
|
|
if ( ! open RD, "$file" ) { |
|
|
$msg = "Cannot read from $file: $!"; |
|
|
$res = $ERRORS{CRITICAL}; |
|
|
} |
|
|
else { |
|
|
my $line = <RD>; |
|
|
if ( $line !~ /$now/ ) { |
|
|
$msg = "Read $line but expected $now"; |
|
|
$res = $ERRORS{CRITICAL}; |
|
|
} |
|
|
else { |
|
|
$verbose and print STDERR "Successfully read back contents\n"; |
|
|
} |
|
|
} |
|
|
close RD; |
|
|
unlink $file; |
|
|
} |
|
|
|
|
116 |
if ( $res == $ERRORS{CRITICAL} ) { |
if ( $res == $ERRORS{CRITICAL} ) { |
117 |
$msg = "ERROR: $msg"; |
$msg = "ERROR: $msg"; |
118 |
} |
} |