community.general.oneandone_monitoring_policy 模块 – 配置 1&1 监控策略

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。

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

概要

  • 创建、删除、更新监控策略(并添加/删除端口、进程和服务器)。此模块依赖于 1and1 >= 1.0。

要求

执行此模块的主机需要以下要求。

  • 1and1

参数

参数

注释

add_ports

列表 / 元素=字典

要添加到监控策略的端口。

默认值: []

add_processes

列表 / 元素=字典

要添加到监控策略的进程。

默认值: []

add_servers

列表 / 元素=字符串

要添加到监控策略的服务器。

默认值: []

agent

字符串

设置为 true 以使用代理。

api_url

字符串

自定义 API URL。覆盖 ONEANDONE_API_URL 环境变量。

auth_token

字符串

由 1&1 提供的身份验证 API 令牌。

description

字符串

监控策略描述。maxLength=256

email

字符串

用户的电子邮件。maxLength=128

monitoring_policy

字符串

用于更新状态的监控策略的标识符(id 或名称)。

name

字符串

与 present 状态一起使用的监控策略名称。与 absent 状态一起使用时用作标识符(id 或名称)。maxLength=128

ports

列表 / 元素=字典

将要监控的端口数组。

默认值: []

alert_if

字符串 / 必需

警报的情况。

选择

  • "RESPONDING"

  • "NOT_RESPONDING"

email_notification

字符串 / 必需

设置为 true 以发送电子邮件通知。

port

字符串 / 必需

端口号。最小值=1,最大值=65535

protocol

字符串 / 必需

Internet 协议。

选择

  • "TCP"

  • "UDP"

processes

列表 / 元素=字典

将要监控的进程数组。

默认值: []

alert_if

字符串 / 必需

警报的情况。

选择

  • "RUNNING"

  • "NOT_RUNNING"

process

字符串 / 必需

进程的名称。maxLength=50

remove_ports

列表 / 元素=字符串

要从监控策略中删除的端口。

默认值: []

remove_processes

列表 / 元素=字符串

要从监控策略中删除的进程。

默认值: []

remove_servers

列表 / 元素=字符串

要从监控策略中删除的服务器。

默认值: []

state

字符串

定义监控策略的状态以创建、删除、更新。

选择

  • "present" ←(默认)

  • "absent"

  • "update"

thresholds

列表 / 元素=字典

监控策略阈值。每个子选项都有警告和严重,两者都有警报和值子选项。警告用于设置警告警报的限制,严重用于设置严重警报。警报启用警报,值用于提示何时超出该值。

默认值: []

cpu

字符串 / 必需

CPU 的消耗限制。

disk

字符串 / 必需

硬盘的消耗限制。

internal_ping

字符串 / 必需

内部 ping 的响应限制。

ram

字符串 / 必需

RAM 的消耗限制。

transfer

字符串 / 必需

传输的消耗限制。

update_ports

列表 / 元素=字典

要在监控策略上更新的端口。

默认值: []

update_processes

列表 / 元素=字典

要在监控策略上更新的进程。

默认值: []

wait

布尔值

在返回之前等待实例处于“正在运行”状态

选择

  • false

  • true ←(默认)

wait_interval

整数

定义在使用 _wait_for 方法时等待的秒数

默认值: 5

wait_timeout

整数

等待放弃之前的时长(以秒为单位)

默认值: 600

属性

属性

支持

描述

check_mode

支持:完整

可以在 check_mode 中运行并返回更改的状态预测,而无需修改目标。

diff_mode

支持:

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

示例

- name: Create a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    name: ansible monitoring policy
    description: Testing creation of a monitoring policy with ansible
    email: [email protected]
    agent: true
    thresholds:
     -
       cpu:
         warning:
           value: 80
           alert: false
         critical:
           value: 92
           alert: false
     -
       ram:
         warning:
           value: 80
           alert: false
         critical:
           value: 90
           alert: false
     -
       disk:
         warning:
           value: 80
           alert: false
         critical:
           value: 90
           alert: false
     -
       internal_ping:
         warning:
           value: 50
           alert: false
         critical:
           value: 100
           alert: false
     -
       transfer:
         warning:
           value: 1000
           alert: false
         critical:
           value: 2000
           alert: false
    ports:
     -
       protocol: TCP
       port: 22
       alert_if: RESPONDING
       email_notification: false
    processes:
     -
       process: test
       alert_if: NOT_RUNNING
       email_notification: false
    wait: true

- name: Destroy a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    state: absent
    name: ansible monitoring policy

- name: Update a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy
    name: ansible monitoring policy updated
    description: Testing creation of a monitoring policy with ansible updated
    email: [email protected]
    thresholds:
     -
       cpu:
         warning:
           value: 70
           alert: false
         critical:
           value: 90
           alert: false
     -
       ram:
         warning:
           value: 70
           alert: false
         critical:
           value: 80
           alert: false
     -
       disk:
         warning:
           value: 70
           alert: false
         critical:
           value: 80
           alert: false
     -
       internal_ping:
         warning:
           value: 60
           alert: false
         critical:
           value: 90
           alert: false
     -
       transfer:
         warning:
           value: 900
           alert: false
         critical:
           value: 1900
           alert: false
    wait: true
    state: update

- name: Add a port to a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    add_ports:
     -
       protocol: TCP
       port: 33
       alert_if: RESPONDING
       email_notification: false
    wait: true
    state: update

- name: Update existing ports of a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    update_ports:
     -
       id: existing_port_id
       protocol: TCP
       port: 34
       alert_if: RESPONDING
       email_notification: false
     -
       id: existing_port_id
       protocol: TCP
       port: 23
       alert_if: RESPONDING
       email_notification: false
    wait: true
    state: update

- name: Remove a port from a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    remove_ports:
     - port_id
    state: update

- name: Add a process to a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    add_processes:
     -
       process: test_2
       alert_if: NOT_RUNNING
       email_notification: false
    wait: true
    state: update

- name: Update existing processes of a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    update_processes:
     -
       id: process_id
       process: test_1
       alert_if: NOT_RUNNING
       email_notification: false
     -
       id: process_id
       process: test_3
       alert_if: NOT_RUNNING
       email_notification: false
    wait: true
    state: update

- name: Remove a process from a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    remove_processes:
     - process_id
    wait: true
    state: update

- name: Add server to a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    add_servers:
     - server id or name
    wait: true
    state: update

- name: Remove server from a monitoring policy
  community.general.oneandone_monitoring_policy:
    auth_token: oneandone_private_api_key
    monitoring_policy: ansible monitoring policy updated
    remove_servers:
     - server01
    wait: true
    state: update

返回值

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

描述

monitoring_policy

字典

有关已处理的监控策略的信息

返回: 总是

示例: {"id": "92B74394A397ECC3359825C1656D67A6", "name": "默认 策略"}

作者

  • Amel Ajdinovic (@aajdinov)

  • Ethan Devenport (@edevenport)