Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
syphernl opened this issue Apr 28, 2017 · 1 comment
Closed

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

syphernl opened this issue Apr 28, 2017 · 1 comment

Comments

@syphernl
Copy link

syphernl commented Apr 28, 2017

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?

@jbfavre
Copy link
Owner

jbfavre commented May 3, 2017

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

@jbfavre jbfavre closed this as completed May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants