Sensu:客户端套接字输入(如何打印事件)

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

我正在尝试使用此处描述的 "Client socket input" 创建一个事件:https://sensuapp.org/docs/latest/reference/clients.html#client-socket-input

当我这样做时,来自 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

有效(我可以在 Uchiwa 中看到该事件),但是当我这样做时,来自 python 代码:

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-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]"}

看来问题不是儿子本身引起的,而是换行符。 如何将每条打印的消息重定向到 > /dev/tcp/localhost/3030

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

有用:)