Skip to content

Instantly share code, notes, and snippets.

@mbabineau
Created May 18, 2011 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbabineau/977747 to your computer and use it in GitHub Desktop.
Save mbabineau/977747 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment