[BUG] zabbix_host.present reports "updated" every time
@frogunder is already working on this.
Since Feb 3, 2022.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
When configuring a Zabbix host's interface via zabbix_host.present, Salt will report that the item has "changed" in highstate ouput every single time that it is run, despite the fact that the real configuration matches the provided configuration and the fact that no changes have been made.
Setup
Here is the relevant portion from my zabbix.sls:
{% if 'zabbix_hosts' in salt.pillar.items() %}
{% for host, data in pillar['zabbix_hosts'].items() %}
zabbix_host_{{ host }}:
zabbix_host.present:
- host: {{ host }}
- visible_name: {{ host }}
{% for k, v in data.items() %}
- {{ k }}: {{ v }}
{% endfor %}
{% endfor %}
{% endif %}
Here is a portion of the zabbix_hosts dictionary from my Pillar:
zabbix_hosts:
hostname-redacted:
groups:
- 19 # Cisco Switches
- 20 # Network Switches
description: "write something here"
interfaces:
- snmp_interface:
- type: 'snmp'
- dns: 'hostname-redacted'
- ip: '10.10.10.10'
- port: '161'
- useip: true
- main: true
- details:
- version: '3' # SNMPv3
- bulk: '1'
- securityname: 'security-name-redacted'
- securitylevel: 2 # AuthPriv
- authpassphrase: '{$OBS_AUTH_PASS}'
- authprotocol: 1 # SHA1
- privpassphrase: '{$OBS_PRIV_PASS}'
- privprotocol: 1 # AES128
Here is the relevant snippet from my highstate run:
----------
ID: zabbix_host_hostname-redacted
Function: zabbix_host.present
Result: True
Comment: Host hostname-redacted updated.
Started: 13:36:17.168069
Duration: 292.355 ms
Changes:
----------
interfaces:
[{'type': '2', 'main': '1', 'useip': '1', 'ip': '10.10.10.10', 'dns': 'hostname-redacted', 'port': '161', 'details': {'version': '3', 'bulk': '1', 'community': '{$SNMP_COMMUNITY}', 'securitylevel': 2, 'securityname': 'security-name-redacted', 'contextname': '', 'authpassphrase': '{$OBS_AUTH_PASS}', 'authprotocol': 1, 'privpassphrase': '{$OBS_PRIV_PASS}', 'privprotocol': 1}}]
Steps to Reproduce the behavior
- Have Zabbix and Salt installed and configure Salt to be able to use the
zabbix_hostmodule. - Configure a host (I have only hosts with SNMPv3 interfaces, not sure if this issue exists on other interface types)
- Run highstate twice
Expected behavior
Salt prints something along the lines of "Host hostname-redacted already exists." or at least does not report that a change has occurred.
Versions Report
salt --versions-report
Master:Salt Version:
Salt: 3004
Dependency Versions:
cffi: 1.14.3
cherrypy: unknown
dateutil: 2.6.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.14
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Sep 21 2021, 10:09:35)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 19.0.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: oracle 8.4
locale: UTF-8
machine: x86_64
release: 5.4.17-2102.202.5.el8uek.x86_64
system: Linux
version: Oracle Linux Server 8.4
Minion:
Salt Version:
Salt: 3004
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.7.3
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.10 (default, Nov 26 2021, 20:14:08)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-96-generic
system: Linux
version: Ubuntu 20.04 focal
Additional context
speculation about cause
I am not a Python developer but I poked around a little bit and here is what I found:
When Salt compares the existing parameters from the Zabbix API with the parameters that it thinks should exist, it is erroneously adding a parameter that is not defined. In the (above) provided highstate ouptut, you can see that Salt is trying to set a value for community, while this is not provided in my Pillar data. When I manually query the Zabbix API, this is the result that I see for the host's interface:
{
"interfaceid": "15",
"hostid": "10462",
"main": "1",
"type": "2",
"useip": "1",
"ip": "10.10.10.10",
"dns": "hostname-redacted",
"port": "161",
"available": "2",
"error": "",
"errors_from": "0",
"disable_until": "0",
"details": {
"version": "3",
"bulk": "1",
"securityname": "security-name-redacted",
"securitylevel": "2",
"authpassphrase": "{$OBS_AUTH_PASS}",
"privpassphrase": "{$OBS_PRIV_PASS}",
"authprotocol": "1",
"privprotocol": "1",
"contextname": ""
}
In this result, no community is present. I believe that Salt compares this result to what it thinks should be there and erroneously tries to set the community string, which Zabbix silently drops because this is SNMPv3 and not SNMPv2.
I found that the community parameter was being injected in zabbix_host.py when none is set for an SNMP-type interface, regardless of the version of SNMP. I commented out the line that adds the community to the details (line 157) and I am no longer seeing the erroneous "community" show up in my highstate output.
However, I do still see it reported as "changed" even though all of the parameters now match.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.