-
Notifications
You must be signed in to change notification settings - Fork 9
/
ilm.py
143 lines (130 loc) · 4.17 KB
/
ilm.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""Launches Elastic ILM"""
import hashlib
import argparse
import time
from argparse import RawTextHelpFormatter
from apscheduler.schedulers.background import BackgroundScheduler
from config import load_settings
from accounting import run_accounting
#from custom_checks import run_custom_checks
from retention import apply_retention_policies
from allocation import apply_allocation_policies
from rollover import apply_rollover_policies
from forcemerge import apply_forcemerge_policies
from backup import run_backup
parser = argparse.ArgumentParser(
description='Used to manually run script (Example: ilm.py --manual 1)',
formatter_class=RawTextHelpFormatter
)
parser.add_argument(
"--manual",
default=0,
type=int,
help="Set to 1 to manually run script"
)
parser.add_argument(
"--client",
default="",
type=str,
help="Set to a specific client name to limit calls to one client"
)
parser.add_argument(
"--notification",
default="True",
type=str,
help="Set to False to disable notifications"
)
args = parser.parse_args()
manual = args.manual
manual_client = args.client
NOTIFICATION = args.notification
if args.notification == "True":
NOTIFICATION = True
else:
NOTIFICATION = False
if manual == 0:
sched = BackgroundScheduler(daemon=True)
else:
sched = BackgroundScheduler(daemon=False)
def start_jobs():
"""Starts background jobs
"""
settings = load_settings()
if 'rollover' in settings:
if settings['rollover']['enabled']:
sched.add_job(
apply_rollover_policies,
'interval',
minutes=settings['rollover']['minutes_between_run'],
args=[manual_client]
)
apply_rollover_policies(manual_client)
if "accounting" in settings:
if settings['accounting']['enabled']:
sched.add_job(
run_accounting,
'interval',
minutes=settings['accounting']['minutes_between_run'],
args=[manual_client]
)
run_accounting(manual_client)
if 'backup' in settings:
if settings['backup']['enabled']:
sched.add_job(run_backup, 'interval', minutes=settings['backup']['minutes_between_run'])
run_backup()
if 'retention' in settings:
if settings['retention']['enabled']:
sched.add_job(
apply_retention_policies,
'interval',
minutes=settings['retention']['minutes_between_run']
#,
#args=[settings['retention']['health_check_level']]
)
apply_retention_policies()
if 'allocation' in settings:
if settings['allocation']['enabled']:
sched.add_job(
apply_allocation_policies,
'interval',
minutes=settings['allocation']['minutes_between_run']
)
apply_allocation_policies()
if 'forcemerge' in settings:
if settings['forcemerge']['enabled']:
sched.add_job(
apply_forcemerge_policies,
'interval',
minutes=settings['forcemerge']['minutes_between_run']
)
else:
sched.add_job(
apply_forcemerge_policies,
'interval',
minutes=1440
)
else:
sched.add_job(
apply_forcemerge_policies,
'interval',
minutes=1440
)
sched.start()
if __name__ == "__main__":
settings_as_bytes = load_settings(format='bytes')
CONFIG_HASH = hashlib.sha256(settings_as_bytes).hexdigest()
start_jobs()
while True:
time.sleep(5)
settings_as_bytes = load_settings(format='bytes')
CURRENT_HASH = hashlib.sha256(settings_as_bytes).hexdigest()
if CURRENT_HASH != CONFIG_HASH:
print("Configuration changed. Reloading jobs")
CONFIG_HASH = CURRENT_HASH
sched.shutdown()
if manual == 0:
sched = BackgroundScheduler(daemon=True)
else:
sched = BackgroundScheduler(daemon=False)
start_jobs()