
    VhQ                     ~    d dl mZmZmZ eZdZdZd dlm	Z	 d dl
mZ d dlmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functionaW  
module: pushover
short_description: Send notifications through U(https://pushover.net)
description:
  - Send notifications through pushover to subscriber list of devices and email addresses. Requires pushover app on devices.
notes:
  - You will require a pushover.net account to use this module. But no account is required to receive messages.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  msg:
    type: str
    description:
      - What message you wish to send.
    required: true
  app_token:
    type: str
    description:
      - Pushover issued token identifying your pushover app.
    required: true
  user_key:
    type: str
    description:
      - Pushover issued authentication key for your user.
    required: true
  title:
    type: str
    description:
      - Message title.
    required: false
  pri:
    type: str
    description:
      - Message priority (see U(https://pushover.net) for details).
    required: false
    default: '0'
    choices: ['-2', '-1', '0', '1', '2']
  device:
    type: str
    description:
      - A device the message should be sent to. Multiple devices can be specified, separated by a comma.
    required: false
    version_added: 1.2.0

author:
  - "Jim Richardson (@weaselkeeper)"
  - "Bernd Arnold (@wopfel)"
a  
- name: Send notifications via pushover.net
  community.general.pushover:
    msg: '{{ inventory_hostname }} is acting strange ...'
    app_token: wxfdksl
    user_key: baa5fe97f2c5ab3ca8f0bb59
  delegate_to: localhost

- name: Send notifications via pushover.net
  community.general.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

- name: Send notifications via pushover.net to a specific device
  community.general.pushover:
    msg: '{{ inventory_hostname }} has been lost somewhere'
    app_token: wxfdksl
    user_key: baa5fe97f2c5ab3ca8f0bb59
    device: admins-iPhone
  delegate_to: localhost
)AnsibleModule)	urlencode)	fetch_urlc                        e Zd ZdZdZd Zd Zy)Pushoverz> Instantiates a pushover object, use it to send notifications zhttps://api.pushover.netc                 .    || _         || _        || _        y )N)moduleusertoken)selfr   r   r   s       n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pushover.py__init__zPushover.__init__e   s    	
    c                 @   d| j                   z  }t        | j                  | j                  ||      }|t        ||      }|t        ||      }t	        |      }ddi}t        | j                  |d||      \  }	}
|
d	   d
k7  rt        |
      |	j                         S )z Do, whatever it is, we do. z%s/1/messages.json)r   r   prioritymessage)title)devicezContent-typez!application/x-www-form-urlencodedPOST)methoddataheadersstatus   )	base_uridictr   r   r   r   r   	Exceptionread)r   r   msgr   r   urloptionsr   r   rinfos              r   runzPushover.runj   s     #dmm4 DII!ZZ ("$
 7!&(G 7"(*G !!#FGDKKV$PWX4>S D/!vvxr   N)__name__
__module____qualname____doc__r   r   r'    r   r   r
   r
   a   s    H)H
r   r
   c                     t        t        t        d      t        d      t        dd      t        dd      t        ddg d	      t        d      
            } t        | | j                  d   | j                  d         }	 |j	                  | j                  d   | j                  d   | j                  d   | j                  d         }| j                  dz  d       y # t
        $ r | j                  d       Y 4w xY w)Nstr)typeT)required)r0   no_logF0)z-2z-1r2   12)r0   defaultchoices)r   r"   	app_tokenuser_keyprir   )argument_specr8   r7   r9   r"   r   r   zUnable to send msg via pushover)r"   zmessage sent successfully: %s)r"   changed)r   r   r
   paramsr'   r    	fail_json	exit_json)r   
msg_objectresponses      r   mainrA      s    E"d#D645eS:UVU#
	F &&--
";V]];=WXJ@>>&--"6e8Lfmm\cNdflfsfst|f}~ 88CUS  @>?@s   AC% %DD__main__N)
__future__r   r   r   r/   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   +ansible.module_utils.six.moves.urllib.parser   ansible.module_utils.urlsr   objectr
   rA   r(   r,   r   r   <module>rK      sT    A @4l4 5 A /#v #LT, zF r   