No Node Left Behind

Currently Being Moderated

twitter_logo_header.png

This month's tip comes from Zenoss Community member Stacy Uden that shows how to take advantage of the flexibility of Event Commands within Zenoss. Event Commands allow the system to run arbitrary shell commands when events occur that match pre-configured criteria. This allows almost any action to be taken in response to events that occur. Common uses of event commands include:

  • Auto-remediation of events. You can use SSH to remotely restart services on a UNIX system when they fail, or winexe to do the same for Windows services.
  • Integration with external systems. This includes sending SNMP traps to other management systems, or opening tickets in your incident management system.
  • Extending alerting mechanisms. Currently Zenoss supports only email and pagers as alerting mechanisms "out of the box" through normal alerting rules. You could use event commands to alert through instant messaging systems, SMS or even by playing sounds.

Stacy gives us the great following example in his Wiki article Tweet out Events to Twitter, using Twitter to republish events from Zenoss:

Here is a handy & simple way to convert events into tweets with an Event Command and a bash script. This uses the Twitter API and doen't require anything other than bash and curl.

 

First, set up a dedicated, private twitter account. A private account is recommended as to not share your infrastructure status to the world, but your preferences may vary. Using your own personal account, follow this new account (and of course from the new private account, you have to "accept" the follow request).

 

Second, put this script somewhere convenient like $ZENHOME/scripts. Name it "tweet.sh" and set it to be owned by the "zenoss" user and executable.

 

---Start script

#!/bin/bash

 

# This script takes in a message and sends it out as a Twitter tweet.

 

user="Twitter_user_account_here"
pass="Twitter-acct-password-here"
curl="/usr/bin/curl"

 

$curl --basic --user "$user:$pass" --data-ascii \
"status=`echo $@`" \
"
http://twitter.com/statuses/update.json" \
>& /dev/null

 

exit 0

---End Script

 

Third, set up an Event Command, setting the filters to taste. The command would be:

 

$$ZENHOME/scripts/tweet.sh ${evt/device} -- ${evt/summary}

and the clear command might be

$$ZENHOME/scripts/tweet.sh CLEAR ${evt/device} -- ${evt/summary}

 

Of course you can edit this command with whatever parameters you prefer, but beware of the 140 character Twitter limit.

 

 

Now, if you have your cell phone linked to your personal Twitter account, you can have another way to have events sent to you via SMS. It is also a nice way to send events to multiple people without taxing the Zenoss main server. Have your co-workers follow the new private account, and approve their requests.

Thanks again for the write-up Stacy!

4,259 Views Tags: tips, tip, events, tip-of-the-month, event, notifications, command, twitter, notification


Aug 23, 2010 12:48 PM MacSEK MacSEK    says:

great! works fine for me!!

Aug 24, 2010 3:46 AM MacSEK MacSEK    says:

Hi everybody,

 

nice script. I made a litte modification. Because i use an iPhone i want to get push notifications. so what i did is, I set up a second twitter account. Both accounts have to follow each other, so you can send direct messages between them. now i added:

 

seconduser="the_second_twitter_account_i_want_messages_sent_to"

 

and i added a second curl-line to create the direct message:

 

$curl -u $user:$pass -d "text=`echo $@`&user=$seconduser" http://twitter.com/direct_messages/new.xml >& /dev/null

 

Now with an iphone app that support twitter direct messages with push i got the update right to my iphone.

 

Hope you like it!

 

MacSEK

Aug 30, 2010 7:12 AM MacSEK MacSEK    says in response to MacSEK:

Hi,

 

i like this twitter thing but i had a problem with. sometimes i got some error tickets when the script was running. These errors where cause by some event summary / device names that contained brackets. so if you have similar problems you should change command from this:

 

$ZENHOME/scripts/tweet.sh ${evt/device} -- ${evt/summary}

 

to this:

 

$ZENHOME/scripts/tweet.sh "${evt/device} -- ${evt/summary}"

 

then everything will work also with brackets inside the device name and event summary.

 

MacSEK