summaryrefslogtreecommitdiff
path: root/python_scripts/src/python_scripts/module2.old
diff options
context:
space:
mode:
Diffstat (limited to 'python_scripts/src/python_scripts/module2.old')
-rw-r--r--python_scripts/src/python_scripts/module2.old44
1 files changed, 44 insertions, 0 deletions
diff --git a/python_scripts/src/python_scripts/module2.old b/python_scripts/src/python_scripts/module2.old
new file mode 100644
index 00000000..3df7a768
--- /dev/null
+++ b/python_scripts/src/python_scripts/module2.old
@@ -0,0 +1,44 @@
+import pandas as pd
+import requests
+import numpy as np
+
+"""
+The threshold should be set based on a OpenDC failure model with statistical distribution.
+"""
+confidence_red = 0.95
+confidence_yellow = 0.80
+sigma = 0
+
+
+def check_metric(stream, frame, threshold, dictionary):
+ timestamp = int(stream[b"timestamp"].decode())
+ host = str(stream[b"host_id"].decode())
+ new_threshold = threshold
+ filtered_df = frame[
+ (frame["timestamp"] == timestamp) & (frame["host_name"] == host)
+ ]
+ y_t = float(stream[b"downtime"].decode())
+ y_t_hat = float(filtered_df["downtime"].iloc[0])
+ e_t = y_t - y_t_hat
+
+ if e_t > threshold * confidence_red:
+ print(f"Red,{timestamp}")
+ dictionary[str(timestamp)] = dictionary.get(str(timestamp), 0) + 1
+
+ alert = {"Name": "Alert", "Type": "Red", "Timestamp": str(timestamp)}
+ alert_dt(alert)
+ return new_threshold
+
+ if e_t > threshold * confidence_yellow:
+ print(new_threshold)
+ dictionary[str(timestamp)] = dictionary.get(str(timestamp), 0) + 1
+ print(f"Yellow,{timestamp}")
+ alert = {"Name": "Alert", "Type": "Yellow", "Timestamp": str(timestamp)}
+ alert_dt(alert)
+ return new_threshold
+
+ return new_threshold
+
+
+def alert_dt(alert):
+ requests.post("http://localhost:1234/insight", json=alert)