Updated to use fetch_url
This commit is contained in:
parent
6d00756863
commit
fb4cf9410b
1 changed files with 14 additions and 13 deletions
|
@ -70,9 +70,9 @@ options:
|
|||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- stackdriver: key=AAAAAA event=deploy deployed_to=production deployed_by=leroyjenkins repository=MyWebApp revision_id=abcd123
|
||||
- stackdriver: key=AAAAAA event=deploy deployed_to=production deployed_by=leeroyjenkins repository=MyWebApp revision_id=abcd123
|
||||
|
||||
- stackdriver: key=AAAAAA event=annotation msg="Greetings from Ansible" annotated_by=leroyjenkins level=WARN instance_id=i-abcd1234
|
||||
- stackdriver: key=AAAAAA event=annotation msg="Greetings from Ansible" annotated_by=leeroyjenkins level=WARN instance_id=i-abcd1234
|
||||
'''
|
||||
|
||||
# ===========================================
|
||||
|
@ -96,12 +96,7 @@ def send_deploy_event(module, key, revision_id, deployed_by='Ansible', deployed_
|
|||
if repository:
|
||||
params['repository'] = repository
|
||||
|
||||
data = json.dumps(params)
|
||||
|
||||
req = urllib2.Request(deploy_api, data)
|
||||
req.add_header('content-type', 'application/json')
|
||||
req.add_header('x-stackdriver-apikey', key)
|
||||
return urllib2.urlopen(req)
|
||||
return do_send_request(module, deploy_api, params, key)
|
||||
|
||||
def send_annotation_event(module, key, msg, annotated_by='Ansible', level=None, instance_id=None, event_epoch=None):
|
||||
"""Send an annotation event to Stackdriver"""
|
||||
|
@ -118,12 +113,18 @@ def send_annotation_event(module, key, msg, annotated_by='Ansible', level=None,
|
|||
if event_epoch:
|
||||
params['event_epoch'] = event_epoch
|
||||
|
||||
data = json.dumps(params)
|
||||
return do_send_request(module, annotation_api, params, key)
|
||||
|
||||
def do_send_request(module, url, params, key):
|
||||
data = json.dumps(params)
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-stackdriver-apikey': key
|
||||
}
|
||||
response, info = fetch_url(module, url, headers=headers, data=data, method='POST')
|
||||
if info['status'] != 200:
|
||||
module.fail_json(msg="Unable to send msg: %s" % info['msg'])
|
||||
|
||||
req = urllib2.Request(annotation_api, data)
|
||||
req.add_header('content-type', 'application/json')
|
||||
req.add_header('x-stackdriver-apikey', key)
|
||||
return urllib2.urlopen(req)
|
||||
|
||||
# ===========================================
|
||||
# Module execution.
|
||||
|
|
Loading…
Reference in a new issue