Sunday, March 20, 2011

Monitoring zpool with email alert «Solaris 11 Express»

Crontab job to scrub zpool once a week and check zpool status

45 3 * * 0 /usr/sbin/zpool scrub MydataZpool

45 3 * * 1 /usr/sbin/zpool scrub rpool

15 8 * * * /pathToperlScript/Zpool_check

Perl script to send email alert when zpool is not healthy

«Zpool_check»

#!/usr/bin/perl

my $command_output = `zpool status -x`;

if ($command_output eq "all pools are healthy\n") {

print "all pools are healthy";

exit;

}

else

{

print "zpool not healthy";

$to='MYEMAIL@MYPROVIDER.com';

$from= 'alert@MYDOMAIN.COM';

$subject='zfs alert';

open(MAIL, "/usr/sbin/sendmail -t");

## Mail Header

print MAIL "To: $to\n";

print MAIL "From: $from\n";

print MAIL "Subject: $subject\n\n";

## Mail Body

print MAIL "Zfs alert \n";

print MAIL $command_output;

close(MAIL);

}

Configure sendmail if not already done...

Add this line to “/etc/mail/cf/cf/sendmail.mc”

DOMAIN(`solaris-generic')dnl

define(`SMART_HOST', `SMTP.MYPROVIDER.com')

define(`confFALLBACK_SMARTHOST', `mailhost$?m.$m$.')dnl



No comments: