Pages

Monday, August 10, 2009

Setting up EventTriggers to send alerts via Twitter DM

I mentioned in a previous post how you can send Direct Messages on Twitter using VBScript or KiXtart scripting.  Prior to that, I described how you can setup a twitter account for your server(s) to use so you can pass confidential messages between you and your server(s).  That opens up a TON of possibilities for monitoring as well as sending control requests to the remote computer(s) using a locked-down Twitter account.  As with everything like this, exercise extreme caution and perform a lot of testing before sitting back and getting too comfortable.  There are risks involved you cannot ignore, but they can be mitigated.

One way to employ Twitter for remote systems management is to have your servers/computers use the built-in EVENTTRIGGERS command.  This command is available with various Windows platforms and version and allows you to respond to specific events.  One of those is to have the action call on a script. That script can do anything you want to do, including sending Twitter messages.  I recommend a Direct Message, rather than a general timeline status update.  You probably don’t want to share your system events with your followers, and I’m pretty sure they wouldn’t want to read them anyway.

The syntax for EVENTTRIGGERS is documented on Microsoft TechNet.  An example for creating an event trigger to respond to a “low disk space” warning event is as follows:

eventtriggers /create /s Server1 /u domain\userid /p password /tr "Low Disk Space" /eid 4133 /t warning /tk \\server2\scripts\tweet.vbs


In this example, the server being monitored is Server1.  The event id is 4133 and the event type is “warning”.  The action being taken is to call a script, “tweet.vbs” which is a vbscript file.  You can call any script you like, but if there is no default script engine handler (e.g. wscript.exe) then you would probably want to put the execution statement into a .BAT file and call the .BAT file instead.  So, in this example, if I wanted to invoke cscript.exe…



@echo off
cscript.exe /nologo \\server2\scripts\tweet.vbs "low disk space on server1"

The net result would be something like this...

eventtriggers /create /s Server1 /u domain\userid /p password /tr "Low Disk Space" /eid 4133 /t warning /tk \\server2\scripts\tweetalert.bat


This would call the .BAT file, which would invoke cscript.exe and execute tweet.vbs. This also makes it easier and cleaner to add optional arguments to your script execution to give you more flexibility while keeping your EVENTTRIGGERS setup less cluttered.



Now, before you start scoffing at this whole preposterous concept, I will admit this isn’t foolproof.  It’s just an example of something you COULD do.  As an old mentor often said to me years ago: “never confuse COULD and SHOULD”.  The most likely weak spot in this idea is the availability aspect (let’s face it: Twitter is very unreliable at times).  It is possible to respond to an error result from the Twitter API by entering a timed-loop until the response indicates success, but that’s cumbersome and also unreliable.  The takeaway here is that you COULD do this.  I’m not saying you SHOULD.  Charlie would be proud of me.

No comments:

Post a Comment