saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.17k stars 5.48k forks source link

[BUG] zabbix_host.present KeyError: 'bulk" if you add again a host #60796

Closed colttt closed 3 years ago

colttt commented 3 years ago

Description When I run a high state and my states add a new host it works fine, if I run it again, I get an error.

first time

----------
          ID: create_host_to_zabbix
    Function: zabbix_host.present
      Result: True
     Comment: Host salt-minion-1 created.
     Started: 11:13:32.614666
    Duration: 602.548 ms
     Changes:   
              ----------                                                                                                                                                                                                                                                                                                     
              salt-minion-1:
                  ----------
                  new:
                      Host salt-minion-1 created.
                  old:
                      Host salt-minion-1 does not exist.
----------
          ID: assign_templates_to_host
    Function: zabbix_host.assign_templates
      Result: True
     Comment: Templates updated.
     Started: 11:13:33.217568
    Duration: 1316.034 ms
     Changes:   
              ----------                                                                                                                                                                                                                                                                                                     
              salt-minion-1:
                  ----------
                  new:
                      Host templates: 10001
                  old:
                      Host templates: 
----------

second time

----------
          ID: create_host_to_zabbix
    Function: zabbix_host.present
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 2154, in call                                                                                                                                                                                                                                      
                  *cdata["args"], **cdata["kwargs"]                                                                                                                                                                                                                                                                          
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2106, in wrapper                                                                                                                                                                                                                                  
                  return f(*args, **kwargs)                                                                                                                                                                                                                                                                                  
                File "/usr/lib/python3/dist-packages/salt/states/zabbix_host.py", line 260, in present                                                                                                                                                                                                                       
                  hostintf.pop("bulk")                                                                                                                                                                                                                                                                                       
              KeyError: 'bulk'                                                                                                                                                                                                                                                                                               
     Started: 11:14:36.371455
    Duration: 932.251 ms
     Changes:   
----------

Setup we use zabbix 5.4.1

create_host_to_zabbix:
  zabbix_host.present:
    - host: {{ grains['host'] }}
    - groups:
      - 2
    - interfaces:
      - {{ grains['fqdn'] }}:
        - ip: {{ grains['ipv4'][1] }}
        - type: agent
        - port: 10050
        - main: true
        - useip: true
    - require:
      - pkg: zabbix-agent
    - _connection_user: ***
    - _connection_password: ****
    - _connection_url: https://monitoring.example.de/api_jsonrpc.php

assign_templates_to_host:
  zabbix_host.assign_templates:
    - host: {{ grains['host'] }}
    - templates:
      - "Template OS Linux"
    - _connection_user: ***
    - _connection_password: ****
    - _connection_url: https://monitoring.example.de/api_jsonrpc.php

Expected behavior Just to add a host in zabbix

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ``` salt-master: salt --versions-report Salt Version: Salt: 3003.1 Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 2.7.3 docker-py: Not Installed gitdb: 2.0.5 gitpython: 2.1.11 Jinja2: 2.10 libgit2: 0.27.7 M2Crypto: Not Installed Mako: Not Installed msgpack: 0.5.6 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.19 pycrypto: Not Installed pycryptodome: 3.6.1 pygit2: 0.27.4 Python: 3.7.3 (default, Jan 22 2021, 20:04:44) python-gnupg: Not Installed PyYAML: 3.13 PyZMQ: 17.1.2 smmap: 2.0.5 timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.1 System Versions: dist: debian 10 buster locale: UTF-8 machine: x86_64 release: 4.19.0-17-amd64 system: Linux version: Debian GNU/Linux 10 buster ``` ``` salt-minion --versions-report Salt Version: Salt: 3003.2 Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 2.5.3 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 2.9.4 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.5.3 (default, Apr 5 2021, 09:00:41) python-gnupg: Not Installed PyYAML: 3.12 PyZMQ: 17.1.2 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.2.1 System Versions: dist: debian 9 stretch locale: UTF-8 machine: x86_64 release: 4.9.0-15-amd64 system: Linux version: Debian GNU/Linux 9 stretch ```

Additional context Add any other context about the problem here.

piterpunk commented 3 years ago

Hi @colttt ,

Reading your error message, or you are running the state in an salt 3002.x or, by some reason, you're using an old zabbix_host.py:

                File "/usr/lib/python3/dist-packages/salt/states/zabbix_host.py", line 260, in present
                  hostintf.pop("bulk")
              KeyError: 'bulk'

The line 260 doesn't have that the hostinf.pop("bulk") since 5928d9ce67e2bf01734b69e9940e23e725591ee7 which is part of Salt 3003.x. You can check it yourself here.

colttt commented 3 years ago

fixed in salt 3003.x