Skip to content

Commit

Permalink
Merge pull request #376 from jacques42/patch-1
Browse files Browse the repository at this point in the history
Build post data correctly when no additional influx tags included
  • Loading branch information
jpmens committed Oct 7, 2019
2 parents 61afc58 + 9ff63dd commit fe88033
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions services/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ def plugin(srv, item):
url = "http:https://%s:%d/write?db=%s&rp=%s&precision=%s" % (host, port, database, rp, precision)

# influxdb line protocol:
# measurement,tagKey1=tagVal1,tagKey2=tagVal2 field1=value1 field2=value2
# measurement,tagKey1=tagVal1,tagKey2=tagVal2 field1=value1,field2=value2 Timestamp
# sample format in .ini file; no quotes

# if no format has been set, default to "value={payload}""
if item.message == item.payload:
if (item.message == item.payload) or (not (' ' in item.message) and not (',' in item.message)):
# if no format has been set, default to "value={payload}"
# or if format has been set to output simple value, without additional tags or multiple fields
# format = {json_attribute}
data = measurement + ',' + tag + ' value=' + value

elif (',' in item.message) and (not ' ' in item.message):
# if format does not include any additional tags or a timestamp, but includes one or multiple non-default fields
# format = field1=value1,field2=value2
data = measurement + ',' + tag + ' ' + item.message

else:
# sample format in .ini file; no quotes:
# format = host=server1,location=rack1 cpu={payload}
# if format includes additional tags and one or multiple non-default fields and an optional timestamp, either group separated by whitespace from each other
# format = tagKey1=tagVal1,tagKey2=tagVal2 field1=value1,field2=value2
data = measurement + ',' + tag + ',' + item.message

srv.logging.debug(url)
Expand Down

0 comments on commit fe88033

Please sign in to comment.