zabbix-elasticsearch

Форк
0
/
index_health.py 
42 строки · 1.1 Кб
1
from urllib.parse import urlparse
2

3
import json
4
import argparse
5
import requests
6
import sys
7

8

9
class InspectIndex():
10
    """ Stub """
11

12
    def __init__(self):
13
        """ Stub """
14
        self.value = None
15

16
    def get_index_metric(self, url, index, metric):
17
        """
18
        Return specific metric for the especified index.
19
        """
20
        address = url.scheme + '://' + url.netloc + '/_cat/indices/%s?format=json' % index
21
        result = requests.get(address)
22
        
23
        assert result.status_code == 200
24

25
        state = result.json()[0]
26
        
27
        if metric in state.keys():
28
            print(state[metric])
29
            sys.exit(0)
30

31
        raise ValueError('The Key %s provided not exists on the response' %metric)        
32

33
if __name__ == '__main__':
34
    parser = argparse.ArgumentParser()
35
    parser.add_argument('--url', type=urlparse, required=True)
36
    parser.add_argument('--index', type=str, required=True)
37
    parser.add_argument('--metric', type=str, required=True)
38
    
39
    args = parser.parse_args()
40
    
41
    index = InspectIndex()
42
    index.get_index_metric(args.url, args.index, args.metric)
43

44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.