zbxsend icon indicating copy to clipboard operation
zbxsend copied to clipboard

zbxsend.py sends a non-integer timestamp

Open asaveljevs opened this issue 9 years ago • 2 comments

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.

asaveljevs avatar Jan 07 '16 07:01 asaveljevs

One solution would be to truncate clock to an integer, another would be to additionally make use of ns element.

asaveljevs avatar Jan 07 '16 07:01 asaveljevs

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'
[...]

martinonicolas avatar Jun 20 '17 19:06 martinonicolas