Skip to content

Twitter as a sysadmin tool?

December 13, 2009

After the disk failures I have suffered I have decided to start using twitter monitor the health of my home server and network as this is easier to pick up than on my phone email. Also it provides a nice log.

Using a modified version of the command line twitter script http://blogs.sun.com/sandip/entry/tweeting_from_command_line_using modified so that it will read the account information from a file. I have changed the standard script I have for watching the system to use twitter rather than email to notify me of issues. It posts to the twitter account “syslogathome” which I now follow, you can too but I’m sure you won’t want to.

My script to check things is here.

#!/bin/ksh

export PATH=/usr/sbin:/usr/bin

function tweet
{
        echo tweeting $1
        /usr/local/bin/tweet.py "$1"
}
function tweet_services
{
        typeset zone="$1 "
        if [[ "$1" != "global" ]]
        then
                typeset zl="pfexec zlogin $1 "
        else
                typeset zl=""
        fi
        ${zl}svcs -x | nawk '/^svc:/ { s=$0 } /^Reason:/ { print s,$0 }' | while read line
        do
                tweet "$zone$line"
        done
}
function tweet_zfs
{
        zpool list -H -o name,health | while read zfs state
        do
                [[ "$state" != "ONLINE" ]] && tweet "$zfs $state"
        done
}
function tweet_disks
{
        export IFS="    "
        kstat -p -m sderr -s "Predictive Failure Analysis" | while read err value
        do
                (( $value != 0 )) && tweet "$err     $value"
        done
}
function tweet_net
{
        typeset speed=$(dladm show-linkprop -co VALUE -p speed nge0)
        if (( $speed != 1000 ))
        then
                tweet "network running in degraded state $speed" 
        fi
}
function tweet_phone
{
        if ! ping phone 1 > /dev/null 2>&1
        then
                tweet "Phone is not responding"
        fi
}

for zone in $(zoneadm list)
do
        tweet_services $zone
done
tweet_zfs
tweet_disks
tweet_net
tweet_phone
Advertisements

From → Solaris

One Comment
  1. Brian McManus permalink

    Very simple way to build a monitoring system with alerts! Great work.
    I use Nagios with a check_zfs application. I get an email and a text but only because I know my phones att.net SMS address.
    Your solution is much more "fun."

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: