Wednesday, January 18, 2012

Getting Promise Pegasus to actually email you in case of drive failure

UPDATE: ContrarySheep (e.g. GriffithStudio) has posted an excellent update to these scripts that take advantage of launchd to run these processes. See this gist for more information.

So the Promise Pegasus thunderbolt external storage array is a super piece of hardware for the price. One thing they list as a feature is the ability to email a user in case of a drive failure. One problem, though, is that I could not get this to work for me.

A nice feature of the system, though, is that the included Promise Utility GUI that ships with the array also installs quite a full featured command line utility. For instance, you can get a quick report of the drives in the array by issuing the following:


$ promiseutil -C phydrv
===============================================================================
PdId Model Type Capacity Location OpStatus ConfigStatus
===============================================================================
1 Hitachi HDS7 SATA HDD 2TB Encl1 Slot1 OK Array0 Seq. No.0
2 Hitachi HDS7 SATA HDD 2TB Encl1 Slot2 OK Array0 Seq. No.1
3 Hitachi HDS7 SATA HDD 2TB Encl1 Slot3 OK Array0 Seq. No.2
4 Hitachi HDS7 SATA HDD 2TB Encl1 Slot4 OK Array0 Seq. No.3
5 Hitachi HDS7 SATA HDD 2TB Encl1 Slot5 OK Array0 Seq. No.4
6 Hitachi HDS7 SATA HDD 2TB Encl1 Slot6 OK Array0 Seq. No.5
view raw example.out.txt hosted with ❤ by GitHub


w00t!


I wrote a quick little Ruby script to grab the drive information and send me an email in case the status is not "OK".

#!/usr/bin/env ruby
`promiseutil -C phydrv`.split(/\n/).each do |l|
next unless l =~ /^\d/
unless l =~ /OK/
# email a warning to the user
system "echo \"PEGASUS 1: BAD DRIVE \n\n #{l}\" | mail -s 'ERR: PEGASUS 1' angel@upenn.edu"
end
end


DISCLAMIER: This snippet is provided as-is. I am not guaranteeing this works at all, and is using the assumption that the status will change from "OK" to something else if there is an issue with a drive. Use at your own risk.