如何通过 python 从 filebeat 索引中获取选定的日志
How to get selected log from filebeat index by python
我正在使用 python elasticsearch 模块通过 using 关键字搜索 filebeat 日志。与我在 "Kibana Discover" 中所做的相同,但我的搜索没有 return 任何内容。
# make sure ES is up and running
import requests
res = requests.get('http://xxxxx:9200')
print(res.content)
# Import Elasticsearch package
from elasticsearch import Elasticsearch
# Connect to the elastic cluster
es=Elasticsearch([{'host':'xxxxx','port':9200}],timeout=30)
es
es.search(index='*', body={
'query': {
'match': {
'message': 'SocketTimeoutException',
}
}
})
es
它应该给我这样的日志文件,但它没有。
消息:14:20:01,387 错误 [com.yuma.jca.sockets.concox](默认线程 - 37)IMEI 的 MessageWork SocketTimeoutException:0358735075610732-> 读取超时@timestamp:2019 年 8 月 8 日@[=43= .559 ecs.version:1.0.0
但我是这样的,只有打印连接
b'{\n "name" : "kibana",\n "cluster_name" : "elasticsearch",\n "cluster_uuid" : "pspfiiegRre8OOFSsLWIhQ", \n "version" : {\n "number" : "7.2.0",\n "build_flavor" : "default",\n "build_type" : "deb" ,\n "build_hash" : "508c38a",\n "build_date" : "2019-06-20T15:54:18.811730Z",\n "build_snapshot" : 假,\n "lucene_version" : "8.0.0",\n "minimum_wire_compatibility_version" : "6.8.0",\n "minimum_index_compatibility_version" : "6.0.0-beta1"\n },\n "tagline" : "You Know, for Search"\n}\n'
将elasticsearch查询结果赋值到一个变量中,并打印响应数据。
data = es.search(index='*', body={
'query': {
'match': {
'message': 'SocketTimeoutException',
}
}
})
print(data)
我正在使用 python elasticsearch 模块通过 using 关键字搜索 filebeat 日志。与我在 "Kibana Discover" 中所做的相同,但我的搜索没有 return 任何内容。
# make sure ES is up and running
import requests
res = requests.get('http://xxxxx:9200')
print(res.content)
# Import Elasticsearch package
from elasticsearch import Elasticsearch
# Connect to the elastic cluster
es=Elasticsearch([{'host':'xxxxx','port':9200}],timeout=30)
es
es.search(index='*', body={
'query': {
'match': {
'message': 'SocketTimeoutException',
}
}
})
es
它应该给我这样的日志文件,但它没有。
消息:14:20:01,387 错误 [com.yuma.jca.sockets.concox](默认线程 - 37)IMEI 的 MessageWork SocketTimeoutException:0358735075610732-> 读取超时@timestamp:2019 年 8 月 8 日@[=43= .559 ecs.version:1.0.0
但我是这样的,只有打印连接
b'{\n "name" : "kibana",\n "cluster_name" : "elasticsearch",\n "cluster_uuid" : "pspfiiegRre8OOFSsLWIhQ", \n "version" : {\n "number" : "7.2.0",\n "build_flavor" : "default",\n "build_type" : "deb" ,\n "build_hash" : "508c38a",\n "build_date" : "2019-06-20T15:54:18.811730Z",\n "build_snapshot" : 假,\n "lucene_version" : "8.0.0",\n "minimum_wire_compatibility_version" : "6.8.0",\n "minimum_index_compatibility_version" : "6.0.0-beta1"\n },\n "tagline" : "You Know, for Search"\n}\n'
将elasticsearch查询结果赋值到一个变量中,并打印响应数据。
data = es.search(index='*', body={
'query': {
'match': {
'message': 'SocketTimeoutException',
}
}
})
print(data)