0

我已经编写了一个示例 python 脚本来在 EFK 堆栈的 Kibana Dashboard 发送消息。我正在从 python 脚本向 Fluentd Endpoint 发送消息。

脚本如下:

import requests
import json
from datetime import datetime

username = "abc"
password = "xyz"

url = "https://fluentd-aaaaa-bbbb.com"

r = requests.post(url, auth=(username, password), json={"msg":"random testing"})

print(r.status_code)

在 EFK 堆栈的 Kibana Dashboard,我得到了以下信息。

Sep 1, 2021 @ 21:32:48.258  msg:random testing @timestamp:Sep 1, 2021 @ 21:32:48.258 _id:4rVKrHsBWfzSb5RDi6m7 _type:_doc 
                            
                            _index:logs-json-2021.09.01 _score: -

有什么方法可以将 python 脚本中的 '@timestamp' 和 '_id' 发送到 Fluentd Endpoit ?

如果我们使用 elasticsearch API 从 Python 脚本在 Elasticsearch Endpoint 发送,我们可以在 Python 脚本中设置“@timestamp”和“_id”。我正在尝试找出 Fluentd Endpoint 是否有任何方法。

我已经尝试过这样的事情,但它不起作用。

date_time = datetime.now().__str__()
r = requests.post(url, auth=(username, password), json={"msg":"random testing", "@timestamp":date_time})
4

0 回答 0