
    Vh)                         d dl mZmZmZ eZddgddZ edd      Z ed	d
d      Z	 ed      Z
 ed      ZdZdZdZd dlmZ ddlmZmZmZ d Zd Zd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1stableinterface	certified)metadata_versionstatussupported_byzpipeline/v1zcore/v2)v1v2HandlerTCPStreamHandlerSumoLogicMetricsHandlerhandlertcp_stream_handlersumo_logic_metrics_handlerMutator)mutatorEventFilter)event_filteraj  
module: pipeline
author:
  - Domen Dobnikar (@domen_dobnikar)
short_description: Manage Sensu pipeline
description:
  - Create, update or delete a Sensu pipeline.
  - For more information, refer to the Sensu documentation at
    U(https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/pipelines/).
version_added: 1.14.0
extends_documentation_fragment:
  - sensu.sensu_go.auth
  - sensu.sensu_go.name
  - sensu.sensu_go.namespace
  - sensu.sensu_go.state
  - sensu.sensu_go.labels
seealso:
  - module: sensu.sensu_go.socket_handler
  - module: sensu.sensu_go.handler_info
  - module: sensu.sensu_go.pipe_handler
  - module: sensu.sensu_go.filter
  - module: sensu.sensu_go.filter_info
  - module: sensu.sensu_go.mutator
  - module: sensu.sensu_go.mutator_info
options:
  workflows:
    description:
      - Array of workflows (by names) to use when filtering, mutating, and handling observability events with a pipeline.
    type: list
    elements: dict
    suboptions:
      name:
        description:
          - Name of the Sensu pipeline workflow.
        type: str
        required: true
      filters:
        description:
          - Reference for the Sensu event filters to use when filtering events for the pipeline.
          - Each pipeline workflow can reference more than one event filter.
          - If a workflow has more than one filter, Sensu applies the filters in a series, starting with the filter that is listed first.
        type: list
        elements: dict
        suboptions:
          name:
            description:
              - Name of the Sensu event filter to use for the workflow.
              - You can use the built-in event filters, as well as your existing event filters, in pipeline workflows.
            type: str
            required: true
          type:
            description:
              - The sensuctl create resource type for the event filter.
              - Event filters should always be type EventFilter.
            type: str
            default: event_filter
            choices: [ event_filter ]
      mutator:
        description:
          - Reference for the Sensu mutator to use to mutate event data for the workflow.
          - Each pipeline workflow can reference only one mutator.
        type: dict
        suboptions:
          name:
            description:
              - Name of the Sensu mutator to use for the workflow.
              - You can use your existing mutators in pipeline workflows.
            type: str
            required: true
          type:
            description:
              - The sensuctl create resource type for the mutator.
              - Mutators should always be type Mutator.
            type: str
            default: mutator
            choices: [ mutator ]
      handler:
        description:
          - Reference for the Sensu handler to use for event processing in the workflow.
          - Each pipeline workflow must reference one handler.
          - Pipelines ignore any filters and mutators specified in handler definitions.
        type: dict
        required: true
        suboptions:
          name:
            description:
              - Name of the Sensu handler to use for the workflow.
              - You can use your existing handlers in pipeline workflows.
              - Pipelines ignore any filters and mutators specified in handler definitions.
            type: str
            required: true
          type:
            description:
              - The sensuctl create resource type for the handler.
            type: str
            required: true
            choices: [ handler, tcp_stream_handler, sumo_logic_metrics_handler ]
a  
- name: Create a pipeline
  sensu.sensu_go.pipeline:
    name: this_pipeline
    workflows:
      - name: this-wf
        handler:
          name: this_handler
          type: tcp_stream_handler
        filters:
          - name: this_filter
          - name: this_filter_2
        mutator:
          name: this_mutator

- name: Delete pipeline
  sensu.sensu_go.pipeline:
    name: this_pipeline
    state: absent
a  
object:
  description: Object representing Sensu pipeline.
  returned: success
  type: dict
  sample:
    metadata:
      created_by: admin
      name: this_pipeline
      namespace: default
    workflows:
      - filters:
          - api_version: core/v2
            name: this_filter
            type: EventFilter
          - api_version: core/v2
            name: this_filter_2
            type: EventFilter
        handler:
          api_version: pipeline/v1
          name: this_handler
          type: TCPStreamHandler
        mutator:
          api_version: core/v2
          name: this_mutator
          type: Mutator
        name: this-wf
)AnsibleModule   )	argumentserrorsutilsc                 0    t        j                  | |d      S )N	pipelines)r   	do_differ)currentdesireds     k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/sensu/sensu_go/plugins/modules/pipeline.pyr   r      s    +6    c                 :    t         | d      | d<   t        d   | d<   y )Ntyper   api_version)MUTATOR_TYPEAPI_VERSION)payload_mutators    r"   handle_mutator_api_and_typer*      s%    *?6+BCOF%0%6OM"r#   c                 h    d}|d   D ](  }t         |d      | |   d<   t        d   | |   d<   |dz  }* y )Nr   filtersr%   r   r&      )FILTER_TYPEr(   )payload_filtersworkflowfilter_countfilters       r"   handle_filter_api_and_typer3      sQ    L9% 0;F6N0K%f-7B47H%m4r#   c                 b    | d   dv rt         d   | d<   nt         d   | d<   t        | d      | d<   y )Nr%   )r   r   r   r&   r   )r(   HANDLER_TYPE)payload_handlers    r"   handle_handler_api_and_typer7      sB    v"VV)4T):&)4T):&*?6+BCOFr#   c                    d}| j                   d   D ]  }t        |d   |   d          |j                  d      rt        |d   |   d          n!d|d   |   v r|d   |   j	                  d       |j                  d      rt        |d   |   d   |       n!d|d   |   v r|d   |   j	                  d       |dz  } y )Nr   	workflowsr   r   r,   r-   )paramsr7   getr*   popr3   )modulepayloadpayload_countr0   s       r"   handle_api_version_and_typesr@      s    MMM+. #GK$8$G	$RS <<	"'(<](KI(VW'+.}==K /33I> <<	"&$]3I>J'+.}==K /33I>!r#   c                     dddgfg} t        | dt        t        j                  ddddd      t        d	d
t        t        dd      t        d	d
t        t        dd      t        dddg                  t        d
t        t        dd      t        dddg                  t        d
dt        t        dd      t        ddg d                                          }t        j                  |j
                  d         }t        j                  |j
                  d   d|j
                  d         }t        j                  |j
                  d      }|j
                  d   dk(  rt        ||       	 t        j                  |j
                  d   ||||j                  t              \  }}|j                  ||       y # t        j                  $ r%}|j!                  t#        |             Y d }~y d }~ww xY w)Nstatepresentr9   Tauthname	namespacelabelslistdictstr)r%   requiredr   )r%   defaultchoices)rE   r%   )r%   elementsoptionsr   )r%   rO   r   )r%   rK   rM   )r%   rK   rO   )rE   r,   r   r   )r9   )required_ifsupports_check_modeargument_specr   )changedobject)msg)r   rI   r   get_specget_sensu_clientr:   r   build_core_v2_pathget_mutation_payloadr@   sync
check_moder   	exit_jsonr   Error	fail_jsonrJ   )rP   r=   clientpathr>   rS   r   es           r"   mainrb      s   	)k]+K  h "!% !#!' $!%%*)-" "&%*(6$2)""!" !# $!%%*)-" "&%*(1$-)""!  !#!% $!%%*)-" "&%*)-)""!M9=	B
FFN ''f(=>F##k"Kv1FD ,,{G }}W*$VW5% ::MM'"FD'6;L;L
 	9<< %SV$$%s   ;AG G?G::G?__main__N)
__future__r   r   r   r%   __metaclass__ANSIBLE_METADATArI   r(   r5   r'   r.   DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utilsr   r   r   r   r*   r3   r7   r@   rb   __name__ r#   r"   <module>rn      s    A @  ! 
 m	2I:L  jC  DI&.aF*
: 5 3 37
D*[%| zF r#   