2013-11-08 12:21:46 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
2013-11-19 00:55:49 +01:00
|
|
|
module: grove
|
|
|
|
version_added: 1.4
|
2013-11-08 12:21:46 +01:00
|
|
|
short_description: Sends a notification to a grove.io channel
|
|
|
|
description:
|
2013-11-19 00:55:49 +01:00
|
|
|
- The M(grove) module sends a message for a service to a Grove.io
|
2013-11-08 12:21:46 +01:00
|
|
|
channel.
|
|
|
|
options:
|
|
|
|
channel_token:
|
|
|
|
description:
|
|
|
|
- Token of the channel to post to.
|
|
|
|
required: true
|
|
|
|
service:
|
|
|
|
description:
|
2014-01-21 13:43:25 +01:00
|
|
|
- Name of the service (displayed as the "user" in the message)
|
|
|
|
required: false
|
|
|
|
default: ansible
|
2013-11-08 12:21:46 +01:00
|
|
|
message:
|
|
|
|
description:
|
|
|
|
- Message content
|
|
|
|
required: true
|
|
|
|
url:
|
|
|
|
description:
|
|
|
|
- Service URL for the web client
|
|
|
|
required: false
|
|
|
|
icon_url:
|
|
|
|
description:
|
|
|
|
- Icon for the service
|
|
|
|
required: false
|
2014-03-12 16:19:22 +01:00
|
|
|
validate_certs:
|
|
|
|
description:
|
|
|
|
- If C(no), SSL certificates will not be validated. This should only be used
|
|
|
|
on personally controlled sites using self-signed certificates.
|
|
|
|
required: false
|
|
|
|
default: 'yes'
|
|
|
|
choices: ['yes', 'no']
|
|
|
|
version_added: 1.5.1
|
2013-11-08 12:21:46 +01:00
|
|
|
author: Jonas Pfenniger <zimbatm@zimbatm.com>
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2013-11-19 00:55:49 +01:00
|
|
|
- grove: >
|
|
|
|
channel_token=6Ph62VBBJOccmtTPZbubiPzdrhipZXtg
|
|
|
|
service=my-app
|
|
|
|
message=deployed {{ target }}
|
2013-11-08 12:21:46 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
BASE_URL = 'https://grove.io/api/notice/%s/'
|
|
|
|
|
|
|
|
# ==============================================================
|
|
|
|
# do_notify_grove
|
|
|
|
|
|
|
|
def do_notify_grove(module, channel_token, service, message, url=None, icon_url=None):
|
|
|
|
my_url = BASE_URL % (channel_token,)
|
|
|
|
|
|
|
|
my_data = dict(service=service, message=message)
|
|
|
|
if url is not None:
|
|
|
|
my_data['url'] = url
|
|
|
|
if icon_url is not None:
|
|
|
|
my_data['icon_url'] = icon_url
|
|
|
|
|
2014-03-10 22:06:52 +01:00
|
|
|
data = urllib.urlencode(my_data)
|
|
|
|
response, info = fetch_url(module, my_url, data=data)
|
|
|
|
if info['status'] != 200:
|
|
|
|
module.fail_json(msg="failed to send notification: %s" % info['msg'])
|
2013-11-08 12:21:46 +01:00
|
|
|
|
|
|
|
# ==============================================================
|
|
|
|
# main
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
channel_token = dict(type='str', required=True),
|
|
|
|
message = dict(type='str', required=True),
|
2014-01-21 13:43:25 +01:00
|
|
|
service = dict(type='str', default='ansible'),
|
2013-11-08 12:21:46 +01:00
|
|
|
url = dict(type='str', default=None),
|
|
|
|
icon_url = dict(type='str', default=None),
|
2014-03-12 16:19:22 +01:00
|
|
|
validate_certs = dict(default='yes', type='bool'),
|
2013-11-08 12:21:46 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
channel_token = module.params['channel_token']
|
|
|
|
service = module.params['service']
|
|
|
|
message = module.params['message']
|
|
|
|
url = module.params['url']
|
|
|
|
icon_url = module.params['icon_url']
|
|
|
|
|
|
|
|
do_notify_grove(module, channel_token, service, message, url, icon_url)
|
|
|
|
|
|
|
|
# Mission complete
|
|
|
|
module.exit_json(msg="OK")
|
|
|
|
|
2013-12-02 21:13:49 +01:00
|
|
|
# import module snippets
|
2013-12-02 21:11:23 +01:00
|
|
|
from ansible.module_utils.basic import *
|
2013-11-08 12:21:46 +01:00
|
|
|
main()
|