Check Apple RAIDs and email when there is a problem

This script can be used in a cron which runs every 5 or 10 minutes and will email as soon as it detects an issue with an Apple RAID.
I am working on an Apple XServe RAID checker, but this one will handle internal drive bay RAIDs.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##EMAIL_OF_RECIPIENT##']

raidstatus = os.popen('/usr/sbin/diskutil listRaid')
status = raidstatus.read()
raidstatus.close()
if status.find('Degraded') > -1:
     smtpsubject = 'WARNING - Raid degraded on ' + gethostname()
     smtp = smtplib.SMTP(smtpserver)
     message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, status)
     smtp.sendmail(smtpfrom, smtpto, message)
     smtp.quit()

Check OSX partitions and email results

I wrote a small Python script which gets a list of partitions and checks each one to make sure the partition is okay, and for the script to email the results.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##recipient email##']

driveshandle = os.popen('/bin/df -h | grep disk')
drives = driveshandle.read()
driveshandle.close()
drives = drives.split('\n')

for drive in drives:

     diskinfo = ''
     if drive.find('dev') > -1:
          partition = drive.split(' ')
          print 'Drive ' +partition[0]
          fsck = os.popen('/sbin/fsck_hfs -fy ' + partition[0])
          diskinfo = fsck.read()
          fsck.close()
          smtpsubject = 'File System Checks for ' + gethostname() + ', drive ' + drive
          smtp = smtplib.SMTP(smtpserver)
          message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, diskinfo)
          smtp.sendmail(smtpfrom, smtpto, message)
          smtp.quit()

print 'completed'

OSX Command Line Goodies

You can take a screenshot by command:

screencapture -C ~/screen.png

This will save a screenshot into the user’s home folder.

You can get system information:

/usr/sbin/system_profiler SPHardwareDataType

Which would show something like this:
Hardware:

Hardware Overview:

Model Name: iMac
Model Identifier: iMac8,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.66 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 6 MB
Memory: 4 GB
Bus Speed: 1.07 GHz
Boot ROM Version: IM81.00C1.B00
SMC Version (system): 1.29f1
Serial Number (system): VM906KT5ZE3
Hardware UUID: FB5DEAE0-DAB6-56DD-A62B-0F38C384654A

Speaking- You can make the computer speak by commandline:

say -v Albert "Hello world"

Albert can be replaced with any of the following:

Agnes,Albert,BadNews,Bahh,Bells,Boing,Bruce,Bubbles,Cellos,Deranged,Fred,GoodNews,Hysterical,Junior,Kathy,Organ,Princess,Ralph,Trinoids,Vicki,Victoria,Whisper,Zarvox

Automatic checking of IMAP subfolders in Thunderbird

Open up the preferences dialog (either Tools -> Preferences or Edit -> Preferences), and click Advanced -> General -> Config Editor.
In the filter box type ‘mail.check’ and double click on mail.check_all_imap_folders_for_new.

That should do it..

The Dreadnought Framework

A friend of mine and I are working on a pretty impressive project which will hopefully fill a niche in the IT market.
Its a pretty impressive amount of work, but we are both up for a challenge, and the chance to sink a few beers on a project meeting will be a necessity.

One major milestone has been completed – the Dreadnought framework. Its basis is two files – index.php and _dreadnought.php. All heavy duty code is held in the dreadnought kernel – accessable through $dreadnought. Its very very simple. No access control, basic MySQL support but has a promising future.

I am developing a ‘blogging’ module into it, and hopefully will move this site from wordpress into Dreadnought in the not too distant future.

The one thing I really love about the way I have designed dreadnought is that the templating system could not be easier. You have a html file and just add the tag <DREADNOUGHT_CONTENT /> and the code does the rest.
I’m hoping to release the framework as open source soonish, but not until some more work has gone into it, including some rudimentary pre-flight checking of modules – ie to prevent a module from killing the framework’s kernel.