1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/modules/notification/grove.py
patchback[bot] a3a33cb019
Tidy up validate-modules ignores for notification modules (#1229) (#1232)
* fixed validation-modules for plugins/modules/notification/bearychat.py

* fixed validation-modules for plugins/modules/notification/campfire.py

* fixed validation-modules for plugins/modules/notification/catapult.py

* fixed validation-modules for plugins/modules/notification/flowdock.py

* fixed validation-modules for plugins/modules/notification/grove.py

* fixed validation-modules for plugins/modules/notification/hipchat.py

* fixed validation-modules for plugins/modules/notification/irc.py

* fixed validation-modules for plugins/modules/notification/jabber.py

* fixed validation-modules for plugins/modules/notification/logentries_msg.py

* fixed validation-modules for plugins/modules/notification/mail.py

* fixed validation-modules for plugins/modules/notification/matrix.py

* fixed validation-modules for plugins/modules/notification/mattermost.py

* fixed validation-modules for plugins/modules/notification/mqtt.py

* fixed validation-modules for plugins/modules/notification/nexmo.py

* fixed validation-modules for plugins/modules/notification/office_365_connector_card.py

* fixed some docs issues in plugins/modules/notification/pushbullet.py, but cannot remove the ignore lines yet

* fixed validation-modules for plugins/modules/notification/pushover.py

* fixed some docs issues in plugins/modules/notification/rocketchat.py, but cannot remove all ignore lines yet

* fixed validation-modules for plugins/modules/notification/say.py

* fixed validation-modules for plugins/modules/notification/sendgrid.py

* fixed validation-modules for plugins/modules/notification/slack.py

* fixed validation-modules for plugins/modules/notification/syslogger.py

* fixed validation-modules for plugins/modules/notification/telegram.py

* fixed validation-modules for plugins/modules/notification/twilio.py

* fixed validation-modules for plugins/modules/notification/typetalk.py

* Enabling validation-modules for modules in: notification

* removed naughty trailing space

(cherry picked from commit 24f780ec9a)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-05 07:40:30 +01:00

116 lines
3.1 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: grove
short_description: Sends a notification to a grove.io channel
description:
- The C(grove) module sends a message for a service to a Grove.io
channel.
options:
channel_token:
type: str
description:
- Token of the channel to post to.
required: true
service:
type: str
description:
- Name of the service (displayed as the "user" in the message)
required: false
default: ansible
message:
type: str
description:
- Message content
required: true
url:
type: str
description:
- Service URL for the web client
required: false
icon_url:
type: str
description:
- Icon for the service
required: false
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.
default: 'yes'
type: bool
author: "Jonas Pfenniger (@zimbatm)"
'''
EXAMPLES = '''
- name: Sends a notification to a grove.io channel
community.general.grove:
channel_token: 6Ph62VBBJOccmtTPZbubiPzdrhipZXtg
service: my-app
message: 'deployed {{ target }}'
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url
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
data = 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'])
# ==============================================================
# main
def main():
module = AnsibleModule(
argument_spec=dict(
channel_token=dict(type='str', required=True, no_log=True),
message=dict(type='str', required=True),
service=dict(type='str', default='ansible'),
url=dict(type='str', default=None),
icon_url=dict(type='str', default=None),
validate_certs=dict(default=True, type='bool'),
)
)
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")
if __name__ == '__main__':
main()