Created
May 18, 2011 00:17
-
-
Save mbabineau/977747 to your computer and use it in GitHub Desktop.
Revisions
-
mbabineau renamed this gist
May 18, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mbabineau created this gist
May 18, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ import datetime import urllib2 from jabberbot import JabberBot, botcmd import boto class EA2DJabberBot(JabberBot): def __init__(self, *args, **kwargs): super(EA2DJabberBot, self).__init__(*args, **kwargs) @botcmd def as_list_hosts(self, msg, args): """Returns the hostnames for instances within an Auto Scaling Group""" if args: asg_name = args else: return "Error: You must pass an Auto Scaling Group name" c = boto.connect_autoscale() asgs = c.get_all_groups([asg_name]) if len(asgs) > 0: asg = asgs.pop() else: return 'Error: "%s" not found' % asg_name instance_ids = [i.instance_id for i in asg.instances] if len(instance_ids) > 0: c = boto.connect_ec2() reservations = c.get_all_instances(instance_ids) instances = [] for r in reservations: instances += [i.dns_name for i in r.instances] return "\n".join(instances) else: return 'No instances found in "%s(asg_name)"' if __name__ == '__main__': username = '9879_25735@chat.hipchat.com' #### password = chatroom = '9879_platform@conf.hipchat.com' nickname = 'Soundwave' bot = EA2DJabberBot(username, password) bot.PING_FREQUENCY = 15 bot.join_room(chatroom, nickname) bot.serve_forever()