Kapacitor log as pretty json?


#1

I’m working with series with lots of fields and tags , when alerts are triggered into a log file. we can see this.

{"id":"Alert::deadman_snmpcollector_device_fase3","message":"Alert::deadman_snmpcollector_device_fase3 is CRITICAL stats value: map[emitted:0] map[device:xxxxxx305 instance:san] deadman_snmpcollector_device_fase3 deadman_snmpcollector_device_fase3 device=xxxxxx305,instance=san 2017-08-11 11:55:00 +0000 UTC ","details":"{\u0026#34;Name\u0026#34;:\u0026#34;stats\u0026#34;,\u0026#34;TaskName\u0026#34;:\u0026#34;deadman_snmpcollector_device_fase3\u0026#34;,\u0026#34;Group\u0026#34;:\u0026#34;device=xxxxxx305,instance=san\u0026#34;,\u0026#34;Tags\u0026#34;:{\u0026#34;device\u0026#34;:\u0026#34;xxxxxx305\u0026#34;,\u0026#34;instance\u0026#34;:\u0026#34;san\u0026#34;},\u0026#34;ServerInfo\u0026#34;:{\u0026#34;Hostname\u0026#34;:\u0026#34;server01\u0026#34;,\u0026#34;ClusterID\u0026#34;:\u0026#34;ba75442c-a531-41b1-8174-6fad1e2c9148\u0026#34;,\u0026#34;ServerID\u0026#34;:\u0026#34;9ec3ab9f-fa61-4450-89da-4e24631cec29\u0026#34;},\u0026#34;ID\u0026#34;:\u0026#34;Alert::deadman_snmpcollector_device_fase3\u0026#34;,\u0026#34;Fields\u0026#34;:{\u0026#34;emitted\u0026#34;:0},\u0026#34;Level\u0026#34;:\u0026#34;CRITICAL\u0026#34;,\u0026#34;Time\u0026#34;:\u0026#34;2017-08-11T11:55:00Z\u0026#34;,\u0026#34;Message\u0026#34;:\u0026#34;Alert::deadman_snmpcollector_device_fase3 is CRITICAL stats value: map[emitted:0] map[device:xxxxxx305 instance:san] deadman_snmpcollector_device_fase3 deadman_snmpcollector_device_fase3 device=xxxxxx305,instance=san 2017-08-11 11:55:00 \u0026#43;0000 UTC \u0026#34;}\n","time":"2017-08-11T11:55:00Z","duration":0,"level":"CRITICAL","data":{"series":[{"name":"stats","tags":{"device":"xxxxxx305","instance":"san"},"columns":["time","emitted"],"values":[["2017-08-11T11:55:00Z",0]]}]}}

could be possible to see something more human readable, like the following …

======["2017-08-11T11:55:00Z"]===================================================
{
    "data": {
        "series": [
            {
                "columns": [
                    "time",
                    "emitted"
                ],
                "name": "stats",
                "tags": {
                    "device": "xxxxxx305",
                    "instance": "san"
                },
                "values": [
                    [
                        "2017-08-11T11:55:00Z",
                        0
                    ]
                ]
            }
        ]
    },
    "details": "{"Name":"stats","TaskName":"deadman_snmpcollector_device_fase3","Group":"device=xxxxxx305,instance=san","Tags":{"device":"xxxxxx305","instance":"san"},"ServerInfo":{"Hostname":"server01","ClusterID":"ba75442c-a531-41b1-8174-6fad1e2c9148","ServerID":"9ec3ab9f-fa61-4450-89da-4e24631cec29"},"ID":"Alert::deadman_snmpcollector_device_fase3","Fields":{"emitted":0},"Level":"CRITICAL","Time":"2017-08-11T11:55:00Z","Message":"Alert::deadman_snmpcollector_device_fase3 is CRITICAL stats value: map[emitted:0] map[device:xxxxxx305 instance:san] deadman_snmpcollector_device_fase3 deadman_snmpcollector_device_fase3 device=xxxxxx305,instance=san 2017-08-11 11:55:00 +0000 UTC "}\n",
    "duration": 0,
    "id": "Alert::deadman_snmpcollector_device_fase3",
    "level": "CRITICAL",
    "message": "Alert::deadman_snmpcollector_device_fase3 is CRITICAL stats value: map[emitted:0] map[device:xxxxxx305 instance:san] deadman_snmpcollector_device_fase3 deadman_snmpcollector_device_fase3 device=xxxxxx305,instance=san 2017-08-11 11:55:00 +0000 UTC ",
    "time": "2017-08-11T11:55:00Z"
}

#2

Is it possible to use the telegraf JSON Log Parser to do this?


#3

I have the same challenge, did you find anything?
I was looking to see if row-template-file in kapacitor.conf may help…


#4

I’d suggest installing https://github.com/sharkdp/bat and piping content through it


#5

Thank you!
I was also thinking to send the output to an API which will parse the json string and send it to wherever we want.


#6