
    Vh                         d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d
ZdZdZdddefdZdddefdZd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaB  
module: hipchat
short_description: Send a message to Hipchat
description:
  - Send a message to a Hipchat room, with options to control the formatting.
extends_documentation_fragment:
  - community.general.attributes
deprecated:
  removed_in: 11.0.0
  why: The hipchat service has been discontinued and the self-hosted variant has been End of Life since 2020.
  alternative: There is none.
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  token:
    type: str
    description:
      - API token.
    required: true
  room:
    type: str
    description:
      - ID or name of the room.
    required: true
  msg_from:
    type: str
    description:
      - Name the message will appear to be sent from. Max length is 15 characters - above this it will be truncated.
    default: Ansible
    aliases: [from]
  msg:
    type: str
    description:
      - The message body.
    required: true
  color:
    type: str
    description:
      - Background color for the message.
    default: yellow
    choices: ["yellow", "red", "green", "purple", "gray", "random"]
  msg_format:
    type: str
    description:
      - Message format.
    default: text
    choices: ["text", "html"]
  notify:
    description:
      - If true, a notification will be triggered for users in the room.
    type: bool
    default: true
  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.
    type: bool
    default: true
  api:
    type: str
    description:
      - API URL if using a self-hosted hipchat server. For Hipchat API version 2 use the default URI with C(/v2) instead of
        C(/v1).
    default: 'https://api.hipchat.com/v1'

author:
  - Shirou Wakayama (@shirou)
  - Paul Bourdel (@pb8226)
aF  
- name: Send a message to a Hipchat room
  community.general.hipchat:
    room: notif
    msg: Ansible task finished

- name: Send a message to a Hipchat room using Hipchat API version 2
  community.general.hipchat:
    api: https://api.hipchat.com/v2/
    token: OAUTH2_TOKEN
    room: notify
    msg: Ansible task finished
N)AnsibleModule)	urlencode)pathname2url)	to_native)	fetch_urlzhttps://api.hipchat.com/v1z/rooms/messagez/room/{id_or_name}/notificationtextyellowFc	                 j   i }	||	d<   |dd |	d<   ||	d<   ||	d<   ||	d<   ||	d<   t        |      |	d	<   |t        z   d
|z  z   }
t        |	      }| j                  r| j	                  d       t        | |
|      \  }}|d   dk(  r|j                         S | j                  dt        |d         z         y)z$sending message to hipchat v1 serverroom_idN   frommessagemessage_formatcolorapinotifyz?auth_token=%sFchanged)datastatus   (failed to send message, return status=%smsg)	int
MSG_URI_V1r   
check_mode	exit_jsonr
   read	fail_jsonstr)moduletokenroommsg_fromr   
msg_formatr   r   r   paramsurlr   responseinfos                 m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/hipchat.pysend_msg_v1r/   x   s     FF9cr]F6NF9)FF7OF5M6{F8


-7
7CVD'vs6NHdH~}}G#dS[nJ]]^    c	                    d|z  dd}	t               }
||
d<   ||
d<   ||
d<   ||
d<   |t        z   }|j                  dt        |            }t	        j
                  |
      }| j                  r| j                  d	
       t        | |||	d      \  }}|d   dv r|j                         S | j                  dt        |d         z         y)z$sending message to hipchat v2 serverz	Bearer %szapplication/json)AuthorizationzContent-Typer   r   r   r   z{id_or_name}Fr   POST)r   headersmethodr   )r      r   r   N)dictNOTIFY_URI_V2replacer   jsondumpsr    r!   r
   r"   r#   r$   )r%   r&   r'   r(   r   r)   r   r   r   r4   bodyPOST_URLr+   r   r,   r-   s                   r.   send_msg_v2r>      s     !,e 3EWXG6DDODM'D	DN]"H


><+=
>C::dD'vswvVNHd H~#}}G#dS[nJ]]^r0   c                  J   t        t        t        dd      t        d      t        d      t        ddg      t        dg d	      t        d
d
dg	      t        dd      t        dd      t        t              	      d      } | j                  d   }t	        | j                  d         }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }	 |j                  d      dk7  rt        | ||||||||	       nt        | ||||||||	       d}
| j                  |
|||       y # t        $ r;}	| j                  dt        |	      z  t        j                                Y d }	~	Wd }	~	ww xY w)NT)requiredno_log)r@   Ansibler   )defaultaliasesr   )r   redgreenpurplegrayrandom)rC   choicesr   htmlbool)rC   type)rC   )	r&   r'   r   r(   r   r)   r   validate_certsr   )argument_specsupports_check_moder&   r'   r   r(   r   r)   r   r   z/v2zunable to send msg: %s)r   	exception)r   r'   r(   r   )r   r7   DEFAULT_URIr*   r$   findr>   r/   	Exceptionr#   r	   	traceback
format_excr!   )r%   r&   r'   r   r(   r   r)   r   r   er   s              r.   mainrY      s   T2t$d#)fX>x 2N OFVV4DE626:[)
 !F  MM'"Ev}}V$%D
--
C}}Z(HMM'"E|,J]]8$F
--
Ch88E?b tXsJvWZ[tXsJvWZ[ G
W4(L	  h5	!DPYPdPdPfgghs   ;E 	F"'1FF"__main__)
__future__r   r   r   rM   __metaclass__DOCUMENTATIONEXAMPLESr:   rV   ansible.module_utils.basicr   +ansible.module_utils.six.moves.urllib.parser   -ansible.module_utils.six.moves.urllib.requestr   +ansible.module_utils.common.text.convertersr	   ansible.module_utils.urlsr
   rS   r   r8   r/   r>   rY   __name__ r0   r.   <module>rf      s    A @GR$   4 A F A / +
1 @Fu*_6 @Fu-_F$MN zF r0   