gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 03:50:37 24 4
gpt4 key购买 nike

我正在尝试使用此处描述的“客户端套接字输入”创建一个事件: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 提示:

==> 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()

成功了:)

关于python - Sensu:客户端套接字输入(如何打印事件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38315287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com