question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Populating InfluxDB with individual tags and fields from JSON message

See original GitHub issue

Been playing with fail2ban over the past couple of days…and from it managed to get a json formatted mqtt message out on each ban.

{ "ip": "37.49.226.155", "failures": "28", "jail": "ssh", "time": "1591645309.58". "country": "<country"> }

So now I want to get these into influx.

Here is my section…I’ve tried all sorts of combinations. I basically want a table, with tags for the jail (ssh) and ip, with values of the number of failures.

; -----------------------------------------
;             Fail2ban
; -----------------------------------------
[fail2ban/ban]
#topic = fail2ban/ban
targets = influxdb:fail2ban
format  = jail={jail},ip={ip} value={failures}

But nothing I do seems to affect the format. The logs just try sending the entire json string as the value:

2020-06-09 07:41:50,985 DEBUG [connectionpool] http://influxdb:8096 "POST /write?db=network&rp=default&precision=ns HTTP/1.1" 400 219
2020-06-09 07:41:50,987 WARNING [influxdb] POST request failed: (400) {"error":"unable to parse 'fail2ban,topic=fail2ban_ban value={ \"ip\": \"37.49.226.155\", \"failures\": \"28\", \"jail\": \"ssh\", \"time\": \"1591645309.58\". \"country\": \"\u003ccountry\"\u003e }': invalid boolean"}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
psyciknzcommented, Jun 17, 2021

I think this can be closed now also, as I’m running main mqttwarn and not a custom one.

1reaction
psyciknzcommented, Jun 8, 2020

So I pulled the latest influxdb code (was able to add it as a quick local service). With this config and the change found by @jacques42:

; -----------------------------------------
;             Fail2ban
; -----------------------------------------
[fail2ban/ban]
topic = fail2ban/ban
targets = log:info, slack:general, influxdb2:fail2ban
format = jail={jail},ip={ip} value={failures}
[fail2ban/unban]
topic = fail2ban/unban
targets = log:info, slack:general, influxdb2:fail2ban
format = jail={jail},ip={ip} value=0

And json of :

 payload: u'{ "ip": "37.49.226.173", "failures": "20", "jail": "ssh", "time": "1591654022.12"}'

I’m now getting entries into a fail2ban table with

time                ip            jail topic        value
----                --            ---- -----        -----
1591654023921039577 37.49.226.173 ssh  fail2ban_ban 20

Which is good enough for me. Unbans go into the same table. with fail2ban_unban. Ideally I’d like it just to say ban an unban, but close enough.

I should merge you latest code into my branch for updates. Since my PR would be well out of date now. (#375)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert results to JSON and send them to a URL | InfluxDB ...
Use json.encode() to convert query results to JSON and http.post() to send them to a URL endpoint.
Read more >
JSON to InfluxDB Line Protocol Using Telegraf and Starlark
This video shows how to convert nested JSON into InfluxDB line protocol, using the Telegraf Starklark processor. You'll be able to take ...
Read more >
Getting MQTT Data into InfluxDB - Full Stack Energy
Forwarding Data to InfluxDB via MQTT and Telegraf. ... I have deployed in various fields, sometimes literally, is having them populate our ...
Read more >
Only last stage data is sent to influx db from jenkins pipeline
durationMillis myDataField1['stage_name'] = jsonObject.stages[i].name //populating the tag type columns of InfluxDB measurements and pushing ...
Read more >
InfluxDB 2 Sink Connector for Confluent Cloud Quick Start
If you plan to use one or more Single Message Transforms (SMTs), ... It can contain a number of InfluxdDB fields, a tag...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found