zbxsend
zbxsend copied to clipboard
zbxsend.py sends a non-integer timestamp
There is a bug in how the clock
element of JSON is formed:
for m in metrics:
clock = m.clock or time.time()
metrics_data.append(('\t\t{\n'
'\t\t\t"host":%s,\n'
'\t\t\t"key":%s,\n'
'\t\t\t"value":%s,\n'
'\t\t\t"clock":%s}') % (j(m.host), j(m.key), j(m.value), clock))
If a timestamp is not provided with the metric, it uses time.time()
, which returns a floating-point value and that floating-point value is then inserted into the JSON. However, according to the protocol, Zabbix expects to have an integer Unix timestamp there.
Please see https://support.zabbix.com/browse/ZBX-10234 for more information.
One solution would be to truncate clock
to an integer, another would be to additionally make use of ns
element.
To solve this, I add clock = int(clock)
in line 30
[...]
for m in metrics:
clock = m.clock or time.time()
clock = int(clock)
metrics_data.append(('\t\t{\n'
[...]