From b41c6fcdd42c1e4947ba51396cd4add49567c46e Mon Sep 17 00:00:00 2001 From: desimaniac <5501908+desimaniac@users.noreply.github.com> Date: Wed, 10 Apr 2019 16:13:54 -0500 Subject: [PATCH] Pushover: Adds support for optional 'title' (#53726) ** SUMMARY ** Adds support for optional 'title'. ** ISSUE TYPE ** Feature Pull Request ** COMPONENT NAME ** pushover --- lib/ansible/modules/notification/pushover.py | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/notification/pushover.py b/lib/ansible/modules/notification/pushover.py index d1d2d18b713..72edd98fcaf 100644 --- a/lib/ansible/modules/notification/pushover.py +++ b/lib/ansible/modules/notification/pushover.py @@ -36,9 +36,14 @@ options: description: - Pushover issued authentication key for your user. required: true + title: + description: + - Message title. + required: false + version_added: "2.8" pri: description: - - Message priority (see U(https://pushover.net) for details.) + - Message priority (see U(https://pushover.net) for details). required: false author: "Jim Richardson (@weaselkeeper)" @@ -46,7 +51,15 @@ author: "Jim Richardson (@weaselkeeper)" EXAMPLES = ''' - pushover: + msg: '{{ inventory_hostname }} is acting strange ...' + app_token: wxfdksl + user_key: baa5fe97f2c5ab3ca8f0bb59 + delegate_to: localhost + +- pushover: + title: 'Alert!' msg: '{{ inventory_hostname }} has exploded in flames, It is now time to panic' + pri: 1 app_token: wxfdksl user_key: baa5fe97f2c5ab3ca8f0bb59 delegate_to: localhost @@ -66,7 +79,7 @@ class Pushover(object): self.user = user self.token = token - def run(self, priority, msg): + def run(self, priority, msg, title): ''' Do, whatever it is, we do. ''' url = '%s/1/messages.json' % (self.base_uri) @@ -76,6 +89,11 @@ class Pushover(object): token=self.token, priority=priority, message=msg) + + if title is not None: + options = dict(options, + title=title) + data = urlencode(options) headers = {"Content-type": "application/x-www-form-urlencoded"} @@ -90,6 +108,7 @@ def main(): module = AnsibleModule( argument_spec=dict( + title=dict(type='str'), msg=dict(required=True), app_token=dict(required=True, no_log=True), user_key=dict(required=True, no_log=True), @@ -99,7 +118,7 @@ def main(): msg_object = Pushover(module, module.params['user_key'], module.params['app_token']) try: - response = msg_object.run(module.params['pri'], module.params['msg']) + response = msg_object.run(module.params['pri'], module.params['msg'], module.params['title']) except Exception: module.fail_json(msg='Unable to send msg via pushover')