Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from email.message import EmailMessage
|
|
11 |
import matplotlib.pyplot as plt
|
12 |
import numpy as np
|
13 |
from collections import defaultdict
|
|
|
14 |
|
15 |
# Configuration
|
16 |
CONFIG_FILE = "config.yaml"
|
@@ -25,10 +26,28 @@ class Monitor:
|
|
25 |
self.incidents = defaultdict(list)
|
26 |
|
27 |
def load_config(self):
|
|
|
28 |
with open(CONFIG_FILE, "r") as f:
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
config.setdefault('settings', {})
|
31 |
config['settings'].setdefault('check_interval_seconds', 300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
return config
|
33 |
|
34 |
def load_data(self):
|
|
|
11 |
import matplotlib.pyplot as plt
|
12 |
import numpy as np
|
13 |
from collections import defaultdict
|
14 |
+
from string import Template
|
15 |
|
16 |
# Configuration
|
17 |
CONFIG_FILE = "config.yaml"
|
|
|
26 |
self.incidents = defaultdict(list)
|
27 |
|
28 |
def load_config(self):
|
29 |
+
# Load and substitute environment variables in the config
|
30 |
with open(CONFIG_FILE, "r") as f:
|
31 |
+
config_content = f.read()
|
32 |
+
|
33 |
+
# Replace ${VAR} with environment variables
|
34 |
+
config_content = Template(config_content).substitute(os.environ)
|
35 |
+
config = yaml.safe_load(config_content)
|
36 |
+
|
37 |
+
# Set defaults
|
38 |
config.setdefault('settings', {})
|
39 |
config['settings'].setdefault('check_interval_seconds', 300)
|
40 |
+
|
41 |
+
# Validate required environment variables
|
42 |
+
required_vars = ['SMTP_HOST', 'SMTP_PORT', 'SMTP_USERNAME', 'SMTP_PASSWORD', 'SMTP_FROM']
|
43 |
+
for var in required_vars:
|
44 |
+
if var not in os.environ:
|
45 |
+
raise ValueError(f"Missing required environment variable: {var}")
|
46 |
+
|
47 |
+
# Add SMTP credentials from environment
|
48 |
+
config['settings']['smtp']['username'] = os.environ['SMTP_USERNAME']
|
49 |
+
config['settings']['smtp']['password'] = os.environ['SMTP_PASSWORD']
|
50 |
+
|
51 |
return config
|
52 |
|
53 |
def load_data(self):
|