A good script or program for status notification?

Hi all,

I am new to ZFS and have been using it in my arch installation with a raidz setup. I'm guessing there are a lot of users of ZFS here that have more information than I do and to these users I ask:

Are there any good scripts or status notification programs that you have which will email you when a device fails on raidz? The possibly also take care of zpool scheduled scrubbings? And anything else I have missed.

Thanks & I hope this helps other novice users!

Posted Mar 9, 2013, 10:13 PM UTC

13
Gonffed•

Here's what I use to report into Nagios, so far it's caught everything I've seen to date. Feel free to modify it as needed to generate e-mails.

#!/usr/bin/perl

# Taken from nagrepclient
$| = 1;

sub usage() {
        print <<"EOM";
 
Usage:  $0 -h <remotehost> -p <remoteport> -f <authkeyfile> [ -d ] [-n]
 
        -h <remotehost> Host to report data to
        -p <remoteport> Port
	-n Print nagios_report details to stdout with sending to remote host
EOM
}

# Defaults
$DEBUGMODE = 0; $KEYFILE = $AUTHKEY = $FAKE = undef;

while ($arg = shift(@ARGV)) {
    if ($arg =~ /^-h$/) {
	$LOG_HOST = shift(@ARGV);
    } elsif ($arg =~ /^-p$/) {
	$LOG_PORT = shift(@ARGV);
    } elsif ($arg =~ /^-d$/) {
	$DEBUGMODE = 1;
    } elsif ($arg eq "-f") { 
	$KEYFILE = shift(@ARGV); 
    } elsif ($arg eq "-c") { 
	$PATH_CONFIG = shift(@ARGV); 
    } elsif  ($arg eq "-n") {
	$FAKE = 1;
    } else {
	&usage(); exit(-1);
    }
}

$NAGIOS_REPORT = "/software/common/adm/nagios_report";

$nagios_report_opts = "";
$nagios_report_opts .= "-a $KEYFILE " if $KEYFILE;
$nagios_report_opts .= "-p $LOG_PORT " if $LOG_PORT;
$nagios_report_opts .= "-s $LOG_HOST " if $LOG_HOST;
$nagios_report_opts .= "-n " if $FAKE;
$nagios_report_opts .- "-v " if $DEBUGMODE;

#
# Check all zpools and report errors
#

open ZPOOLS, "/usr/sbin/zpool list | /bin/awk '{print \$1}' | /bin/grep -v NAME|";

$STATE_OK = 0; 
$STATE_WARN = 1;
$STATE_CRIT = 2;
$STATE_UNK = 3;

$code = $STATE_OK;
$status = "";

foreach $zpool (<ZPOOLS>) {
    $zpool =~ s/\n//g;
    $zpool_status = `/usr/sbin/zpool status -x $zpool`;

    if($zpool_status =~ /healthy/) { next; }


    $zpool_status =~ /state:(.*\n)/;
    $pool_state = $1;

    $zpool_status =~ /status:([\s\S]*)action:/;
    $pool_status = $1;
    $pool_status =~ s/\n//g;

    if($pool_state =~ /ONLINE/) {
        if($pool_status =~ /formatted using an older/) {
          $status .= "## $zpool is using an old zpool version ##";
        }

	if($pool_status =~ /corruption/) {
	    $code = $STATE_WARN unless $code >= $STATE_CRIT;
	    $status .= "## $zpool has data corruption. Restore files or the entire pool ASAP ##";
	}


	# Add other ONLINE status errors here
        next;
    }

    if($pool_state =~ /DEGRADED/) {
	$code = $STATE_WARN unless $code >= $STATE_CRIT;

	if($pool_status =~ /One or more devices has been taken offline/ ||
           $pool_status =~ /One or more devices has been removed/       ||
	   $pool_status =~ /One or more devices are faulted/										  ) {
	    $status .= "## $zpool has a failed device. Replace ASAP ##";

	    # Elevate to Critical for failed disk
	    $code = $STATE_CRIT;
	}
	
	if($pool_status =~ /currently being resilvered/) {
	  $status .= "## $zpool is being resilvered; no action needed ##";
        }

	if($pool_status =~ /label is missing or invalid/) {
	  $status .= "## $zpool has a disk with a corrupt label; Fix label ASAP ##";
        }
	
	# Add other DEGRADED status errors here
	next;
    }

    if($pool_state =~ /FAULTED/) {
	$code = $STATE_CRIT;
	
	if($pool_status =~ /metadata is corrupted/) {
	    $status .= "## $zpool FAULTED due to damaged data or devices ##";
	}

	# Add other FAULTED status errors here
	next;
    }

    if($pool_state =~ /UNAVAIL/) {
	$code = $STATE_CRIT;

	if($pool_status =~ /IO failure/) {
	    $status .= "## $zpool UNAVAILABLE due to IO failures ##";
	}

	# Add other UNAVAIL status errors here
	next;
    }    
}

$status = "All pools are healthy." if $status eq "" and $code == $STATE_OK;
$status = "Unknown error occurred - please see zpool status -xv on the system." if $status eq "" and $code > $STATE_OK;

print "$NAGIOS_REPORT $nagios_report_opts ZPOOLSTATUS $code \"$status\"\n" if $DEBUGMODE;
system("$NAGIOS_REPORT $nagios_report_opts ZPOOLSTATUS $code \"$status\"")    
5
DevotedfollowerOP•

many thanks for posting this!

1
yagobg•

Take a look at nappit . Does what you want and more

2