Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build post data correctly when no additional influx tags included #376

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
build post data correctly when no additional influx tags included
It currently seems assumes that in line 55 by appending `item.message`  after a comma, any message includes at least one more influx tag to start with. This may not always be the case. Enhancing the logic to build the data payload for Influx post in a way that format strings can work without having to add additional tags.
  • Loading branch information
jacques42 committed Oct 5, 2019
commit 9ff63dd05f49caaf3403aabdfaf79c8d7b7862d9
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