telekom_mms.icinga_director.icinga_command 模块 – 在 Icinga2 中管理命令

注意

此模块是 telekom_mms.icinga_director 集合 (版本 2.2.1) 的一部分。

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

要安装它,请使用: ansible-galaxy collection install telekom_mms.icinga_director

要在 playbook 中使用它,请指定: telekom_mms.icinga_director.icinga_command

telekom_mms.icinga_director 1.0.0 中的新增功能

概要

  • 通过 director API 添加或删除 Icinga2 命令。

参数

参数

注释

append

布尔值

telekom_mms.icinga_director 1.25.0 中添加

不要覆盖整个对象,而是追加定义的属性。

注意 - 无法追加到现有的变量、导入或任何其他列表/字典。您必须覆盖整个列表/字典。

注意 - 即使未设置,默认设置的变量也会应用。

选项

  • false

  • true

arguments

字典

命令的参数。

每个参数可以取字符串、JSON 或字典。

当使用字典作为参数值时,支持以下属性: skip_key, repeat_key, required, order, description), set_if, value

value 属性可以是字符串、JSON 或字典。当用作字典时,您可以将其 type 定义为 Function 并将其 body 属性设置为 Icinga DSL 配置片段。

client_cert

路径

用于 SSL 客户端身份验证的 PEM 格式证书链文件。

此文件也可以包含密钥,如果包含密钥,则不需要 client_key

client_key

路径

包含用于 SSL 客户端身份验证的私钥的 PEM 格式文件。

如果 client_cert 包含证书和密钥,则不需要此选项。

command

字符串

Icinga 应运行的命令。当 state 为 present 时,此参数是必需的。

接受提供的绝对路径,相对路径以“PluginDir +”为前缀,允许类似的常量前缀。

空格将导致命令路径和独立参数的分隔。

请注意,这意味着我们目前不支持插件名称和路径中的空格。

disabled

布尔值

已禁用的对象将不会部署。

选项

  • false ← (默认)

  • true

force

布尔值

如果 yes,则不会获取缓存的副本。

选项

  • false ← (默认)

  • true

force_basic_auth

布尔值

使用 url_usernameurl_password 指定的凭据应通过 HTTP 头传递。

选项

  • false ← (默认)

  • true

http_agent

字符串

用于识别的标头,通常出现在 Web 服务器日志中。

默认值: "ansible-httpget"

imports

列表 / 元素=字符串

可导入的模板,您可以添加任意数量的模板。请注意,从多个模板导入属性时,顺序很重要 - 最后一个模板优先。

默认值: []

methods_execute

别名:command_type

字符串

运行基础设施检查时,需要使用插件检查命令。

通知命令用于通知用户。

事件命令允许您在出现问题时触发特定操作。

有些人将其用于自动修复机制,例如在特定阈值下重启服务或系统。

选项

  • "PluginCheck" ← (默认)

  • "PluginNotification"

  • "PluginEvent"

object_name

别名:name

字符串 / 必填

命令名称。

state

字符串

应用功能状态。

选项

  • "present" ← (默认)

  • "absent"

timeout

字符串

可选命令超时时间。允许的值为秒或后缀为特定单位的持续时间(例如 1m 或 3m 30s)。

url

字符串 / 必填

HTTP、HTTPS 或 FTP URL,格式为 (http|https|ftp)://[user[:pass]]@host.domain[:port]/path

url_password

字符串

用于 HTTP 基本身份验证的密码。

如果未指定 url_username 参数,则不会使用 url_password 参数。

url_username

字符串

用于 HTTP 基本身份验证的用户名。

对于允许空密码的站点,此参数可以不用 url_password 参数一起使用。

use_gssapi

布尔值

ansible-core 2.11 中新增

使用 GSSAPI 执行身份验证,通常用于 Kerberos 或通过 Negotiate 身份验证的 Kerberos。

需要安装 Python 库 gssapi

GSSAPI 的凭据可以使用 url_username/url_password 指定,也可以使用指定自定义 Kerberos 凭据缓存的 GSSAPI 环境变量 KRB5CCNAME

即使已安装用于 NTLM 的 GSSAPI 机制,也不支持 NTLM 身份验证。

选项

  • false ← (默认)

  • true

use_proxy

布尔值

如果为 no,即使在目标主机上的环境变量中定义了代理,它也不会使用代理。

选项

  • false

  • true ← (默认)

validate_certs

布尔值

如果为 no,则不会验证 SSL 证书。

这仅应在使用自签名证书的个人控制站点上使用。

选项

  • false

  • true ← (默认)

vars

字典

命令的自定义属性。

默认值: {}

zone

字符串

Icinga 集群区域。允许手动覆盖 Director 关于将配置部署到何处的决策。

除非您深入了解 Icinga 集群堆栈的工作原理,否则应考虑不要这样做。

备注

注意

  • 此模块支持检查模式。

示例

- name: Create command
  telekom_mms.icinga_director.icinga_command:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    arguments:
      '--authpassphrase':
        value: $snmpv3_priv_key$
      '--authprotocol':
        value: $snmpv3_auth_protocol$
      '--critical':
        value: $centreon_critical$
      '--filter':
        value: $centreon_filter$
      '--hostname':
        value: $snmp_address$
      '--maxrepetitions':
        value: $centreon_maxrepetitions$
      '--mode':
        value: $centreon_mode$
      '--plugin':
        value: $centreon_plugin$
      '--privpassphrase':
        value: $snmpv3_auth_key$
      '--privprotocol':
        value: $snmpv3_priv_protocol$
      '--snmp-community':
        value: $snmp_community$
      '--snmp-timeout':
        value: $snmp_timeout$
      '--snmp-username':
        value: $snmpv3_user$
      '--snmp-version':
        value: $snmp_version$
      '--subsetleef':
        value: $centreon_subsetleef$
      '--verbose':
        set_if: $centreon_verbose$
      '--warning':
        value: $centreon_warning$
      '--dummy-arg':
        description: "dummy arg using Icinga DSL code"
        value:
          type: "Function"
          body: 'return macro("$dummy_var$")'
    command: "/opt/centreon-plugins/centreon_plugins.pl"
    command_type: "PluginCheck"
    disabled: false
    object_name: centreon-plugins
    imports:
      - centreon-plugins-template
    vars:
      centreon_maxrepetitions: 20
      centreon_subsetleef: 20
      centreon_verbose: false
      snmp_address: $address$
      snmp_timeout: 60
      snmp_version: '2'
      snmpv3_auth_key: authkey
      snmpv3_priv_key: privkey
      snmpv3_user: user

- name: Update command
  telekom_mms.icinga_director.icinga_command:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    object_name: centreon-plugins
    timeout: "1m"
    append: true

- name: Create event command
  telekom_mms.icinga_director.icinga_command:
    state: present
    url: "{{ icinga_url }}"
    url_username: "{{ icinga_user }}"
    url_password: "{{ icinga_pass }}"
    command: "/opt/scripts/restart_httpd"
    object_name: "restart_httpd"
    command_type: "PluginEvent"
    arguments:
      '-s':
        value: $service.state$
      '-t':
        value: $service.state_type$
      '-a':
        set_if: $service.check_attempt$
        value: $restart_service$

作者

  • Sebastian Gumprich (@rndmh3ro)