
    Vh                     `    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functionaC  
module: mattermost
short_description: Send Mattermost notifications
description:
  - Sends notifications to U(http://your.mattermost.url) using the Incoming WebHook integration.
author: "Benjamin Jolivot (@bjolivot)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  url:
    type: str
    description:
      - Mattermost URL (for example V(http://mattermost.yourcompany.com)).
    required: true
  api_key:
    type: str
    description:
      - Mattermost webhook API key. Log into your Mattermost site, go to Menu -> Integration -> Incoming Webhook -> Add Incoming
        Webhook. This will give you full URL. O(api_key) is the last part. U(http://mattermost.example.com/hooks/API_KEY).
    required: true
  text:
    type: str
    description:
      - Text to send. Note that the module does not handle escaping characters.
      - Required when O(attachments) is not set.
  attachments:
    type: list
    elements: dict
    description:
      - Define a list of attachments.
      - For more information, see U(https://developers.mattermost.com/integrate/admin-guide/admin-message-attachments/).
      - Required when O(text) is not set.
    version_added: 4.3.0
  channel:
    type: str
    description:
      - Channel to send the message to. If absent, the message goes to the channel selected for the O(api_key).
  username:
    type: str
    description:
      - This is the sender of the message (Username Override need to be enabled by mattermost admin, see mattermost doc).
    default: Ansible
  icon_url:
    type: str
    description:
      - URL for the message sender's icon.
    default: https://docs.ansible.com/favicon.ico
  priority:
    type: str
    description:
      - Set a priority for the message.
    choices: [important, urgent]
    version_added: 10.0.0
  validate_certs:
    description:
      - If V(false), SSL certificates will not be validated. This should only be used on personally controlled sites using
        self-signed certificates.
    default: true
    type: bool
a  
- name: Send notification message via Mattermost
  community.general.mattermost:
    url: http://mattermost.example.com
    api_key: my_api_key
    text: '{{ inventory_hostname }} completed'

- name: Send notification message via Mattermost all options
  community.general.mattermost:
    url: http://mattermost.example.com
    api_key: my_api_key
    text: '{{ inventory_hostname }} completed'
    channel: notifications
    username: 'Ansible on {{ inventory_hostname }}'
    icon_url: http://www.example.com/some-image-file.png
    priority: important

- name: Send attachments message via Mattermost
  community.general.mattermost:
    url: http://mattermost.example.com
    api_key: my_api_key
    attachments:
      - text: Display my system load on host A and B
        color: '#ff00dd'
        title: System load
        fields:
          - title: System A
            value: "load average: 0,74, 0,66, 0,63"
            short: true
          - title: System B
            value: 'load average: 5,16, 4,64, 2,43'
            short: true
z
payload:
  description: Mattermost payload.
  returned: success
  type: str
webhook_url:
  description: URL the webhook is sent to.
  returned: success
  type: str
)AnsibleModule)	fetch_urlc                  (   t        dt        t        dd      t        ddd      t        d      t        dd       t        dd      t        dd      t        dd d	d
g      t        dd      t        dd      	      dg      } t        dd      }dj                  | j                  d   | j                  d         }||d<   i }dD ]$  }| j                  |   | j                  |   ||<   & | j                  d   d| j                  d   i|d<   | j	                  |      }||d<   ddd}| j
                  du rDt        | ||d |!      \  }}|d"   d#k7  r)d$j                  |d%         |d%<    | j                  d&i |  | j                  d&i | y )'NTstr)typerequired)r
   r   no_log)r
   )r
   defaultAnsiblez$https://docs.ansible.com/favicon.ico	importanturgent)r
   r   choicesbool)r   r
   listdict)r
   elements)	urlapi_keytextchannelusernameicon_urlpriorityvalidate_certsattachments)r   r   )supports_check_modeargument_specrequired_one_ofFOK)changedmsgz{0}/hooks/{1}r   r   webhook_url)r   r   r   r   r   r   payloadzapplication/json)zContent-TypeAcceptPOST)moduler   headersmethoddatastatus   z5Failed to send mattermost message, the error was: {0}r$    )	r   r   formatparamsjsonify
check_moder   	fail_json	exit_json)r)   resultr%   r&   paramr*   responseinfos           p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/mattermost.pymainr;      s    %$/ed4@5!eT2ui8u.TUud[(<ST6:&6:

 $
F$ %T*F "((u)=v}}Y?WXK'F= GK 2==+#]]51GEN2 }}Z ,)6==+DE
nnW%GF9 +$G E!"&k7[ahop$ >S SZZ[_`e[fgF5MF&v& Fv    __main__N)
__future__r   r   r   r
   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   ansible.module_utils.urlsr   r;   __name__r/   r<   r:   <module>rF      sM    A @@D D	
 5 /:z zF r<   