community.general.sensu_handler (8.5.0) — module

Manages Sensu handler configuration

Authors: David Moreau Simard (@dmsimard)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Manages Sensu handler configuration

For more information, refer to the Sensu documentation: U(https://sensuapp.org/docs/latest/reference/handlers.html)

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Configure a handler that sends event data as STDIN (pipe)
- name: Configure IRC Sensu handler
  community.general.sensu_handler:
    name: "irc_handler"
    type: "pipe"
    command: "/usr/local/bin/notify-irc.sh"
    severities:
      - "ok"
      - "critical"
      - "warning"
      - "unknown"
    timeout: 15
  notify:
    - Restart sensu-client
    - Restart sensu-server
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Delete a handler
- name: Delete IRC Sensu handler
  community.general.sensu_handler:
    name: "irc_handler"
    state: "absent"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example of a TCP handler
- name: Configure TCP Sensu handler
  community.general.sensu_handler:
    name: "tcp_handler"
    type: "tcp"
    timeout: 30
    socket:
      host: "10.0.1.99"
      port: 4444
  register: handler
  notify:
    - Restart sensu-client
    - Restart sensu-server
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Secure Sensu handler configuration file
  ansible.builtin.file:
    path: "{{ handler['file'] }}"
    owner: "sensu"
    group: "sensu"
    mode: "0600"

Inputs

    
name:
    description:
    - A unique name for the handler. The name cannot contain special characters or spaces.
    required: true
    type: str

pipe:
    description:
    - The pipe definition scope, used to configure the Sensu transport pipe.
    - 'NOTE: the pipe attribute is only required for Transport handlers (i.e. handlers
      configured with "type": "transport").'
    type: dict

type:
    choices:
    - pipe
    - tcp
    - udp
    - transport
    - set
    description:
    - The handler type
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Whether the handler should be present or not
    type: str

filter:
    description:
    - The Sensu event filter (name) to use when filtering events for the handler.
    type: str

socket:
    description:
    - The socket definition scope, used to configure the TCP/UDP handler socket.
    - 'NOTE: the socket attribute is only required for TCP/UDP handlers (i.e. handlers
      configured with "type": "tcp" or "type": "udp").'
    type: dict

command:
    description:
    - The handler command to be executed.
    - The event data is passed to the process via STDIN.
    - 'NOTE: the command attribute is only required for Pipe handlers (i.e. handlers configured
      with "type": "pipe").'
    type: str

filters:
    description:
    - An array of Sensu event filters (names) to use when filtering events for the handler.
    - Each array item must be a string.
    elements: str
    type: list

mutator:
    description:
    - The Sensu event mutator (name) to use to mutate event data for the handler.
    type: str

timeout:
    default: 10
    description:
    - The handler execution duration timeout in seconds (hard stop).
    - Only used by pipe and tcp handler types.
    type: int

handlers:
    description:
    - An array of Sensu event handlers (names) to use for events using the handler set.
    - 'NOTE: the handlers attribute is only required for handler sets (i.e. handlers configured
      with "type": "set").'
    elements: str
    type: list

severities:
    description:
    - An array of check result severities the handler will handle.
    - 'NOTE: event resolution bypasses this filtering.'
    - 'Example: [ ''warning'', ''critical'', ''unknown'' ].'
    elements: str
    type: list

handle_flapping:
    default: false
    description:
    - If events in the flapping state should be handled.
    type: bool

handle_silenced:
    default: false
    description:
    - If events matching one or more silence entries should be handled.
    type: bool

Outputs

config:
  description: Effective handler configuration, when state is present
  returned: success
  sample:
    command: /usr/local/bin/notify-irc.sh
    name: irc
    type: pipe
  type: dict
file:
  description: Path to the handler configuration file
  returned: success
  sample: /etc/sensu/conf.d/handlers/irc.json
  type: str
name:
  description: Name of the handler
  returned: success
  sample: irc
  type: str