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

Add base64 decoder processor #4697

Closed
glinton opened this issue Sep 15, 2018 · 2 comments · Fixed by #6740
Closed

Add base64 decoder processor #4697

glinton opened this issue Sep 15, 2018 · 2 comments · Fixed by #6740
Assignees
Labels
feature request Requests for new plugin and for new features to existing plugins
Milestone

Comments

@glinton
Copy link
Contributor

glinton commented Sep 15, 2018

Feature Request

Add a base64 (or configurable) decoder processor

Proposal:

Add to strings (not likely the correct place) a decoder, to decode a field.

Example config:

[agent]
  interval="1s"
  flush_interval="1s"

[[inputs.exec]]
  timeout = "1s"
  data_format = "json"
  commands = [
    "echo -en '{\"message\":{\"attributes\":{\"deviceId\":\"myPi\",\"deviceNumId\":\"2808946627307959\",\"deviceRegistryId\":\"my-registry\",\"deviceRegistryLocation\":\"us-central1\",\"projectId\":\"conference-demos\",\"subFolder\":\"\"},\"data\":\"dGVzdGluZ0dvb2dsZSxzZW5zb3I9Ym1lXzI4MCB0ZW1wX2M9MjMuOTUsaHVtaWRpdHk9NjIuODMgMTUzNjk1Mjk3NDU1MzUxMDIzMQ==\",\"messageId\":\"204004313210337\",\"message_id\":\"204004313210337\",\"publishTime\":\"2018-09-14T19:22:54.587Z\",\"publish_time\":\"2018-09-14T19:22:54.587Z\"},\"subscription\":\"projects/conference-demos/subscriptions/my-subscription\"}'"
  ]
  tag_keys = ["message_attributes_deviceId"]
  json_string_fields = ["message_data"]

[[processors.strings]]
  [[processors.strings.decode]]
    field = "message_data"
    dest  = "message_data"

[[processors.parser]]
  parse_fields = ["message_data"]
  # change to "json" if the encoded data contains json
  data_format="influx"
  merge="override"

[[outputs.file]]
  files = ["stdout"]

## Sample output
# testingGoogle,host=test,message_attributes_deviceId=myPi,sensor=bme_280 message_data="testingGoogle,sensor=bme_280 temp_c=23.95,humidity=62.83 1536952974553510231",temp_c=23.95,humidity=62.83 1536972180000000000

Desired behavior:

Decode a field so further processing can be done on it.

Use case:

Google IOT sends a data field base64 encoded, it would be nice to be able to pull this data out and store it.

@cliffordvandyk
Copy link

It seems to be common practice (I have other examples than the original Google Core IOT) to send multiple IOT numeric payload fields combined into a single base64-encoded string (presumably for OTA efficiency). It would be useful to have methods to decode a base64 string, and then split the resulting (HEX) into multiple (InfluxDB-friendly) fields.

Specific example: "{"applicationID":"1","applicationName":"AppSensors","devEUI":"393032357a377e05","deviceName":"dev-393032357a377e05","timestamp":1574109564,"fCnt":45,"fPort":2,"data":"VQP0DQwCiv7Qf28M5kkAqg==","data_encode":"base64"}"

Here the "data" key is a base64-encoded string, containg a number of fields.
However, after decoding, the resultant HEX string needs to then be split into a number of fields (on byte boundaries), that must then be converted to InfluxDB-friendly format. I'm not sure that there is a plug-in to accomplish this either.

@cliffordvandyk
Copy link

cliffordvandyk commented Nov 18, 2019

Also (someone else with same requirement):
https://community.influxdata.com/t/telegraf-influxdb-parse-base-64-data-payload/2610

@danielnelson danielnelson added the feature request Requests for new plugin and for new features to existing plugins label Nov 18, 2019
@danielnelson danielnelson added this to the 1.13.0 milestone Nov 18, 2019
@danielnelson danielnelson self-assigned this Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
3 participants