-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes-cluster-state.py
37 lines (28 loc) · 1015 Bytes
/
es-cluster-state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Check Cluster State
# ====
# This notebook check the state of ES cluster and if needed creates alarm.
# It is run once per hour from a cron job.
import sys
from alerts import alarms
from elasticsearch import Elasticsearch
import json
with open('/config/config.json') as json_data:
config = json.load(json_data,)
es = Elasticsearch(
hosts=[{'host': config['ES_HOST'], 'port':9200, 'scheme':'https'}],
basic_auth=(config['ES_USER'], config['ES_PASS']),
request_timeout=60)
if es.ping():
print('connected to ES.')
else:
print('no connection to ES.')
sys.exit(1)
report=es.health_report()
print(report)
if report['status'] == 'green':
sys.exit(0)
ALARM = alarms('Analytics', 'Elasticsearch', 'status')
if report['status'] == 'red':
ALARM.addAlarm(body='Alert on Elastic cluster state [ES in red]', tags=['red'])
if report['status'] == 'yellow':
ALARM.addAlarm(body='Alert on Elastic cluster state [ES in yellow]', tags=['yellow'])