ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
320 stars 277 forks source link

Zabbix_Host Module Failed #1355

Closed pyrodie18 closed 1 month ago

pyrodie18 commented 1 month ago
SUMMARY

Not sure what happened but at some point in the last two weeks the host module started breaking. The last plugin-integration test to run (https://github.com/ansible-collections/community.zabbix/actions/runs/9933607178/job/28017631838) ran 100% all the way through (NOTE: The failure there now is one that I triggered today to see if it still passed like it had previously). @masa-orca discovered this failure with #1353.

Failure read-out:

2024-07-28T16:06:46.5176821Z TASK [test_zabbix_host : test: change visible_name] ****************************
2024-07-28T16:06:48.0601942Z fatal: [testhost]: FAILED! => {"changed": false, "msg": "connection error occurred: REST API returned {'code': -32602, 'message': 'Invalid params.', 'data': 'Incorrect arguments passed to function.'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"host.update\", \"id\": \"175fde32-1edc-4c1e-a207-671f3740d514\", \"params\": {\"hostid\": \"10642\", \"groups\": [{\"groupid\": \"2\"}, {\"groupid\": \"4\"}], \"status\": 0, \"proxyid\": 2, \"monitored_by\": 1, \"name\": \"ExampleName Changed\", \"interfaces\": [{\"main\": 1, \"useip\": 1, \"ip\": \"10.1.1.1\", \"dns\": \"\", \"port\": \"10050\", \"interfaceid\": \"33\", \"hostid\": \"10642\", \"type\": 1, \"available\": \"0\", \"error\": \"\", \"errors_from\": \"0\", \"disable_until\": \"0\", \"details\": {\"version\": 2, \"bulk\": 1, \"community\": \"\", \"securityname\": \"\", \"contextname\": \"\", \"securitylevel\": 0, \"authprotocol\": 0, \"authpassphrase\": \"\", \"privprotocol\": 0, \"privpassphrase\": \"\"}}, {\"main\": 0, \"useip\": 1, \"ip\": \"10.1.1.1\", \"dns\": \"\", \"port\": \"{$MACRO}\", \"interfaceid\": \"34\", \"hostid\": \"10642\", \"type\": 1, \"available\": \"0\", \"error\": \"\", \"errors_from\": \"0\", \"disable_until\": \"0\", \"details\": {\"version\": 2, \"bulk\": 1, \"community\": \"\", \"securityname\": \"\", \"contextname\": \"\", \"securitylevel\": 0, \"authprotocol\": 0, \"authpassphrase\": \"\", \"privprotocol\": 0, \"privpassphrase\": \"\"}}, {\"main\": 1, \"useip\": 1, \"ip\": \"10.1.1.1\", \"dns\": \"\", \"port\": \"12345\", \"interfaceid\": \"35\", \"hostid\": \"10642\", \"type\": 4, \"available\": \"0\", \"error\": \"\", \"errors_from\": \"0\", \"disable_until\": \"0\", \"details\": {\"version\": 2, \"bulk\": 1, \"community\": \"\", \"securityname\": \"\", \"contextname\": \"\", \"securitylevel\": 0, \"authprotocol\": 0, \"authpassphrase\": \"\", \"privprotocol\": 0, \"privpassphrase\": \"\"}}]}, \"auth\": \"7e5d648a0d540540091207ce5da5a1fa\"}"}

It looks like Zabbix dropped 7.0.1 in the last week or two but the change doesn't doesn't mention the host API at all so not sure what changed.

ISSUE TYPE
COMPONENT NAME

zabbix_host module on Zabbix 7.0

Vanav commented 1 month ago

I confirm this issue. It appeared with Zabbix Frontend 7.0.1. Ansible code:

- zabbix_host:
    host_name: '{{ zabbix_agent_hostname }}'
    tls_accept: 2     # PSK
    tls_connect: 2    # PSK
    tls_psk: '{{ zabbix_agent2_tlspsk_secret }}'
    tls_psk_identity: '{{ zabbix_agent_hostname }}'

Error (reformatted):

fatal: [host -> zabbix.example.com]: FAILED! => 
    changed: false
    msg: 'connection error occurred: REST API returned {''code'': -32602, ''message'':
        ''Invalid params.'', ''data'': ''Incorrect arguments passed to function.''} when
        sending:
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "id": "1a48c4c6-f48a-49de-8aad-10887697bc5e",
    "params": {
        "hostid": "10188",
        "groups": [
            {
                "groupid": "28"
            }
        ],
        "status": 0,
        "monitored_by": 0,
        "tls_connect": 2,
        "tls_accept": 2,
        "tls_psk_identity": "xxx",
        "tls_psk": "********",
        "interfaces": [
            {
                "main": 1,
                "useip": 1,
                "ip": "xx.xx.xx.xx",
                "dns": "",
                "port": "10050",
                "interfaceid": "30204",
                "hostid": "10188",
                "type": 1,
                "available": "1",
                "error": "",
                "errors_from": "0",
                "disable_until": "0",
                "details": {
                    "version": 2,
                    "bulk": 1,
                    "community": "",
                    "securityname": "",
                    "contextname": "",
                    "securitylevel": 0,
                    "authprotocol": 0,
                    "authpassphrase": "",
                    "privprotocol": 0,
                    "privpassphrase": ""
                }
            }
        ]
    },
    "auth": "xxx"
}

Seems the cause is the fix: "The "error" field must be read-only, but it is possible to set a value for this field when creating a network discovery rule" that added this check: https://git.zabbix.com/projects/ZBX/repos/zabbix/commits/3d5a48d327ec01a4c8e58460873297f9b56f576e#ui/include/classes/api/services/CHostInterface.php:

$allowed_fields = array_flip([
    'hostid', 'type', 'ip', 'dns', 'port', 'useip', 'main', 'details', 'interface_ref', 'items', 'interfaceid'
]);
...
if (!check_db_fields($interfaceDBfields, $interface) || array_diff_key($interface, $allowed_fields)) {
    self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect arguments passed to function.'));
}

We have a bug and for an unknown reason we are passing in API call extra read-only fields: "available": "1", "error": "", "errors_from": "0", "disable_until": "0", "details":{...} Need to remove this useless fields from an API call to host.update.

Workaround: for any zabbix_host specify block interfaces:

- zabbix_host:
    host_name: '{{ zabbix_agent_hostname }}'
    tls_accept: 2     # PSK
    tls_connect: 2    # PSK
    tls_psk: '{{ zabbix_agent2_tlspsk_secret }}'
    tls_psk_identity: '{{ zabbix_agent_hostname }}'
    interfaces:
    - type: agent
      main: 1
      useip: 1
      ip: '{{ ansible_host }}'
      port: '{{ zabbix_agent_port }}'

In this case no extra parameters will be passed.

the-iot commented 1 month ago

yesterday zabbix 7.0.2 was released.

the bug ist closed with this version on zabbix site

Vanav commented 1 month ago

I've tested versions 7.0.1 and 7.0.2, both have this issue, additional validation added in 7.0.1.

pyrodie18 commented 1 month ago

I spent some time looking around yesterday and don't see where those values are even being added into the API call. Unfortunately @BGmot is a lot better with the module stuff then me.

masa-orca commented 1 month ago

I understood how to resolve, so I wrote commit to fix. @BGmot If I offend you, I apologize for creating PR although you were assigned.

pyrodie18 commented 1 month ago

I assigned it to him since he's the one that normally does it....Don't think he's even seen it yet so I'm sure no offense taken.

the-iot commented 1 month ago

I've tested versions 7.0.1 and 7.0.2, both have this issue, additional validation added in 7.0.1.

ah ok. thanks for the workaround with the interface ...this works for me