"""Send notifications via `Pushover <https://www.pushover.net>`_ during state runs... important:: See :ref:`Configuration <pushover-setup>` for a description of available configuration parameters.Example-------.. code-block:: yaml pushover-message: pushover.post_message: - user: uQiRzpo4DXghDmr9QzzfQu27cmVRsG - token: azGDORePK8gMaC0QOYAMyEEuzJnyUi - title: Message from Salt - device: phone - priority: -1 - expire: 3600 - retry: 5 - message: 'This state was executed successfully.'"""__virtualname__="pushover"def__virtual__():if"pushover.post_message"in__salt__:return__virtualname__return(False,"pushover module could not be loaded")
[docs]defpost_message(name,user=None,device=None,message=None,title=None,priority=0,expire=None,retry=None,sound=None,# pylint: disable=unused-argumentapi_version=1,# pylint: disable=unused-argumenttoken=None,):""" Send a message to a Pushover user or group. .. code-block:: yaml pushover-message: pushover.post_message: - user: uQiRzpo4DXghDmr9QzzfQu27cmVRsG - token: azGDORePK8gMaC0QOYAMyEEuzJnyUi - title: Message from Salt - device: phone - priority: -1 - expire: 3600 - retry: 5 name The name of the state. Irrelevant. user The user or group of users to send the message to. Must be a user/group ID (key), not a name or an email address. Required if not specified in the configuration. message The message to send to the Pushover user or group. Required. title The message title to use. device The name of the device to send the message to. priority The priority of the message (integers between ``-2`` and ``2``). Defaults to ``0``. .. note:: Emergency priority (``2``) requires ``expire`` and ``retry`` parameters to be set. expire Stop notifying the user after the specified amount of seconds. The message is still shown after expiry. retry Repeat the notification after this amount of seconds. Minimum: ``30``. token The authentication token to use for the Pushover API. Required if not specified in the configuration. """ret={"name":name,"changes":{},"result":False,"comment":""}if__opts__["test"]:ret["comment"]=f"The following message is to be sent to Pushover: {message}"ret["result"]=Nonereturnretifnotuser:user=__salt__["config.get"]("pushover.user")or__salt__["config.get"]("pushover:user")ifnotuser:ret["comment"]=f"Pushover user is missing: {user}"returnretifnotmessage:ret["comment"]=f"Pushover message is missing: {message}"returnretresult=__salt__["pushover.post_message"](user=user,message=message,title=title,device=device,priority=priority,expire=expire,retry=retry,token=token,)ifresult:ret["result"]=Trueret["comment"]=f"Sent message: {name}"else:ret["comment"]=f"Failed to send message: {name}"returnret