I am trying to create an event using the "Client socket input" described here: https://sensuapp.org/docs/latest/reference/clients.html#client-socket-input
when i do, from bash:
echo '{"status": 1, "output": "x.x.x.x/22 [AS0000] | NotFound. No VRP Covers the Route Prefix.", "name": "err_rpki_rr.py"}' > /dev/tcp/localhost/3030
works (i can see the event in Uchiwa), but when i do, from python code:
print json.dumps(msg)
$ python err_rpki_rr.py > /dev/tcp/localhost/3030
{"status": 1, "output": "x.x.x.x/22 [AS0000] | NotFound. No VRP Covers the Route Prefix.", "name": "err_rpki_rr.py"}
{"status": 1, "output": "y.y.y.y/22 [AS0000] | NotFound. No VRP Covers the Route Prefix.", "name": "err_rpki_rr.py"}
Sensu complains about:
==> sensu-client.log <==
{"timestamp":"2016-07-11T22:02:21.698967+0200","level":"warn","message":"discarding data buffer for sender and closing connection","data":"{\"status\": 1, \"output\": \"x.x.x.x/22 [AS0000] | NotFound. No VRP Covers the Route Prefix.\", \"name\": \"err_rpki_rr.py\"}\n{\"status\": 1, \"output\": \"y.y.y.y/22 [AS0000] | NotFound. No VRP Covers the Route Prefix.\", \"name\": \"err_rpki_rr.py\"}\n","parse_error":"unexpected characters after the JSON document at line 2, column 1 [parse.c:590]"}
It seems that is not the son itself, causing the issue, but the newline.
How can I re-direct every printed message to > /dev/tcp/localhost/3030
?
答案 0 :(得分:2)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect( ("localhost",3030) )
sock.sendall(json.dumps(msg))
sock.close()
does the trick :)