
    Vh                     h    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 d Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functionaW	  
module: pagerduty_change
short_description: Track a code or infrastructure change as a PagerDuty change event
version_added: 1.3.0
description:
  - This module will let you create a PagerDuty change event each time the module is run.
  - This is not an idempotent action and a new change event will be created each time it is run.
author:
  - Adam Vaughan (@adamvaughan)
requirements:
  - PagerDuty integration key
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
    details:
      - Check mode simply does nothing except returning C(changed=true) in case the O(url) seems to be correct.
  diff_mode:
    support: none
options:
  integration_key:
    description:
      - The integration key that identifies the service the change was made to. This can be found by adding an integration
        to a service in PagerDuty.
    required: true
    type: str
  summary:
    description:
      - A short description of the change that occurred.
    required: true
    type: str
  source:
    description:
      - The source of the change event.
    default: Ansible
    type: str
  user:
    description:
      - The name of the user or process that triggered this deployment.
    type: str
  repo:
    description:
      - The URL of the project repository.
    required: false
    type: str
  revision:
    description:
      - An identifier of the revision being deployed, typically a number or SHA from a version control system.
    required: false
    type: str
  environment:
    description:
      - The environment name, typically V(production), V(staging), and so on.
    required: false
    type: str
  link_url:
    description:
      - A URL where more information about the deployment can be obtained.
    required: false
    type: str
  link_text:
    description:
      - Descriptive text for a URL where more information about the deployment can be obtained.
    required: false
    type: str
  url:
    description:
      - URL to submit the change event to.
    required: false
    default: https://events.pagerduty.com/v2/change/enqueue
    type: str
  validate_certs:
    description:
      - If V(false), SSL certificates for the target URL will not be validated. This should only be used on personally controlled
        sites using self-signed certificates.
    required: false
    default: true
    type: bool
a  
- name: Track the deployment as a PagerDuty change event
  community.general.pagerduty_change:
    integration_key: abc123abc123abc123abc123abc123ab
    summary: The application was deployed

- name: Track the deployment as a PagerDuty change event with more details
  community.general.pagerduty_change:
    integration_key: abc123abc123abc123abc123abc123ab
    summary: The application was deployed
    source: Ansible Deploy
    user: ansible
    repo: github.com/ansible/ansible
    revision: '4.2'
    environment: production
    link_url: https://github.com/ansible-collections/community.general/pull/1269
    link_text: View changes on GitHub
)	fetch_url)AnsibleModule)nowc                     t        t        t        ddd      t        dd      t        ddd      t        dd      t        dd      t        dd      t        dd      t        dd      t        dd      t        ddd      t        dd	
            d      } | j                  d   }ddi}| j                  rEt	        | ||d      \  }}|d   dk(  r| j                  d       n| j                  d|d   z         i }| j                  d   r| j                  d   |d<   | j                  d   r| j                  d   |d<   | j                  d   r| j                  d   |d<   | j                  d   r| j                  d   |d<   t               j                  d      }| j                  d   | j                  d   ||d}| j                  d   |d }| j                  d!   r8d"| j                  d!   i}	| j                  d#   r| j                  d#   |	d$<   |	g|d%<   t	        | || j                  |      |d&      \  }}|d   d'k(  r| j                  d       y | j                  d(|d   z         y ))NTstr)requiredtypeno_log)r   r   FAnsible)r   defaultr   z.https://events.pagerduty.com/v2/change/enqueuebool)r   r   )integration_keysummarysourceuserreporevisionenvironmentlink_url	link_texturlvalidate_certs)argument_specsupports_check_moder   zContent-Typezapplication/jsonPOST)headersmethodstatusi  )changedzKChecking the PagerDuty change event API returned an unexpected response: %d)msgr   r   r   r   z%Y-%m-%dT%H:%M:%S.%fZr   r   )r   r   	timestampcustom_detailsr   )routing_keypayloadr   hrefr   textlinks)datar   r       z.Creating PagerDuty change event failed with %d)
r   dictparams
check_moder   	exit_json	fail_jsonr   strftimejsonify)
moduler   r   	_responseinfor%   r$   r'   eventlinks
             v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pagerduty_change.pymainr:   w   s    $U4H$U3	Fu51u515u5e%85u5E6eMTY[6:
 !F( --
C12G#C9	4 >S T*aeijrest  v N}}V!'v!6v}}V!'v!6v}}Z %+]]:%>z"}}]#(.m(D}%67I ==+--)(	G }}%67E
 }}Z FMM*-
 ==%!==5DLg&../QOIt H~&@DNS 	 	U    __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.urlsr   ansible.module_utils.basicr   Cansible_collections.community.general.plugins.module_utils.datetimer   r:   __name__ r;   r9   <module>rF      sL    A @Ob& 0 4
OUd zF r;   