/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_writable_filesystem
ViewVC logotype

Diff of /trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_writable_filesystem

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1592 by ronalds, Mon Mar 22 17:09:49 2010 UTC revision 1593 by ronalds, Mon Mar 29 11:43:05 2010 UTC
# Line 2  Line 2 
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;
# Line 34  if ( scalar @ARGV < 1 ) { Line 33  if ( scalar @ARGV < 1 ) {
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");
# Line 107  sub check_writable_filesystem { Line 109  sub check_writable_filesystem {
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      }      }

Legend:
Removed from v.1592  
changed lines
  Added in v.1593

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28