2016-07-11 22 views
1

Ich versuche, ein Ereignis zu erstellen mit dem "Client-Eingang" hier beschrieben: https://sensuapp.org/docs/latest/reference/clients.html#client-socket-inputSensu: Client-Socket-Eingang (wie-zu einem Ereignisse drucken)

wenn ich das tue, von 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 

Werke (ich kann das Ereignis in Uchiwa sehen), aber wenn ich das tue, aus 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 beklagt:

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

Es scheint, dass nicht der Sohn selbst, verursacht das Problem, aber die Newline. Wie kann ich jede gedruckte Nachricht an > /dev/tcp/localhost/3030 umleiten?

Antwort

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

funktioniert der Trick :)