jbfavre / python-protobix

Very simple python module implementing Zabbix Sender protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'dict' object has no attribute 'data_type'

syphernl opened this issue · comments

commented

I'm struggling with getting this to work properly.

Traceback (most recent call last):
  File "/etc/salt/eventsd_workers/Zabbix_Return_Worker.py", line 170, in _store
    self.zbx_datacontainer.add(data)
  File "/usr/local/lib/python2.7/dist-packages/protobix/datacontainer.py", line 69, in add
    self.add_item(host, key, data[host][key])
  File "/usr/local/lib/python2.7/dist-packages/protobix/datacontainer.py", line 48, in add_item
    if self._config.data_type == "items":
AttributeError: 'dict' object has no attribute 'data_type'

The datacontainer is setup like this:

            config = {
                # Protobix specific options
                'data_type': None,
                'dryrun': False,

                # Zabbix Agent options
                'ServerActive': self.creds['server'],
                'ServerPort': 10051,
                'LogType': 'file',
                'LogFile': '/dev/null',
                'DebugLevel': 3,
                'Timeout': 3,
                'Hostname': getfqdn(),
                'TLSConnect': 'unencrypted',
                'TLSCAFile': None,
                'TLSCertFile': None,
                'TLSCRLFile': None,
                'TLSKeyFile': None,
                'TLSServerCertIssuer': None,
                'TLSServerCertSubject': None,
                'TLSPSKIdentity': None,
                'TLSPSKFile': None,
            }

        config['data_type'] = 'items'

        log.debug('[Zabbix] Creating data container with config {0}'.format(config))

        self.zbx_datacontainer = protobix.DataContainer(config=config)

Later on we try to send data:

            data = {
                minion: {
                    self.creds['failed_key']: failed_counter,
                    self.creds['changed_key']: changed_counter
                }
            }
            log.debug('[Zabbix] Dataset to send: {0}'.format(data))

            self.zbx_datacontainer.add(data)

            response = self.zbx_datacontainer.send()

Previously I was using add_item but this was affected by the same.

I also tried to set it like self.zbx_datacontainer.data_type = 'items' and self.zbx_datacontainer.data_type('items') but had no luck with those either.

Am I doing something wrong? This is (more or less) also in the tests so ISTM this should work?

Hello,
Thanks for the report.
As far as I can see, you're passing a dict as argument to datacontainer.
But config argument must be an instance of ZabbixAgentConfig.

You can have a look on protobix.SampleProbe to see how it works.
You could also use SampleProbe in Zabbix_Return_Worker.py to avoid managing all the details