由于项目需要,调研使用graylog收集项目操作日志, 并使用api查询日志
python代码
if __name__ == '__main__':
import requests
search_content = {
"query_string": {
"type": "elasticsearch",
"query_string": "id"
},
"timerange": {
"type": "relative",
"range": 3000000
},
"fields_in_order": ["message"]
}
headers = {
"Accept": "text/csv",
"Accept-Encoding": "gzip, deflate, br",
"X-Requested-By": "Graylog API Browser"
}
response = requests.post("http://127.0.0.1:9001/api/views/search/messages", json=search_content,
auth=("admin", "admin"),
headers=headers)
messages = []
for line in response.text.split("\n"):
if line:
print(line)
print(messages)
标签:__,search,rest,graylog,api,line,日志
From: https://www.cnblogs.com/luslin/p/17493930.html