Skip to content

Instantly share code, notes, and snippets.

@mbabineau
Created May 18, 2011 00:17
Show Gist options
  • Select an option

  • Save mbabineau/977747 to your computer and use it in GitHub Desktop.

Select an option

Save mbabineau/977747 to your computer and use it in GitHub Desktop.

Revisions

  1. mbabineau renamed this gist May 18, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. mbabineau created this gist May 18, 2011.
    49 changes: 49 additions & 0 deletions gistfile1.txt
    Original 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()