Skip to content

Create discovery actions with zabbix_action module not possible #1487

Open
@w3ich3rt

Description

@w3ich3rt

I think something similar was reported in the past and should be fixed as well, but I run into the similar error.
The related issue would be #1409 #1460

SUMMARY

I have a discovery rule that has multiple checks and want to create different actions for the different checks.

Image

I want to create a discovery rule for some of the checks to do something, if http or https is detected.
I can create a lot of these separate checks automatically, but not for that kind of checks, where the port is in the name of the check.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

The component should be zabbix_actions.

ANSIBLE VERSION
ansible [core 2.18.3]
  config file = None
  configured module search path = ['/home/um3n/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.13/site-packages/ansible
  ansible collection location = /home/um3n/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.13.2 (main, Feb  5 2025, 08:05:21) [GCC 14.2.1 20250128] (/usr/bin/python)
  jinja version = 3.1.5
  libyaml = True

#-----------------

❯ ansible-galaxy collection list

# /home/um3n/.ansible/collections/ansible_collections
Collection                               Version
---------------------------------------- -------
community.zabbix                         3.3.0

# /usr/lib/python3.13/site-packages/ansible_collections
Collection                               Version
---------------------------------------- -------
amazon.aws                               9.2.0
ansible.netcommon                        7.1.0
ansible.posix                            1.6.2
ansible.utils                            5.1.2
ansible.windows                          2.7.0
arista.eos                               10.1.1
awx.awx                                  24.6.1
azure.azcollection                       3.2.0
check_point.mgmt                         6.4.0
chocolatey.chocolatey                    1.5.3
cisco.aci                                2.10.1
cisco.asa                                6.1.0
cisco.dnac                               6.30.0
cisco.intersight                         2.0.20
cisco.ios                                9.1.1
cisco.iosxr                              10.3.0
cisco.ise                                2.10.0
cisco.meraki                             2.20.8
cisco.mso                                2.9.0
cisco.nxos                               9.3.0
cisco.ucs                                1.15.0
cloud.common                             4.0.0
cloudscale_ch.cloud                      2.4.1
community.aws                            9.0.0
community.ciscosmb                       1.0.10
community.crypto                         2.25.0
community.digitalocean                   1.27.0
community.dns                            3.2.1
community.docker                         4.4.0
community.general                        10.4.0
community.grafana                        2.1.0
community.hashi_vault                    6.2.0
community.hrobot                         2.1.0
community.library_inventory_filtering_v1 1.0.2
community.libvirt                        1.3.1
community.mongodb                        1.7.9
community.mysql                          3.12.0
community.network                        5.1.0
community.okd                            4.0.1
community.postgresql                     3.10.2
community.proxysql                       1.6.0
community.rabbitmq                       1.4.0
community.routeros                       3.4.0
community.sap_libs                       1.4.2
community.sops                           2.0.2
community.vmware                         5.4.0
community.windows                        2.3.0
community.zabbix                         3.2.0
containers.podman                        1.16.3
cyberark.conjur                          1.3.2
cyberark.pas                             1.0.30
dellemc.enterprise_sonic                 2.5.1
dellemc.openmanage                       9.10.0
dellemc.powerflex                        2.6.0
dellemc.unity                            2.0.0
f5networks.f5_modules                    1.34.1
fortinet.fortimanager                    2.9.0
fortinet.fortios                         2.3.9
google.cloud                             1.5.1
grafana.grafana                          5.7.0
hetzner.hcloud                           4.2.2
ibm.qradar                               4.0.0
ibm.spectrum_virtualize                  2.0.0
ibm.storage_virtualize                   2.6.0
ieisystem.inmanage                       3.0.0
infinidat.infinibox                      1.4.5
infoblox.nios_modules                    1.8.0
inspur.ispim                             2.2.3
junipernetworks.junos                    9.1.0
kaytus.ksmanage                          2.0.0
kubernetes.core                          5.1.0
kubevirt.core                            2.1.0
lowlydba.sqlserver                       2.5.0
microsoft.ad                             1.8.0
netapp.cloudmanager                      21.24.0
netapp.ontap                             22.14.0
netapp.storagegrid                       21.14.0
netapp_eseries.santricity                1.4.1
netbox.netbox                            3.20.0
ngine_io.cloudstack                      2.5.0
openstack.cloud                          2.4.1
ovirt.ovirt                              3.2.0
purestorage.flasharray                   1.33.1
purestorage.flashblade                   1.19.2
sensu.sensu_go                           1.14.0
splunk.es                                4.0.0
telekom_mms.icinga_director              2.2.2
theforeman.foreman                       4.2.0
vmware.vmware                            1.10.1
vmware.vmware_rest                       4.6.0
vultr.cloud                              1.13.0
vyos.vyos                                5.0.0
wti.remote                               1.0.10
CONFIGURATION
❯ ansible-config dump --only-changed
CONFIG_FILE() = None

GALAXY_SERVERS:
OS / ENVIRONMENT / Zabbix Version

Running on ARCH Linux directly against Zabbix 7.0 API.

{"jsonrpc":"2.0","result":"7.0.10","id":1}
STEPS TO REPRODUCE

This would be my playbook:

# Main structure for adding autoenrollment (discovery-rules and actions)
# Adding the discovery-rule
- block:
  - name: "[AUTOENROLLMENT][ZABBIX][DISCOVERY] Adding customer discovery rule [TASK 01]"
    community.zabbix.zabbix_discovery_rule:
      name: "{{ customer_short }} Discoveryrule [AutoEnrollment]"
      state: present
      iprange: '{{ disc_ipranges }}'
      proxy: '{{ proxy_name }}'
      delay: '24h'
      status: 'disabled'
      dchecks:
        - type: 'ICMP'
          host_source: 'DNS'
          name_source: 'DNS'
        - type: 'FTP'
          ports: '21'
        - type: 'HTTP'
          ports: '80'
        - type: 'HTTPS'
          ports: '443'
        - type: 'LDAP'
          ports: '636'
        - type: 'SMTP'
          ports: '25'
        - type: 'SSH'
          ports: '22'
        - type: 'Telnet'
          ports: '23'
        - type: 'TCP'
          ports: '161'
        - type: 'TCP'
          ports: '1433'
        - type: 'TCP'
          ports: '2598'
        - type: 'TCP'
          ports: '3306'
        - type: 'TCP'
          ports: '3389'
        - type: 'TCP'
          ports: '5000'

## Including subtasks (for readability)
#  Each discovery action would be an own task.

- include_tasks: disc_create-host.yaml
- include_tasks: disc_delete_webservice_tags.yaml
- include_tasks: disc_add_citrix_tag.yaml
- include_tasks: disc_add_ftp_tag.yaml
- include_tasks: disc_add_http_tag.yaml
- include_tasks: disc_add_https_tag.yaml
- include_tasks: disc_add_ldap_tag.yaml
- include_tasks: disc_add_mssql_tag.yaml
- include_tasks: disc_add_mysql_tag.yaml
- include_tasks: disc_add_nas_tag.yaml
- include_tasks: disc_add_rdp_tag.yaml
- include_tasks: disc_add_smtp_tag.yaml
- include_tasks: disc_add_snmp_tag.yaml
- include_tasks: disc_add_ssh_tag.yaml
- include_tasks: disc_add_telnet_tag.yaml

#### This one works (an example)
### This task creates the discovery action to add ftp tags.
#
# This task creates the discovery action to
# add ftp tag, if ftp is found on the host.

- block:
  - name: "[AUTOENROLLMENT][ZABBIX][DISCOVERY] Add discovery action: Add FTP Tag [TASK 06]"
    community.zabbix.zabbix_action:
      name: "CUS - {{ customer_short }} - FTP"
      event_source: "discovery"
      state: 'present'
      status: 'enabled'
      eval_type: 'and'
      esc_period: 60
      conditions:
        - type: 'discovery_rule'
          operator: 'equals'
          value: '{{ customer_short }} Discoveryrule [AutoEnrollment]'
        - type: 'discovery_check'
          operator: 'equals'
          value: '{{ customer_short }} Discoveryrule [AutoEnrollment]: FTP'
        - type: 'discovery_status'
          operator: 'equals'
          value: 'discovered'
      operations:
        - type: 'add_host_tags'
          tags:
            - tag: 'discovered'
              value: 'ftp'

#### This one works not (as example)
### This task creates the discovery action to add ldap tags.
#
# This task creates the discovery action to
# add ldap tag, if ldap is found on the host.

- block:
  - name: "[AUTOENROLLMENT][ZABBIX][DISCOVERY] Add discovery action: Add LDAP Tag [TASK 07]"
    community.zabbix.zabbix_action:
      name: "CUS - {{ customer_short }} - LDAP"
      event_source: "discovery"
      state: 'present'
      status: 'enabled'
      eval_type: 'and'
      esc_period: 60
      conditions:
        - type: 'discovery_rule'
          operator: 'equals'
          value: '{{ customer_short }} Discoveryrule [AutoEnrollment]'
        - type: 'discovery_check'
          operator: 'equals'
          value: '{{ customer_short }} Discoveryrule [AutoEnrollment]: LDAP (636)'
        - type: 'discovery_status'
          operator: 'equals'
          value: 'discovered'
      operations:
        - type: 'add_host_tags'
          tags:
            - tag: 'discovered'
              value: 'ldap'
EXPECTED RESULTS

I would expect, that all of my action-creation tasks running through without an error, especially, because the checks are there.

ACTUAL RESULTS

Sadly, only the checks will be created, where no port is added in the name of the checks.
For all other ports or checks I'll get:

 "msg": "Discovery check type: TCP (2598) does not exist"
TASK [autoenrollment-discovery : [AUTOENROLLMENT][ZABBIX][DISCOVERY] Add discovery action: Add CITRIX Tag [TASK 09]] ***************************************************
task path: /home/um3n/Work/fks-ansible/proxy-setup/roles/autoenrollment-discovery/tasks/disc_add_citrix_tag.yaml:7
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
Loading collection ansible.netcommon from /usr/lib/python3.13/site-packages/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /usr/lib/python3.13/site-packages/ansible_collections/ansible/utils
<monitoring.weichert.intern> attempting to start connection
<monitoring.weichert.intern> using connection plugin ansible.netcommon.httpapi
<monitoring.weichert.intern> found existing local domain socket, using it!
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (action.get)
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (action.get)
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (drule.get)
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (drule.get)
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (drule.get)
<monitoring.weichert.intern> Zabbix httpapi request: POST https://monitoring.weichert.intern:443//api_jsonrpc.php/api_jsonrpc.php (action.get)
<monitoring.weichert.intern> updating play_context for connection
<monitoring.weichert.intern> Loading collection ansible.builtin from
<monitoring.weichert.intern> local domain socket path is /home/um3n/.ansible/pc/2201efb4f8
<monitoring.weichert.intern> ESTABLISH LOCAL CONNECTION FOR USER: um3n
<monitoring.weichert.intern> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa `"&& mkdir "` echo /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206 `" && echo ansible-tmp-1742569561.9832916-95152-269023794593206="` echo /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206 `" ) && sleep 0'
Using module file /home/um3n/.ansible/collections/ansible_collections/community/zabbix/plugins/modules/zabbix_action.bkp
<monitoring.weichert.intern> PUT /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/tmpm491ld3k TO /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206/AnsiballZ_zabbix_action.bkp
<monitoring.weichert.intern> EXEC /bin/sh -c 'chmod u+x /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206/ /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206/AnsiballZ_zabbix_action.bkp && sleep 0'
<monitoring.weichert.intern> EXEC /bin/sh -c '/usr/bin/python /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206/AnsiballZ_zabbix_action.bkp && sleep 0'
<monitoring.weichert.intern> EXEC /bin/sh -c 'rm -f -r /home/um3n/.ansible/tmp/ansible-local-95071c3dmv7wa/ansible-tmp-1742569561.9832916-95152-269023794593206/ > /dev/null 2>&1 && sleep 0'
fatal: [zbxsrvfrontend]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "acknowledge_operations": [],
            "conditions": [
                {
                    "formulaid": null,
                    "operator": "equals",
                    "type": "discovery_rule",
                    "value": "Test Discoveryrule [AutoEnrollment]",
                    "value2": null
                },
                {
                    "formulaid": null,
                    "operator": "equals",
                    "type": "discovery_check",
                    "value": "Test Discoveryrule [AutoEnrollment]: TCP (2598)",
                    "value2": null
                },
                {
                    "formulaid": null,
                    "operator": "equals",
                    "type": "discovery_status",
                    "value": "discovered",
                    "value2": null
                }
            ],
            "esc_period": "60",
            "eval_type": "and",
            "event_source": "discovery",
            "formula": null,
            "http_login_password": null,
            "http_login_user": null,
            "name": "CUS - Test - CITRIX",
            "notify_if_canceled": true,
            "operations": [
                {
                    "command": null,
                    "command_type": null,
                    "esc_period": "0s",
                    "esc_step_from": 1,
                    "esc_step_to": 1,
                    "execute_on": null,
                    "host_groups": null,
                    "inventory": null,
                    "media_type": "all",
                    "op_message": null,
                    "operation_condition": null,
                    "password": null,
                    "port": null,
                    "run_on_groups": null,
                    "run_on_hosts": null,
                    "script_name": null,
                    "send_to_groups": null,
                    "send_to_users": null,
                    "ssh_auth_type": null,
                    "ssh_privatekey_file": null,
                    "ssh_publickey_file": null,
                    "subject": null,
                    "tags": [
                        {
                            "tag": "discovered",
                            "value": "citrix"
                        }
                    ],
                    "templates": null,
                    "type": "add_host_tags",
                    "username": null
                }
            ],
            "pause_in_maintenance": true,
            "pause_symptoms": true,
            "recovery_operations": [],
            "state": "present",
            "status": "enabled"
        }
    },
    "msg": "Discovery check type: TCP (2598) does not exist"
}

PLAY RECAP *************************************************************************************************************************************************************
zbxsrvfrontend             : ok=7    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions