Scripts to email you if pool is degraded

Moderators: jhartley, MSR734, nola

Scripts to email you if pool is degraded

Post by elfpltfn » Sat Sep 29, 2012 2:05 pm

Per request, HERE is my zfs integrity checker with installation instructions.

The script checks the status of my pool every 15 minutes, and emails me if the pool is degraded, offline, etc (anything but online for every disk).

The script detects degradation by counting the number of "ONLINE"s in zpool status, and if its not the expected count, it triggers an automator "program" to email you. Launchd triggers the script.

**There are apparently issues with 10.8 and automator- to fix just delete the add attachment step in the automator workflow.**
elfpltfn Offline


 
Posts: 23
Joined: Fri Sep 14, 2012 9:52 pm

Re: Scripts to email you if pool is degraded

Post by si-ghan-bi » Sat Sep 29, 2012 6:18 pm

Modified to use Perl and to print in the output file only the info about the pools with anomalies. At the time being this means status not "ONLINE" or errors different from "No known data errors".

Tested against ZEVO 1.1.1.

Code: Select all
#!/bin/perl

# Check ZFS pools for errors or anomalies. Sends the output to a tmp file.
# Version 1.0, 2012-09-29

# Missing the option to activate notification of resilvering and similar.
# It would print the output if the "status" line is being shown (independently
# from the "state" line).

use strict;

# Options you may change
my $command_status = 'zpool status -v';
my $output_file    = '/tmp/ZFS_STATUS.txt';

# End of configurable options
my $current_message = '';
my $whole_message = '';
my $pool_has_errors = 0;
open(PIPE, "$command_status |") || die "I couldn't execute the '$command_status': $!\n";
while (<PIPE>) {
   if (/^\s*pool: (.+)\n$/) {
      if ($pool_has_errors) {
         $whole_message = $whole_message . $current_message;
         $pool_has_errors = 0;
      }
      $current_message = '';
   }
   $current_message = $current_message . $_;
   if (/^\s*state: (\w+)\n$/) {
      if ($1 ne 'ONLINE') {
         $pool_has_errors = 1;      
      }
   }
   if (/^\s*errors: (.*)\n$/) {
      if ($1 ne 'No known data errors') {
         $pool_has_errors = 1;      
      }
   }
}
close(PIPE);
if ($pool_has_errors) {
   $whole_message = $whole_message . $current_message;
}

open(OUTPUT, '>', $output_file) || die "I couldn't open '$output_file' for writing: $!\n";
print OUTPUT $whole_message;
close(OUTPUT);
si-ghan-bi Offline


 
Posts: 145
Joined: Sat Sep 15, 2012 5:55 am


Return to General Discussion

Who is online

Users browsing this forum: ilovezfs and 1 guest

cron