在restapi中哪里可以找到ELK版本?

2024-05-17 05:05:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过restapi或解析html获得ELK版本。你知道吗

我在API文档中搜索,什么也没找到

重新编辑: 在python中。。。没有比这更好的了

re.findall(r"version":"(\d\.\d\.\d)&quot", requests.get(my_elk).content.decode())[0]

Tags: 文档版本reapirestapielk编辑get
3条回答

没有HTML,但是如果在Kibana的控制台中调用GET /curl -XGET http://localhost:9200/,则返回结果将是:

{
  "name" : "instance-0000000039",
  "cluster_name" : "c2edd39f6fa24b0d8e5c34e8d1d19849",
  "cluster_uuid" : "VBkvp8OmTCaVuVvMioS3SA",
  "version" : {
    "number" : "6.6.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "a9861f4",
    "build_date" : "2019-01-24T11:27:09.439740Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

所以您只需要从JSON响应中获取version.number。你知道吗

如果您已经在使用requests库,为什么不使用json方法来解析结果呢?你知道吗

requests.get(my_elk).json()["version"]["number"]

Elasticsearch提供JSON,而不是HTML。所以,你可以用jq

$ curl -s localhost:9200 | jq '.version.number'
6.6.0

在Python中,请不要使用re模块。。。使用json模块并实际解析该内容

相关问题 更多 >