Pushover: Adds support for optional 'title' (#53726)

** SUMMARY **
Adds support for optional 'title'.

** ISSUE TYPE **
Feature Pull Request

** COMPONENT NAME **
pushover
This commit is contained in:
desimaniac 2019-04-10 16:13:54 -05:00 committed by ansibot
parent 9ac57dff61
commit b41c6fcdd4

View file

@ -36,9 +36,14 @@ options:
description: description:
- Pushover issued authentication key for your user. - Pushover issued authentication key for your user.
required: true required: true
title:
description:
- Message title.
required: false
version_added: "2.8"
pri: pri:
description: description:
- Message priority (see U(https://pushover.net) for details.) - Message priority (see U(https://pushover.net) for details).
required: false required: false
author: "Jim Richardson (@weaselkeeper)" author: "Jim Richardson (@weaselkeeper)"
@ -46,7 +51,15 @@ author: "Jim Richardson (@weaselkeeper)"
EXAMPLES = ''' EXAMPLES = '''
- pushover: - 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' msg: '{{ inventory_hostname }} has exploded in flames, It is now time to panic'
pri: 1
app_token: wxfdksl app_token: wxfdksl
user_key: baa5fe97f2c5ab3ca8f0bb59 user_key: baa5fe97f2c5ab3ca8f0bb59
delegate_to: localhost delegate_to: localhost
@ -66,7 +79,7 @@ class Pushover(object):
self.user = user self.user = user
self.token = token self.token = token
def run(self, priority, msg): def run(self, priority, msg, title):
''' Do, whatever it is, we do. ''' ''' Do, whatever it is, we do. '''
url = '%s/1/messages.json' % (self.base_uri) url = '%s/1/messages.json' % (self.base_uri)
@ -76,6 +89,11 @@ class Pushover(object):
token=self.token, token=self.token,
priority=priority, priority=priority,
message=msg) message=msg)
if title is not None:
options = dict(options,
title=title)
data = urlencode(options) data = urlencode(options)
headers = {"Content-type": "application/x-www-form-urlencoded"} headers = {"Content-type": "application/x-www-form-urlencoded"}
@ -90,6 +108,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
title=dict(type='str'),
msg=dict(required=True), msg=dict(required=True),
app_token=dict(required=True, no_log=True), app_token=dict(required=True, no_log=True),
user_key=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']) msg_object = Pushover(module, module.params['user_key'], module.params['app_token'])
try: 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: except Exception:
module.fail_json(msg='Unable to send msg via pushover') module.fail_json(msg='Unable to send msg via pushover')