0

这可能不是问这个问题的正确地方。但我找不到这样做的文章。我在 CentOS 上安装了以下软件包。

Elasticsearch(我不需要它,因为我正在尝试使用 API 与 ELK 堆栈集群交谈。我不希望 ealsticsearch 在我有 elastalert 的盒子上本地运行。)
ISO8601 或 Unix 时间戳数据
Python 2.6 或 2.7
pip,见 requirements.txt

但是,如何使用 API 调用弹性搜索集群。我有 API 和服务帐户可以这样做。这就是我要找的东西。我应该修改 elastalert-master/example_rules 下的哪个文件?

我也尝试过更改 config.yaml.example ,但这会不断调用 auth py 文件和错误。我知道我不需要验证任何东西,因为我有 API 和服务帐户。我只需要使用 elastakert 作为 cron 来执行此操作。

请建议。

4

1 回答 1

0

我对 Python 很熟悉,所以让我尝试用 Python 来回答。我正在使用模块请求。

In [1]: import requests
In [2]: from requests.auth import HTTPBasicAuth

In [3]: url = 'http://es-server:9200/my_log*/_count'
In [4]: data = '''{
   ....:   "query": {
   ....:     "bool": {
   ....:       "must": [
   ....:         {
   ....:           "term": {
   ....:             "deployment": "testapp"
   ....:           }
   ....:         }
   ....:       ]
   ....:     }
   ....:   }
   ....: }'''

In [5]: resp = requests.get(url, auth = HTTPBasicAuth('esuser', 'espwd'), data = data)

In [6]: j = resp.json()

In [7]: j
Out[7]: 
{u'_shards': {u'failed': 0, u'successful': 185, u'total': 185},
 u'count': 2393083}
于 2017-04-19T23:21:22.250 回答