-
Notifications
You must be signed in to change notification settings - Fork 0
/
job-task-indexing.py
74 lines (54 loc) · 1.85 KB
/
job-task-indexing.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Checks if Panda jobs and taks data are indexed
# ====
# This notebook checks number of indexed documents in jobs and panda tables
# and creates alarm if any of them is 0. It is run every 6h from a cron job.
import sys
import json
from datetime import datetime
from alerts import alarms
from elasticsearch import Elasticsearch, exceptions as es_exceptions
config_path = '/config/config.json'
# config_path = 'kube/secrets/config.json'
with open(config_path) 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)
ALARM = alarms('Analytics', 'WFMS', 'indexing')
ct = datetime.now()
currentTime = int(round(datetime.now().timestamp() * 1000))
lastHours = 7
startTime = currentTime - lastHours * 3600000
print('start time', startTime)
print('current time', datetime.now())
# JOBS
query = {
"range": {"modificationtime": {"gte": startTime, "lte": currentTime}}
}
res = es.count(index='jobs', query=query)
print(res)
if res['count'] == 0:
ALARM.addAlarm(body='Issue in indexing jobs.', tags=['jobs'])
# TASKS
query = {
"range": {"modificationtime": {"gte": startTime, "lte": currentTime}}
}
res = es.count(index='tasks', query=query)
print(res)
if res['count'] == 0:
ALARM.addAlarm(body='Issue in indexing tasks.', tags=['tasks'])
# TASK PARAMETERS
query = {
"range": {"creationdate": {"gte": startTime, "lte": currentTime}}
}
res = es.count(index='task_parameters', query=query)
print(res)
if res['count'] == 0:
ALARM.addAlarm(body='Issue in indexing task parameters.',
tags=['task parameters'])