Automatic email alerting of zpool problems and weekly zpool scrub
Since I’m using consumer drives that are prone to failure (one already failed within 2 days, but ZFS prevented any data loss).
I am using the script located here:
http://www.sun.com/bigadmin/scripts/submittedScripts/zpadmin.txt.
This will script allows for regular monitoring and scrubs of the pool with email alerting.
These next bunch of steps may not be necessary for everyone. I’m essentially setting up sendmail to use a smarthost. Even if you do need to use a smarthost, there may be an easier way by just modifying one line in the script.
Set smarthost for sendmail email delivery since ATT blocks outgoing port 25 on home DSL connections.
Steps learned from:
- http://www.elandsys.com/resources/sendmail/
- http://wiki.xdroop.com/space/sendmail/smart+host+ports
- http://www.dslreports.com/faq/11247
Edited sendmail.mc
cd /usr/lib/mail/cf
nano sendmail.mc
This line only needed if relay not using port 25:
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
Added:
define(`RELAY_MAILER',`esmtp')dnl
define(`SMART_HOST', `relay:[SmartHostAddressGoesHere]')dnl
Commented out by adding # the followng line:
#define(`confFALLBACK_SMARTHOST', `mailhost$?m.$m$.')dnl
Then at the command line:
m4 /usr/lib/mail/m4/cf.m4 sendmail.mc > /etc/mail/sendmail.cf
Restarted sendmail
svcadm restart sendmail
Then I had to get the script working:
Steps taken:
- Created a directory called scripts
- downloaded the script
- renamed it
- set it to be executable
- edited settings
- scheduled with cron
mkdir /scripts
cd /scripts
wget http://www.sun.com/bigadmin/scripts/submittedScripts/zpadmin.txt
mv zpadmin.txt zpadmin.pl
chmod ug+x zpadmin.pl
Edit script. Need to at minimum change:
my $log_path=
Set mine to "/var/log/zpool_adm_log"
my $mailto =
I had to set my $mailhost = "127.0.0.1" might be due to some sort of misconfiguration on my end. This also means that some of the steps above for configuring the smarthost could have been avoided. I still think they are worthwhile because sendmail may be needed to send other sorts of alerts in the future.
Add to cron:
crontab -e
Crontab uses vi, so we need to enter:
G goes to last line of file
o opens new line after line you’re on and gets you into edit mode
Enter the following. Feel free to omit the commented lines if you’d like.
# ZPOOL MONITOR ->
0 * * * * /scripts/zpadmin.pl
# ZPOOL WEEKLY SCRUB ->
0 5 * * 0 /scripts/zpadmin.pl -scrub
Press Esc to get out of edit mode
Then :wq which tells vi to write the file and then quit.
Now your pools will be checked every hour and will be scrubbed once a week on Sunday at 5AM.
See cron on Wikipedia for more information.
September 5th, 2009 at 2:33 pm
[...] Automatic email alerting of zpool problems and weekly zpool scrub Using MDNS to advertise OpenSolaris NAS to Mac computers This entry was posted on Sunday, August 30th, 2009 at 6:42 pmand is filed under Open Source, Storage. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. [...]
March 20th, 2010 at 1:00 pm
I had a problem with OpenSolaris giving errors with the cron job:
“Can’t exec “zpool”: No such file or directory at
zpadmin.pl line 44.
Use of uninitialized value in string eq at zpadmin.pl
line 45.
Use of uninitialized value in split at zpadmin.pl
line 48.
Use of uninitialized value in string eq at zpadmin.pl
line 123.”
I contacted the script’s creator, Paul, who informed me the reason for the errors was probably because zpool is not in cron’s PATH. However, when I tried to set PATH=/usr/sbin as line in crontab, the system didn’t like this and wouldn’t let me save the file. Instead, I had to change every instance of the “zpool” command in the script to “/usr/sbin/zpool”, which fixed the problem and allowed me to run the script in cron. If anyone knows how to set PATH in cron/crontab feel free to chime in, otherwise this fix should work.
Also, guest comments should be enabled
April 1st, 2010 at 10:42 pm
Geoff,
I really wish I could enable guest comments. The problem is there are too many spambots out there trying to add links in blog posts for search engine optimization. I don’t want to help them out.
What release of OpenSolaris are you using?