From 2c0cf1a0a19a0fdc37b7d8e3c2fa1bef95a37158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Zettergren?= Date: Tue, 27 Aug 2019 15:05:59 +0200 Subject: [PATCH] fix elasticsearch sending booleans to opentsdb Added a generic bool-to-int convert in printmetric-function, so that any booleans sent for printing will be converted to an integer. Fixes an an issue where the metric `is_master` tried to send boolean values. If this is too generic, one could fix the specific `is_master` value in `_collect_server`-function, line [185](https://github.com/OpenTSDB/tcollector/blob/master/collectors/0/elasticsearch.py#L185) or [187](https://github.com/OpenTSDB/tcollector/blob/master/collectors/0/elasticsearch.py#L187) by explicitly changing only that to `int()`, but figured the generic approach is future-proof for any other metrics that might slip through as booleans. --- collectors/0/elasticsearch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/collectors/0/elasticsearch.py b/collectors/0/elasticsearch.py index 70a758bb..6e52cdf5 100755 --- a/collectors/0/elasticsearch.py +++ b/collectors/0/elasticsearch.py @@ -106,6 +106,9 @@ def printmetric(metric, ts, value, tags): for name, value in tags.items()) else: tags = "" + # Convert any bool values to int, as opentsdb only accepts int or float. + if isinstance(value, bool): + value = int(value) print("%s %d %s %s" % (metric, ts, value, tags))