When setting up your own home server then proper monitoring system is the one of most important things you want to do. Monit is a monitoring tool I decided to use. It's easy to configure but still very powerful. I also decided to use ZFS filesystem on my server. It's a bit more advanced than ext4 or ntfs thus there is more things to check regarding your pools health.
Thankfully I found very cool ZFS health check script on Calomel.org that sends email if something is wrong with any of the pools. I decided to adjust it a bit to work well with Monit.
Script, to be able to be run by Monit, needs to return exit code instead of sending an email. Next difference is that in bellows script lines 126 and 127 are uncommented (and lines 130 and 131 commented). This is to support Ubuntu date format. If you want to use this script on FreeBSD then you want these lines to look like in the original script. Next thing is that, in the beginning of the script, I added support for input parameters for max capacity and scrub expiration of your zpools. This is in order to keep configuration in one place (i.e. Monit's configuration file). Last but not least is the "Output for monit user interface" section. As its title says it outputs zpool status to the console so it could be recorded by Monit and displayed in its user interface.
To use the script go to your monitrc file and add following lines:
Where80
is the max capacity in percentages and 691200
is the scrub expiration in seconds. This will make Monit notify you everytime something is wrong with your zpool. As a bonus you will get nice status with last script run output on the web user interface:
If you don't see the whole output for your zpools then you probably need to set higher PROGRAMOUTPUT
limit in monitrc
file. The default one is 512 bytes.
The script is also available as Github Gist.
Comments
I tried your script, works perfectly from command line. But apparently Monit does not support passing arguments to the scripts, i wonder how you got this running? this is my status output:
´Missing arguments
Usage: zfs_health_check.sh maxCapacityInPercentages scrubExpireInSeconds´
when running like this
´check program zfs_health with path "/bin/bash -c /root/monit_scripts/zfs_check.sh 80 691200"
if status != 0 then alert´