zabbix-elasticsearch
42 строки · 1.1 Кб
1from urllib.parse import urlparse2
3import json4import argparse5import requests6import sys7
8
9class InspectIndex():10""" Stub """11
12def __init__(self):13""" Stub """14self.value = None15
16def get_index_metric(self, url, index, metric):17"""18Return specific metric for the especified index.
19"""
20address = url.scheme + '://' + url.netloc + '/_cat/indices/%s?format=json' % index21result = requests.get(address)22
23assert result.status_code == 20024
25state = result.json()[0]26
27if metric in state.keys():28print(state[metric])29sys.exit(0)30
31raise ValueError('The Key %s provided not exists on the response' %metric)32
33if __name__ == '__main__':34parser = argparse.ArgumentParser()35parser.add_argument('--url', type=urlparse, required=True)36parser.add_argument('--index', type=str, required=True)37parser.add_argument('--metric', type=str, required=True)38
39args = parser.parse_args()40
41index = InspectIndex()42index.get_index_metric(args.url, args.index, args.metric)43
44