2017-04-19 76 views
0

這可能是不正確的地方問這個問題。但是我找不到要這樣做的文章。 我在CentOS上安裝了下面的軟件包。如何從elastalert調用elasticsearch - ELK - API?

 
Elasticsearch (I don't need it as I am trying to talk to ELK stack cluster using an API. I don't want ealsticsearch run locally on the box where I have elastalert.) 
ISO8601 or Unix timestamped data 
Python 2.6 or 2.7 
pip, see requirements.txt 

但是,如何使用API​​調用彈性搜索集羣。我有API和一個服務帳戶來這樣做。 這是什麼,我在找。 我應該修改哪個文件在elastalert-master/example_rules下?

我試着改變config.yaml.example,但仍然不斷調用auth py文件和錯誤。 我知道我不需要授權任何東西,因爲我擁有API和服務帳戶。 我只需要使用elastakert作爲cron來做到這一點。

請建議。

回答

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} 
+0

感謝您的回覆@felixc。但是,我沒有尋找一種以這種方式進行API調用的方法。這與我可以使用SOAP或POSTMAN REST工具查詢ELK堆棧的方式類似。我正在尋找一種使用elastalert配置文件來調用ELK堆棧的方法。 – user3709172