-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjob.py
executable file
·46 lines (38 loc) · 1.28 KB
/
job.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
import logging
import sys
from kokudaily.config import Config
from kokudaily.config import REGISTRY
from kokudaily.reports import run_reports
from kokudaily.send import email
from kokudaily.send import prometheus
from kokudaily.send import s3
from prometheus_client import push_to_gateway
root = logging.getLogger()
root.setLevel(Config.LOGLEVEL)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(Config.LOGLEVEL)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
root.addHandler(handler)
LOG = logging.getLogger(__name__)
LOG.info("Starting report job.")
report_data = run_reports()
for target, report_dict in report_data.items():
report_files = []
recipients = Config.EMAIL_GROUPS.get(target)
for report_name, report in report_dict.items():
path = report.get("file")
if path:
report_files.append(path)
prometheus(target, report_name, **report)
s3(target, report_name, **report)
email(recipients, attachments=report_files, target=target)
if Config.PROMETHEUS_PUSH_GATEWAY:
push_to_gateway(
Config.PROMETHEUS_PUSH_GATEWAY,
job="cost_metrics",
registry=REGISTRY,
)
LOG.info("Completed report job.")