
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 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!
great! works fine for me!!