
    Vh                     b    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 Zd Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functiona  
module: librato_annotation
short_description: Create an annotation in Librato
description:
  - Create an annotation event on the given annotation stream :name. If the annotation stream does not exist, it will be created
    automatically.
author: "Seth Edwards (@Sedward)"
requirements: []
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  user:
    type: str
    description:
      - Librato account username.
    required: true
  api_key:
    type: str
    description:
      - Librato account API key.
    required: true
  name:
    type: str
    description:
      - The annotation stream name.
      - If the annotation stream does not exist, it will be created automatically.
    required: false
  title:
    type: str
    description:
      - The title of an annotation is a string and may contain spaces.
      - The title should be a short, high-level summary of the annotation for example V(v45 Deployment).
    required: true
  source:
    type: str
    description:
      - A string which describes the originating source of an annotation when that annotation is tracked across multiple members
        of a population.
    required: false
  description:
    type: str
    description:
      - The description contains extra metadata about a particular annotation.
      - The description should contain specifics on the individual annotation for example V(Deployed 9b562b2 shipped new feature
        foo!).
    required: false
  start_time:
    type: int
    description:
      - The unix timestamp indicating the time at which the event referenced by this annotation started.
    required: false
  end_time:
    type: int
    description:
      - The unix timestamp indicating the time at which the event referenced by this annotation ended.
      - For events that have a duration, this is a useful way to annotate the duration of the event.
    required: false
  links:
    type: list
    elements: dict
    description:
      - See examples.
a  
- name: Create a simple annotation event with a source
  community.general.librato_annotation:
    user: user@example.com
    api_key: XXXXXXXXXXXXXXXXX
    title: App Config Change
    source: foo.bar
    description: This is a detailed description of the config change

- name: Create an annotation that includes a link
  community.general.librato_annotation:
    user: user@example.com
    api_key: XXXXXXXXXXXXXXXXXX
    name: code.deploy
    title: app code deploy
    description: this is a detailed description of a deployment
    links:
      - rel: example
        href: http://www.example.com/deploy

- name: Create an annotation with a start_time and end_time
  community.general.librato_annotation:
    user: user@example.com
    api_key: XXXXXXXXXXXXXXXXXX
    name: maintenance
    title: Maintenance window
    description: This is a detailed description of maintenance
    start_time: 1395940006
    end_time: 1395954406
)AnsibleModule)	fetch_urlc                 \   | j                   d   }| j                   d   }| j                   d   }| j                   d   }d|z  }i }||d<   | j                   d   | j                   d   |d<   | j                   d   | j                   d   |d<   | j                   d   | j                   d   |d<   | j                   d	   | j                   d	   |d	<   | j                   d
   | j                   d
   |d
<   | j                  |      }i }d|d<   || j                   d<   || j                   d<   t        | |||      \  }	}
t        |
d         }|
d   }|
d   dk7  r9|
d   dk\  r| j	                  d|z   dz   |z          n| j	                  d|z          |	j                         }	| j                  d|	       y )Nuserapi_keynametitlez1https://metrics-api.librato.com/v1/annotations/%ssourcedescription
start_timeend_timelinkszapplication/jsonzContent-Typeurl_usernameurl_password)dataheadersstatusbody   i  zRequest Failed. Response code: z Response body: )msgT)changed
annotation)paramsjsonifyr   str	fail_jsonread	exit_json)moduler	   r
   r   r   urlr   	json_bodyr   responseinforesponse_coderesponse_bodys                x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/librato_annotation.pypost_annotationr*   t   s   == DmmI&G== DMM'"E
=
DCFF7O}}X*!==2x}}]#/ &m <}}}\".%}}\:|}}Z ,#]]:6z}}W) --0wv&IG0GN %)FMM.!$+FMM.!vsGLNHdX'MLMH~>S !B]!RUg!gjw!wx!B]!RS}}H
Th7    c                     t        t        t        d      t        dd      t        d      t        d      t        d      t        d      t        dd d      t        dd d      t        dd	      
	            } t        |        y )NT)required)r-   no_logFint)r-   defaulttypelistdict)r1   elements)	r	   r
   r   r   r   r   r   r   r   )argument_spec)r   r3   r*   )r"   s    r)   mainr6      sr    t$$t4u%%'e,UDuE5$UCFV4

F Fr+   __main__N)
__future__r   r   r   r1   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   ansible.module_utils.urlsr   r*   r6   __name__ r+   r)   <module>r@      sJ    A @CJ> 5 /&8R& zF r+   