community.zabbix.zabbix_httptest module – Create/delete Zabbix httptests aka Web Scenarios

Note

This module is part of the community.zabbix collection (version 4.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.zabbix. You need further requirements to be able to use this module, see Requirements for details.

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

Synopsis

  • Create httptests if they do not exist.

  • Delete existing httptests if they exist.

Requirements

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

  • python >= 3.9

Parameters

Parameter

Comments

host_name

string / required

Name of host to add httptest to.

http_login_password

string

Basic Auth password

http_login_user

string

Basic Auth login

name

string / required

Name of httptest to create or delete.

params

dictionary

Parameters to create/update httptest with.

Required if state is “present”.

Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/httptest/object

Additionally supported parameters are below.

agent

string

User agent string used by the httptest.

attempts

integer

Number of attempts before failing the httptest

Alias for “retries” in API docs

authentication

string

HTTP authentication method used by the httptest.

Choices:

  • "none"

  • "basic"

  • "ntlm"

enabled

boolean

Status of the httptest.

Overrides “status” in API docs.

Choices:

  • false

  • true

headers

list / elements=dictionary

HTTP headers used when performing the httptest.

Overriden by steps headers.

name

string / required

Name of the header field.

value

string / required

Value of the header field.

http_proxy

string

HTTP(S) proxy used by the httptest

interval

string

Update interval of the httptest.

Alias for “delay” in API docs.

new_name

string

New name for httptest

password

string

Password to authenticate with the host.

Used if authentication is one of basic or ntlm

Alias for “http_password” in API docs.

ssl_cert_file

string

Public SSL key file path for client authentication.

ssl_key_file

string

Private SSL key file path for client authentication.

ssl_key_password

string

Password of the private SSL key file.

status

string

Status of the httptest.

Choices:

  • "enabled"

  • "disabled"

steps

list / elements=dictionary

Scenario steps for the httptest

Required if state is “present” and creating an httptest.

follow_redirects

boolean

Whether to follow HTTP redirects.

Choices:

  • false

  • true

headers

list / elements=dictionary

HTTP headers used when performing the scenario step.

Overrides params headers.

name

string / required

Name of the header field.

value

string / required

Value of the header field.

name

string / required

Name of the scenario step.

posts

list / elements=dictionary

POST variables for the scenario step.

name

string / required

Name of the POST field.

value

string / required

Value of the POST field.

query_field

list / elements=dictionary

Query fields used when performing the scenario step.

name

string / required

Name of the query field.

value

string / required

Value of the query field.

required

string

Text that must be present in the response.

retrieve_mode

string

Part of the HTTP response that the scenario step must retrieve.

Choices:

  • "only_body"

  • "only_headers"

  • "headers_and_body"

status_codes

list / elements=integer

Expected response status code.

timeout

string

Request timeout of the scenario step.

url

string / required

URL to be checked.

variables

list / elements=dictionary

Variables used when performing the scenario step.

Overrides params variables.

name

string / required

Name of the variable field.

value

string / required

Value of the variable field.

tags

list / elements=dictionary

Tags of the httptest.

tag

string / required

Name of the httptest tag.

value

string

Value of the httptest tag.

username

string

Username to authenticate with the host.

Used if authentication is one of basic or ntlm

Alias for “http_user” in API docs.

variables

list / elements=dictionary

httptest variables.

Overriden by steps variables.

name

string / required

Name of the variable field.

value

string / required

Value of the variable field.

verify_host

boolean

Whether the httptest should verify the host’s hostname.

Choices:

  • false

  • true

verify_peer

boolean

Whether the httptest should verify the host’s certificate.

Choices:

  • false

  • true

state

string

Create or delete httptest.

Choices:

  • "present" ← (default)

  • "absent"

Examples

# 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 a web scenario on example_host
- name: create httptest
  # 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_httptest:
    name: example_host_website
    host_name: example_host
    params:
      steps:
        - name: Test
          url: https://zabbix-example-fqdn.org
          status_code: [200]
      interval: 1h
      enabled: True
    state: present

# Change interval for existing Zabbix web scenario
- name: update rule
  # 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_discoveryrule:
    name: example_host_website
    host_name: example_host
    params:
      interval: 2h
    state: present

# Delete web scenario
- name: delete rule
  # 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_discoveryrule:
    name: example_host_website
    host_name: example_host
    state: absent

- name: Rename Zabbix web scenario
  # 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_discoveryrule:
    name: example_host_website
    host_name: example_host
    params:
      new_name: new_example_host_website
    state: present

Authors

  • Trystan Mata (@tytan652)