
    Vhv                         d dl mZmZmZ eZdZdZd dlZd dl	Z	dZ
	 d dlmZmZ dZd dlmZmZ d d	lmZ d
 Zd Zedk(  r e        yy# e$ r  e	j                          Z
dZY <w xY w)    )absolute_importdivisionprint_functionuU  
module: datadog_event
short_description: Posts events to Datadog  service
description:
  - Allows to post events to Datadog (www.datadoghq.com) service.
  - Uses http://docs.datadoghq.com/api/#events API.
author:
  - "Artūras 'arturaz' Šlajus (@arturaz)"
  - "Naoya Nakazawa (@n0ts)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  api_key:
    type: str
    description:
      - Your DataDog API key.
    required: true
  app_key:
    type: str
    description:
      - Your DataDog app key.
    required: true
  title:
    type: str
    description:
      - The event title.
    required: true
  text:
    type: str
    description:
      - The body of the event.
    required: true
  date_happened:
    type: int
    description:
      - POSIX timestamp of the event.
      - Default value is now.
  priority:
    type: str
    description:
      - The priority of the event.
    default: normal
    choices: [normal, low]
  host:
    type: str
    description:
      - Host name to associate with the event.
      - If not specified, it defaults to the remote system's hostname.
  api_host:
    type: str
    description:
      - DataDog API endpoint URL.
    version_added: '3.3.0'
  tags:
    type: list
    elements: str
    description:
      - Comma separated list of tags to apply to the event.
  alert_type:
    type: str
    description:
      - Type of alert.
    default: info
    choices: ['error', 'warning', 'info', 'success']
  aggregation_key:
    type: str
    description:
      - An arbitrary string to use for aggregation.
  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
ai  
- name: Post an event with low priority
  community.general.datadog_event:
    title: Testing from ansible
    text: Test
    priority: low
    api_key: 9775a026f1ca7d1c6c5af9d94d9595a4
    app_key: j4JyCYfefWHhgFgiZUqRm63AXHNZQyPGBfJtAzmN

- name: Post an event with several tags
  community.general.datadog_event:
    title: Testing from ansible
    text: Test
    api_key: 9775a026f1ca7d1c6c5af9d94d9595a4
    app_key: j4JyCYfefWHhgFgiZUqRm63AXHNZQyPGBfJtAzmN
    tags: 'aa,bb,#host:{{ inventory_hostname }}'

- name: Post an event with several tags to another endpoint
  community.general.datadog_event:
    title: Testing from ansible
    text: Test
    api_key: 9775a026f1ca7d1c6c5af9d94d9595a4
    app_key: j4JyCYfefWHhgFgiZUqRm63AXHNZQyPGBfJtAzmN
    api_host: 'https://example.datadoghq.eu'
    tags:
      - aa
      - b
      - '#host:{{ inventory_hostname }}'
N)
initializeapiTF)AnsibleModulemissing_required_lib)	to_nativec                  >   t        t        t        dd      t        dd      t        d      t        d      t        d      t        d      t        dddg	      t               t        d
d      t        dg d	      t        d      t        dd                  } t        s | j                  t	        d      t
               | j                  d   | j                  d   d}| j                  d   | j                  d   |d<   t        di | t        |        y )NT)requiredno_logstr)type)r   intnormallow)defaultchoiceslist)r   elementsinfo)errorwarningr   successF)r   bool)r   r   )api_keyapp_keyapi_hosttitletextdate_happenedpriorityhosttags
alert_typeaggregation_keyvalidate_certs)argument_spec	datadogpymsg	exceptionr   r   )r   r   r    )	r   dictHAS_DATADOG	fail_jsonr	   DATADOG_IMP_ERRparamsr   _post_event)moduleoptionss     s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/datadog_event.pymainr7      s    $t4$t4u%%t$E*(Xu4EF6E2F4[\ .6:
F$ 1+>/Z ==+==+G }}Z ,$mmJ7
    c           
      p   	 | j                   d   3t        j                         j                  d      d   | j                   d<   t        j
                  j                  | j                   d   | j                   d   | j                   d   | j                   d   | j                   d   | j                   d   | j                   d	   d
      }|d   dk7  r| j                  |       | j                  d|       y # t        $ r8}| j                  t        |      t        j                                Y d }~y d }~ww xY w)Nr#   .r   r   r    r$   r"   r%   r&   ansible)r   r    r#   r$   r"   r%   r&   source_type_namestatusok)r+   T)changedr+   r*   )r2   platformnodesplitr   Eventcreater0   	exit_json	Exceptionr
   	traceback
format_exc)r4   r+   es      r6   r3   r3      s   M== ($,MMO$9$9#$>q$AFMM&!iiV]]7%;$*MM&$9$*MM&$9$*MM&$9(.j(A*0--*E/5}}=N/O09  ; x=D %3/ MYq\Y5I5I5KLLMs   C1C4 4	D5=.D00D5__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESr@   rG   r1   datadogr   r   r/   rF   rH   ansible.module_utils.basicr   r	   +ansible.module_utils.common.text.convertersr
   r7   r3   __name__r-   r8   r6   <module>rS      s    A @Ob<   'K
 K ADM( zF }  *i**,OKs   
A A#"A#