
    Vh$                     d    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 Zedk(  r e        yy)	    )absolute_importdivisionprint_functionai  
module: sensu_client
author: "David Moreau Simard (@dmsimard)"
short_description: Manages Sensu client configuration
description:
  - Manages Sensu client configuration.
  - 'For more information, refer to the L(Sensu documentation, https://sensuapp.org/docs/latest/reference/clients.html).'
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:
  state:
    type: str
    description:
      - Whether the client should be present or not.
    choices: ['present', 'absent']
    default: present
  name:
    type: str
    description:
      - A unique name for the client. The name cannot contain special characters or spaces.
      - If not specified, it defaults to the system hostname as determined by Ruby Socket.gethostname (provided by Sensu).
  address:
    type: str
    description:
      - An address to help identify and reach the client. This is only informational, usually an IP address or hostname.
      - If not specified it defaults to non-loopback IPv4 address as determined by Ruby C(Socket.ip_address_list) (provided by
        Sensu).
  subscriptions:
    type: list
    elements: str
    description:
      - An array of client subscriptions, a list of roles and/or responsibilities assigned to the system (for example V(webserver)).
      - These subscriptions determine which monitoring checks are executed by the client, as check requests are sent to subscriptions.
      - The subscriptions array items must be strings.
  safe_mode:
    description:
      - If safe mode is enabled for the client. Safe mode requires local check definitions in order to accept a check request
        and execute the check.
    type: bool
    default: false
  redact:
    type: list
    elements: str
    description:
      - Client definition attributes to redact (values) when logging and sending client keepalives.
  socket:
    type: dict
    description:
      - The socket definition scope, used to configure the Sensu client socket.
  keepalives:
    description:
      - If Sensu should monitor keepalives for this client.
    type: bool
    default: true
  keepalive:
    type: dict
    description:
      - The keepalive definition scope, used to configure Sensu client keepalives behavior (for example keepalive thresholds
        and so).
  registration:
    type: dict
    description:
      - The registration definition scope, used to configure Sensu registration event handlers.
  deregister:
    description:
      - If a deregistration event should be created upon Sensu client process stop.
      - Default is V(false).
    type: bool
  deregistration:
    type: dict
    description:
      - The deregistration definition scope, used to configure automated Sensu client de-registration.
  ec2:
    type: dict
    description:
      - The ec2 definition scope, used to configure the Sensu Enterprise AWS EC2 integration (Sensu Enterprise users only).
  chef:
    type: dict
    description:
      - The chef definition scope, used to configure the Sensu Enterprise Chef integration (Sensu Enterprise users only).
  puppet:
    type: dict
    description:
      - The puppet definition scope, used to configure the Sensu Enterprise Puppet integration (Sensu Enterprise users only).
  servicenow:
    type: dict
    description:
      - The servicenow definition scope, used to configure the Sensu Enterprise ServiceNow integration (Sensu Enterprise users
        only).
a  
# Minimum possible configuration
- name: Configure Sensu client
  community.general.sensu_client:
    subscriptions:
      - default

# With customization
- name: Configure Sensu client
  community.general.sensu_client:
    name: "{{ ansible_fqdn }}"
    address: "{{ ansible_default_ipv4['address'] }}"
    subscriptions:
      - default
      - webserver
    redact:
      - password
    socket:
      bind: 127.0.0.1
      port: 3030
    keepalive:
      thresholds:
        warning: 180
        critical: 300
      handlers:
        - email
      custom:
        - broadcast: irc
      occurrences: 3
  register: client
  notify:
    - Restart sensu-client

- name: Secure Sensu client configuration file
  ansible.builtin.file:
    path: "{{ client['file'] }}"
    owner: "sensu"
    group: "sensu"
    mode: "0600"

- name: Delete the Sensu client configuration
  community.general.sensu_client:
    state: "absent"
a1  
config:
  description: Effective client configuration, when state is present.
  returned: success
  type: dict
  sample: {'name': 'client', 'subscriptions': ['default']}
file:
  description: Path to the client configuration file.
  returned: success
  type: str
  sample: "/etc/sensu/conf.d/client.json"
N)AnsibleModulec                  |   t        dt        d4i dt        dddgd      dt        d      d	t        d      d
t        dd      dt        dd      d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t        d      ddd
ggg      } | j                  d   }d}|dk(  rt        j                  j                  |      rn| j                  r&dj                  |       }| j                  |d!       n`	 t        j                  |       d"j                  |       }| j                  |d!       n$d&j                  |       }| j                  |%       d'i i}g d(}|D ]6  }|| j                  v s| j                  |   "| j                  |   |d'   |<   8 d }	 t        j                  t        |d)            }|||k(  r| j                  d*|d'   |+       | j                  sot        j                  j                  t        j                  j%                  |            s3	 t        j&                  t        j                  j%                  |             | j                  r| j                  d-d|d'   |.       	 t        |d/      5 }	|	j)                  t        j*                  |d01             | j                  d2d|d'   |.       d d d        y # t        $ r9}d#}| j                  |j                  |t        |      $      %       Y d }~d }~ww xY w# t         t"        f$ r Y iw xY w# t        $ rS}| j                  d,j                  t        j                  j%                  |      t        |            %       Y d }~+d }~ww xY w# 1 sw Y   y xY w# t        t         f$ r5}| j                  d3j                  |t        |            %       Y d }~y d }~ww xY w)5NTstatestrpresentabsent)typechoicesdefaultname)r   addresssubscriptionslist)r   elements	safe_modeboolF)r   r   redactsocketdict
keepalives	keepaliveregistration
deregisterderegistrationec2chefpuppet
servicenow)supports_check_modeargument_specrequired_ifz/etc/sensu/conf.d/client.jsonz{path} would have been deleted)path)msgchangedz{path} deleted successfullyz3Exception when trying to delete {path}: {exception})r%   	exception)r&   z{path} already does not existclient)r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   rz*Client configuration is already up to date)r&   configfilezUnable to create {0}: {1}z,Client configuration would have been updated)r&   r'   r+   r,   w   )indentzClient configuration updatedzUnable to write file {0}: {1} )r   r   paramsosr%   exists
check_modeformat	exit_jsonremoveOSError	fail_jsonr	   jsonloadopenIOError
ValueErrordirnamemakedirswritedumps)
moduler   r%   r&   er+   argsargcurrent_configr)   s
             r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/sensu_client.pymainrI      s[     
EIx+@)T
5#
 e&
 FU;	

 6
 Ve4
 V$
 6
 '
 6*
 (
  V,
 &!
 6"
 V$
  (!
& i/!23
)F2 MM'"E*D77>>$  6==4=H  S$ 7EIIdO7>>D>IC$$d$; 288d8CC% ^FED  7&--FMM#$6$B$*MM#$6F8S!7
 N4c?3
 !n&>I &x 0" 	 	$
 RWW^^BGGOOD4I%J	MKK-.
 K!% &x 0" 	 	$
	M$_ 	(LLF156!?%)$*8$4"&  (	( 	(a  EOC$$JJDCFJC % E EE. Z    	M!<!C!CBGGOOTXDYDGF"L M M	M	( 	( W M<CCDDGFL 	M 	MMsy   :L1  M6 2N O7 )?O+(O7 1	M3:.M..M36N	N		O(AO##O(+O40O7 4O7 7P;+P66P;__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr:   r2   ansible.module_utils.basicr   rI   __name__r0       rH   <module>rS      sR    A @bH+Z
  	 4_MD zF rR   