
    Vhz                     x    d dl mZmZmZ eZd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Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: sensu_subscription
short_description: Manage Sensu subscriptions
description:
  - Manage which I(sensu channels) a machine should subscribe to.
deprecated:
  removed_in: 13.0.0
  why: Sensu Core and Sensu Enterprise products have been End of Life since 2019/20.
  alternative: Use Sensu Go and its accompanying collection C(sensu.sensu_go).
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    type: str
    description:
      - The name of the channel.
    required: true
  state:
    type: str
    description:
      - Whether the machine should subscribe or unsubscribe from the channel.
    choices: ['present', 'absent']
    required: false
    default: present
  path:
    type: str
    description:
      - Path to the subscriptions JSON file.
    required: false
    default: /etc/sensu/conf.d/subscriptions.json
  backup:
    description:
      - Create a backup file (if yes), including the timestamp information so you can get the original file back if you somehow
        clobbered it incorrectly.
    type: bool
    required: false
    default: false
requirements: []
author: Anders Ingemann (@andsens)
z
reasons:
  description: The reasons why the module changed or did not change something.
  returned: success
  type: list
  sample: ["channel subscription was absent and state is `present'"]
a  
# Subscribe to the nginx channel
- name: Subscribe to nginx checks
  community.general.sensu_subscription: name=nginx

# Unsubscribe from the common checks channel
- name: Unsubscribe from common checks
  community.general.sensu_subscription: name=common state=absent
N)AnsibleModule)	to_nativec           	         d}g }	 t        j                  t        |            }d	vr2|dk(  r|j                  d
       ||fS i |d	<   d}|j                  d       d|d	   vr5|dk(  r|j                  d       ||fS g |d	   d<   d}|j                  d       ||d	   d   vrE|dk(  r|j                  d       ||fS |d	   d   j                  |       d}|j                  d       n/|dk(  r*|d	   d   j                  |       d}|j                  d       |rW| j                  sK|r| j                  |       	 t        |d      j                  t        j                   |d      dz          ||fS ||fS # t        $ rj}|j                  dk(  r"|dk(  r|j                  d       ||fcY d }~S i }n.| j                  t        |      t        j                                Y d }~d }~wt        $ r( dj                  |      }	| j                  |	       Y w xY w# t        $ rA}| j                  d|dt        |      t        j                                Y d }~||fS d }~ww xY w)NF   absentz(file did not exist and state is `absent')msg	exceptionz{path} contains invalid JSON)path)r   clientz,`client' did not exist and state is `absent'Tz`client' did not existsubscriptionsz:`client.subscriptions' did not exist and state is `absent'z$`client.subscriptions' did not existzchannel subscription was absentz6channel subscription was absent and state is `present'z6channel subscription was present and state is `absent'w)indent
zFailed to write to file z: )jsonloadopenIOErrorerrnoappend	fail_jsonr   	traceback
format_exc
ValueErrorformatremove
check_modebackup_localwritedumps)
moduler   namestatebackupchangedreasonsconfiger   s
             x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/sensu_subscription.pysensu_subscriptionr,   S   s   GG"4:& vHNNKLG##x01fX..HNNYZG##,.x)>?6(#O44HNN<=G##x)006PQH8_-44T:GNNTUv((%	?sO!!$**VA">"EF
 G7Ge  Q77a< JK''F19M9M9OP ",333>S!"L  	?T9UV<!X'0';';'=  ? ? G		?sA   E1 63H 1	H:(G"H(1G0HH	I 4II c                     ddddddddddgdd	d
dd} t        | d      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }t        |||||      \  }}|j                  |||d|       y )NstrT)typerequiredz$/etc/sensu/conf.d/subscriptions.json)r/   defaultpresentr
   )r/   r1   choicesboolF)r$   r   r%   r&   )argument_specsupports_check_moder   r$   r%   r&   OK)r   r$   r'   r   r(   )r   paramsr,   	exit_json)arg_specr#   r   r$   r%   r&   r'   r(   s           r+   mainr;      s    !&D9!&3YZ"'I9V^J_`#)e<H /35F == D== DMM'"E]]8$F)&$eVLGW
$T7gV    __main__)r2   F)
__future__r   r   r   r/   __metaclass__DOCUMENTATIONRETURNEXAMPLESr   r   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r,   r;   __name__ r<   r+   <module>rG      sW    A @,\
   4 A8vW( zF r<   