+def generate_prometheus_alerts(prometheus_alerts, config_file_path):
+ with open(config_file_path, encoding="utf-8", mode="r") as config_file:
+ config_file_yaml = yaml.safe_load(config_file)
+ if config_file_yaml is None:
+ config_file_yaml = {}
+ if "groups" not in config_file_yaml:
+ config_file_yaml["groups"] = []
+
+ timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
+ group = {
+ "name": f"_osm_alert_rules_{timestamp}_",
+ "rules": [],
+ }
+ for alert in prometheus_alerts:
+ if "prometheus_config" in alert:
+ group["rules"].append(alert["prometheus_config"])
+
+ if group["rules"]:
+ config_file_yaml["groups"].append(group)
+
+ return config_file_yaml
+
+