简体   繁体   中英

Sensu: client socket input (how-to print an event)

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 ?

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect( ("localhost",3030) )
sock.sendall(json.dumps(msg))
sock.close()

does the trick :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM