jbfavre / python-protobix Goto Github PK
View Code? Open in Web Editor NEWVery simple python module implementing Zabbix Sender protocol.
License: GNU General Public License v3.0
Very simple python module implementing Zabbix Sender protocol.
License: GNU General Public License v3.0
The examples as given don't seem to work - zbx_container.debug = True causes an error.
A guide on the module would be helpful to us beginners trying to use it.
The module does work well though, but required considerable trial and error and a good amount of perserverance.
In file senderprotocol.py, line 106
@Property
def clock(self):
return int((time.time())/60*60)
Looks like you want divide time by 3600, but for now it multiply by 60 and than multiply by 60. Please correct me if i'm wrong
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?
Upon doing pip install protobix
I get the following error:
(logster)$ pip install functools
Downloading/unpacking functools
Downloading functools-0.5.tar.gz
Running setup.py (path:/home/jeune/.virtualenvs/logster/build/functools/setup.py) egg_info for package functools
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/home/jeune/.virtualenvs/logster/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/home/jeune/.virtualenvs/logster/local/lib/python2.7/site-packages/setuptools/extension.py", line 3, in <module>
import functools
File "functools.py", line 72, in <module>
globals()['c_%s' % x] = globals()[x] = getattr(_functools, x)
AttributeError: 'module' object has no attribute 'compose'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/home/jeune/.virtualenvs/logster/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/home/jeune/.virtualenvs/logster/local/lib/python2.7/site-packages/setuptools/extension.py", line 3, in <module>
import functools
File "functools.py", line 72, in <module>
globals()['c_%s' % x] = globals()[x] = getattr(_functools, x)
AttributeError: 'module' object has no attribute 'compose'
Downloading from github and doing python setup.py install
works. Please update the documentation. Installing via pip seems to be broken.
Get:
from local /etc/zabbix/zabbix_agentd.conf
Correct REGEXP for both 2.2 & 2.4 is:
ZBX_RESP_REGEX = r'processed: (\d+); failed: (\d+); total: (\d+); seconds spent: (\d\.\d+)'
Check wether it's the same with Zabbix 2.0 or not. Could be:
ZBX_RESP_REGEX = r'Processed (\d+) Failed (\d+) Total (\d+) Seconds spent (\d\.\d+)'
Enable logging to ease debug and/or reporting
" If sending many values from an input file, Zabbix sender will batch them at 250 values in one go (all values will be processed)"
https://www.zabbix.com/documentation/2.4/manual/concepts/sender
It looks like reading ServerActive from zabbix_agentd.conf is broken in my environment.
On CentOS 6:
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import protobix
>>> zbx_items = protobix.DataContainer(data_type = 'items')
>>> zbx_items._config
{'dryrun': False, 'data_type': 'items', 'server': '1', 'log_output': '/var/log/zabbix/zabbix_agentd.log', 'timeout': 3, 'log_level': 3, 'port': 10051}
On CentOS 7:
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import protobix
>>> zbx_items = protobix.DataContainer(data_type = 'items')
>>> zbx_items._config
{'dryrun': False, 'data_type': 'items', 'server': '1', 'log_output': '/var/log/zabbix/zabbix_agentd.log', 'timeout': 3, 'log_level': 3, 'port': 10051}
That's what my Zabbix Agent config looks like:
$ fgrep ServerActive /etc/zabbix/zabbix_agentd.conf
ServerActive=192.1.1.1
To me it looks like d88e2cd broke it, but my Python is not really good enough to judge.
I would expect that Datacontainer.items_list would be cleared after a succesfull sending. So the datacontainer can be reused (report from jbfavre/python-zabbix#3)
Add functional / unit tests
Running protobix with it automatically reading the zabbix_agentd.conf
results in traceback:
Traceback (most recent call last):
File "./aamv2.py", line 168, in <module>
ret = AAMv2().run()
File "/usr/local/lib/python2.7/dist-packages/protobix/sampleprobe.py", line 281, in run
self.zbx_config = self._init_config()
File "/usr/local/lib/python2.7/dist-packages/protobix/sampleprobe.py", line 204, in _init_config
zbx_config = ZabbixAgentConfig(self.options.config_file)
File "/usr/local/lib/python2.7/dist-packages/protobix/zabbixagentconfig.py", line 56, in __init__
tmp_config = configobj.ConfigObj(config_file, list_values=False)
File "/usr/lib/python2.7/dist-packages/configobj.py", line 1229, in __init__
self._load(infile, configspec)
File "/usr/lib/python2.7/dist-packages/configobj.py", line 1318, in _load
raise error
configobj.ConfigObjError: Parsing failed with several errors.
First error at line 202.
Line 202 of the /etc/zabbix/zabbix_agentd.conf
is a userparameter:
UserParameter=updates.count.security,/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 2
This is actually the second userparameter in the file. If I uncomment this particular line (the 2nd), the next one complain and so on. Parsing only completes whenever all UserParameters have been commented out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.