community.general.sensu_handler 模块 – 管理 Sensu 处理程序配置

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定:community.general.sensu_handler

概要

参数

参数

注释

command

字符串

要执行的处理程序命令。

事件数据通过 STDIN 传递给进程。

注意:command 属性仅对于管道处理程序(即配置为“type”:“pipe”的处理程序)是必需的。

filter

字符串

用于过滤处理程序事件的 Sensu 事件过滤器(名称)。

filters

列表 / 元素=字符串

用于过滤处理程序事件的 Sensu 事件过滤器(名称)数组。

每个数组项必须是字符串。

handle_flapping

布尔值

是否应处理处于 flapping 状态的事件。

选项

  • false ← (默认)

  • true

handle_silenced

布尔值

是否应处理与一个或多个静默条目匹配的事件。

选项

  • false ← (默认)

  • true

handlers

列表 / 元素=字符串

用于使用处理程序集的事件的 Sensu 事件处理程序(名称)数组。

注意:handlers 属性仅对于处理程序集(即配置为“type”:“set”的处理程序)是必需的。

mutator

字符串

用于变异处理程序事件数据的 Sensu 事件变异器(名称)。

name

字符串 / 必需

处理程序的唯一名称。名称不能包含特殊字符或空格。

pipe

字典

管道定义范围,用于配置 Sensu 传输管道。

注意:pipe 属性仅对于传输处理程序(即配置为“type”:“transport”的处理程序)是必需的。

severities

列表 / 元素=字符串

处理程序将处理的检查结果严重性数组。

注意:事件解决绕过此过滤。

示例:[‘warning’, ‘critical’, ‘unknown’]。

socket

字典

套接字定义范围,用于配置 TCP/UDP 处理程序套接字。

注意:socket 属性仅对于 TCP/UDP 处理程序(即配置为“type”:“tcp”或“type”:“udp”的处理程序)是必需的。

state

字符串

处理程序是否应该存在

选项

  • "present" ← (默认)

  • "absent"

timeout

整数

处理程序执行持续时间超时(秒)(强制停止)。

仅管道和 tcp 处理程序类型使用。

默认: 10

type

字符串

处理程序类型

选项

  • "pipe"

  • "tcp"

  • "udp"

  • "transport"

  • "set"

属性

属性

支持

描述

check_mode

支持:完全支持

可以在 check_mode 中运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

在 diff 模式下,将返回有关已更改内容(或可能需要在 check_mode 中更改的内容)的详细信息。

备注

注意

  • 支持检查模式

示例

# 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

# Delete a handler
- name: Delete IRC Sensu handler
  community.general.sensu_handler:
    name: "irc_handler"
    state: "absent"

# 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

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

返回值

常见的返回值已在此处记录,以下是此模块特有的字段

描述

config

字典

当状态存在时,有效的处理程序配置

返回值: 成功

示例: {"command": "/usr/local/bin/notify-irc.sh", "name": "irc", "type": "pipe"}

file

字符串

处理程序配置文件的路径

返回值: 成功

示例: "/etc/sensu/conf.d/handlers/irc.json"

name

字符串

处理程序的名称

返回值: 成功

示例: "irc"

作者

  • David Moreau Simard (@dmsimard)