community.zabbix.zabbix_item 模块 – 创建/删除 Zabbix 监控项
注意
此模块是 community.zabbix 集合(版本 3.2.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install community.zabbix
。您需要其他要求才能使用此模块,请参阅 要求 了解详细信息。
要在 Playbook 中使用它,请指定: community.zabbix.zabbix_item
。
概要
如果监控项不存在则创建它们。
如果监控项存在则删除它们。
要求
执行此模块的主机需要以下要求。
python >= 2.6
参数
参数 |
注释 |
---|---|
要向其添加监控项的主机名称。 当未使用 *template_name* 时是必需的。 与 *template_name* 互斥。 |
|
基本身份验证密码 |
|
基本身份验证登录名 |
|
要创建或删除的监控项的名称。 |
|
用于创建/更新监控项的参数。 如果状态为 “present”,则为必需。 参数的定义请参阅 https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object 此外,还支持以下参数 |
|
监控项的状态。 覆盖 API 文档中的 “status” 选项
|
|
监控项的更新间隔。 API 文档中 “delay” 的别名 |
|
监控项键值。 API 文档中 “key_” 的别名 |
|
作为当前监控项主项的监控项 覆盖 API 文档中的 “master_itemid” |
|
主监控项所属主机的名称 当未使用 *template_name* 时是必需的。 与 *template_name* 互斥。 |
|
主监控项的名称 |
|
主监控项所属的模板名称 当未使用 *host_name* 时是必需的。 与 *host_name* 互斥。 |
|
监控项预处理选项。 参数的定义请参阅 https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object#item-preprocessing 此外,还支持以下参数 |
|
预处理步骤失败时使用的操作类型。 选项
|
|
预处理选项类型。 选项
|
|
监控项的状态。 选项
|
|
监控项的类型。 如果状态为 “present”,则为必需。 选项
|
|
监控项的信息类型。 如果状态为 “present”,则为必需。 选项
|
|
创建或删除监控项。 选项
|
|
要向其添加监控项的模板名称。 当未使用 *host_name* 时是必需的。 与 *host_name* 互斥。 |
示例
# If you want to use Username and Password to be authenticated by Zabbix Server
- name: Set credentials to access Zabbix Server API
ansible.builtin.set_fact:
ansible_user: Admin
ansible_httpapi_pass: zabbix
# If you want to use API token to be authenticated by Zabbix Server
# https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/administration/general#api-tokens
- name: Set API token
ansible.builtin.set_fact:
ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
# Create ping item on example_host
- name: create ping item
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: 'zabbixeu' # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_item:
name: agent_ping
host_name: example_host
params:
type: zabbix_agent
key: agent.ping
value_type: numeric_unsigned
interval: 1m
state: present
# Create ping item on example_template
- name: create ping item
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: 'zabbixeu' # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_item:
name: agent_ping
template_name: example_template
params:
type: zabbix_agent
key: agent.ping
value_type: numeric_unsigned
interval: 1m
state: present
- name: Add tags to the existing Zabbix item
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_item:
name: agent_ping
template_name: example_template
params:
type: zabbix_agent
key: agent.ping
value_type: numeric_unsigned
interval: 1m
tags:
- tag: class
value: application
state: present
- name: create a dependent item
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_item:
name: depend_item
host_name: example_host
params:
type: dependent_item
key: vfs.fs.pused
value_type: numeric_float
units: '%'
master_item:
item_name: example_item
host_name: example_host
preprocessing:
- type: jsonpath
params: '$[?(@.fstype == "ext4")]'
error_handler: zabbix_server
- type: jsonpath
params: "$[*].['bytes', 'inodes'].pused.max()"
error_handler: zabbix_server
state: present
- name: Delete Zabbix item
# set task level variables as we change ansible_connection plugin here
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
ansible_host: zabbix-example-fqdn.org
community.zabbix.zabbix_item:
name: agent_ping
template_name: example_template
state: absent