def post_to_slack(url, channel, snapshot, prefix):
    f = facter.Facter()
    msg = 'Started Elasticsearch restore of snapshot "%s" (from "%s") into stack "%s"' % (snapshot, prefix, f.lookup('cfn_stack_name'))

    data = json.dumps({
        'channel': channel,
        'username': f.lookup('cfn_stack_name').replace('-', ' '),
        'attachments': [
            {
                'fallback': msg,
                'pretext': msg,
                'color': 'good',
                'fields': [
                    {
                        'title': f.lookup('hostname'),
                        'value': 'You will not be able to connect to Elasticsearch for a little while while the restore is happening.'
                    }
                ]
            }
        ]
    })

    req = urllib2.Request(url, data, {"Content-type": "application/json"})
    reqh = urllib2.urlopen(req)
    reqh.close()
Exemple #2
0
def post_to_flowdock(token, snapshot, prefix):
    try:
        import requests
    except:
        print 'Missing requests library needed by flowdock ... silenty ignoring'
        return

    f = facter.Facter()
    username = f.lookup('cfn_stack_name').replace('-', ' '),

    msg = 'Started Elasticsearch restore of snapshot "%s" (from "%s") into stack "%s"\n' % (
        snapshot, prefix, f.lookup('cfn_stack_name'))
    msg = msg + 'You will not be able to connect to Elasticsearch for a little while while the restore is happening.'

    try:
        r = requests.post("https://api.flowdock.com/messages/chat/" + token,
                          data={
                              'content': msg,
                              'event': 'comment',
                              'external_user_name': username
                          })
        if r.status_code != 200:
            print 'Problem while posting to flowdock. Verify the token'
    except e:
        print 'error while posting to flowdock ' + e.msg
Exemple #3
0
 def __init__(self):
     self.facter = facter.Facter()
     self.facter.build_cache()