community.zabbix.zabbix_discovery_rule – Create/delete/update Zabbix discovery rules

Note

This plugin is part of the community.zabbix collection (version 1.3.0).

To install it use: ansible-galaxy collection install community.zabbix.

To use it in a playbook, specify: community.zabbix.zabbix_discovery_rule.

Synopsis

  • Create discovery rule.

  • Delete existing discovery rule.

  • Update existing discovery rule with new options.

Requirements

The below requirements are needed on the host that executes this module.

  • zabbix-api >= 0.5.4

Parameters

Parameter Choices/Defaults Comments
dchecks
list / elements=dictionary
List of dictionaries of discovery check objects.
For more information, review discovery check object documentation at https://www.zabbix.com/documentation/current/manual/api/reference/dcheck/object

aliases: dcheck
host_source
string
    Choices:
  • DNS ←
  • IP
  • discovery
Source for host name.
Possible values:
DNS (default)
IP
discovery - discovery value of this check
Options is available since Zabbix 4.4
key
string
The value of this property differs depending on the type of the check:
- key to query for Zabbix agent checks
- SNMP OID for SNMPv1, SNMPv2 and SNMPv3 checks
name_source
string
    Choices:
  • None ←
  • DNS
  • IP
  • discovery
Source for visible name.
Possible values:
none - (default) not specified
DNS
IP
discovery - discovery value of this check
Options is available since Zabbix 4.4
ports
string
One or several port ranges to check separated by commas. Used for all checks except for ICMP.
snmp_community
string
SNMP community.
Required for SNMPv1 and SNMPv2 agent checks.
snmpv3_authpassphrase
string
Authentication passphrase used for SNMPv3 agent checks with security level set to authNoPriv or authPriv.
snmpv3_authprotocol
string
    Choices:
  • MD5
  • SHA
Authentication protocol used for SNMPv3 agent checks with security level set to authNoPriv or authPriv.
Possible values:
MD5
SHA
snmpv3_contextname
string
SNMPv3 context name. Used only by SNMPv3 checks.
snmpv3_privpassphrase
string
Privacy passphrase used for SNMPv3 agent checks with security level set to authPriv.
snmpv3_privprotocol
string
    Choices:
  • DES
  • AES
Privacy protocol used for SNMPv3 agent checks with security level set to authPriv.
Possible values:
DES
AES
snmpv3_securitylevel
string
    Choices:
  • noAuthNoPriv
  • authNoPriv
  • authPriv
Security level used for SNMPv3 agent checks.
Possible values:
noAuthNoPriv
authNoPriv
authPriv
snmpv3_securityname
string
Security name used for SNMPv3 agent checks.
type
string
    Choices:
  • SSH
  • LDAP
  • SMTP
  • FTP
  • HTTP
  • POP
  • NNTP
  • IMAP
  • TCP
  • Zabbix
  • SNMPv1
  • SNMPv2
  • ICMP
  • SNMPv3
  • HTTPS
  • Telnet
Type of check.
uniq
boolean
    Choices:
  • no ←
  • yes
Whether to use this check as a device uniqueness criteria.
Only a single unique check can be configured for a discovery rule.
Used for Zabbix agent, SNMPv1, SNMPv2 and SNMPv3 agent checks.
Possible values:
no - (default) do not use this check as a uniqueness criteria
yes - use this check as a uniqueness criteria
delay
string
Default:
"1h"
Execution interval of the discovery rule.
Accepts seconds, time unit with suffix and user macro.
http_login_password
string
Basic Auth password
http_login_user
string
Basic Auth login
iprange
list / elements=string
One or several IP ranges to check separated by commas.
login_password
string / required
Zabbix user password.
login_user
string / required
Zabbix user name.
name
string / required
Name of the discovery rule.
proxy
string
Name of the proxy used for discovery.
server_url
string / required
URL of Zabbix server, with protocol (http or https). url is an alias for server_url.

aliases: url
state
string
    Choices:
  • present ←
  • absent
Create or delete discovery rules.
status
string
    Choices:
  • enabled ←
  • disabled
Whether the discovery rule is enabled.
Possible values:
enabled (default)
disabled
timeout
integer
Default:
10
The timeout of API request (seconds).
validate_certs
boolean
    Choices:
  • no
  • yes ←
If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Notes

Note

  • Only Zabbix >= 4.0 is supported.

  • If you use login_password=zabbix, the word “zabbix” is replaced by “****” in all module output, because login_password uses no_log. See this FAQ for more information.

Examples

# Base create discovery rule example
- name: Create discovery rule with ICMP and zabbix agent checks
  community.zabbix.zabbix_discovery_rule:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: admin
    login_password: secret
    name: ACME
    state: present
    iprange: 192.168.1.1-255
    dchecks:
        - type: ICMP
        - type: Zabbix
          key: "system.hostname"
          ports: 10050
          uniq: yes
          host_source: "discovery"

# Base update (add new dcheck) discovery rule example
- name: Create discovery rule with ICMP and zabbix agent checks
  community.zabbix.zabbix_discovery_rule:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: admin
    login_password: secret
    name: ACME
    state: present
    iprange: 192.168.1.1-255
    dchecks:
        - type: SNMPv3
          snmp_community: CUSTOMER@snmp3-readonly
          ports: "161"
          key: iso.3.6.1.2.1.1.1.0
          snmpv3_contextname: "ContextName"
          snmpv3_securityname: "SecurityName"
          snmpv3_securitylevel: "authPriv"
          snmpv3_authprotocol: "SHA"
          snmpv3_authpassphrase: "SeCrEt"
          snmpv3_privprotocol: "AES"
          snmpv3_privpassphrase: "TopSecret"
          uniq: no
          host_source: "DNS"
          name_source: "None"

# Base delete discovery rule example
- name: Delete discovery rule
  community.zabbix.zabbix_discovery_rule:
    server_url: "http://zabbix.example.com/zabbix/"
    login_user: admin
    login_password: secret
    name: ACME
    state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
drule
string
on success
Discovery rule name.

Sample:
ACME
druleid
string
on success
Discovery rule id.

Sample:
42
msg
string
always
The result of the operation

Sample:
Discovery rule created: ACME, ID: 42
state
string
on success
Discovery rule state at the end of execution.

Sample:
present


Authors

  • Tobias Birkefeld (@tcraxs)