Sample subject
This commit is contained in:
parent
897979d4cc
commit
0a26445778
41
papi/main.py
41
papi/main.py
|
@ -32,7 +32,8 @@ Base.metadata.create_all(bind=engine)
|
|||
conf = ConfigParser()
|
||||
conf.read("conf_notifications.ini")
|
||||
|
||||
configurations = read_config(pattern="*api_client*sonde*")
|
||||
configurations = read_config(pattern="*api_client*")
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
console = logging.StreamHandler()
|
||||
|
@ -44,13 +45,16 @@ logger.addHandler(console)
|
|||
PROBES = {}
|
||||
|
||||
|
||||
def sondeid2notifsemails(idsonde, mapping=conf):
|
||||
def sondeid2notifsemails(idsonde, mapping=None):
|
||||
if mapping is None:
|
||||
mapping = PROBES
|
||||
try:
|
||||
breakpoint()
|
||||
section = mapping[idsonde]
|
||||
except KeyError: # pragma: no cover
|
||||
raise KeyError(f"{idsonde} non trouvé dans {list(mapping.keys())}")
|
||||
|
||||
mails = section["email"]
|
||||
mails = section["emails"]
|
||||
if isinstance(mails, str):
|
||||
mails = [x.strip() for x in mails.split("\n")]
|
||||
return mails
|
||||
|
@ -74,9 +78,15 @@ def atomic_db():
|
|||
db.close()
|
||||
|
||||
|
||||
sondes = {"test": schemas.SondeBase(identifiant="test", nom="Testlocal")}
|
||||
|
||||
|
||||
def apply_config(configs: list[dict] = []):
|
||||
with atomic_db() as db:
|
||||
for config in configs:
|
||||
name = config["nom_sonde"].lower()
|
||||
if "test" in name or "dummy" in name:
|
||||
continue
|
||||
identifiant = config["identifiant_sonde"]
|
||||
sonde = crud.get_sonde(db, identifiant)
|
||||
if sonde is None:
|
||||
|
@ -106,11 +116,32 @@ class Notifier:
|
|||
"status": ["Le monitoring est inacessible"],
|
||||
}
|
||||
)
|
||||
conf = PROBES[idsonde]
|
||||
|
||||
subject = "Probleme api supervision"
|
||||
content = kind
|
||||
from papi.mail_sendermodel import sendmail
|
||||
|
||||
if True:
|
||||
|
||||
sendmail(
|
||||
htmlpart="",
|
||||
emails=conf["emails"],
|
||||
textpart=kind,
|
||||
subject="probleme supervision api",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def clean():
|
||||
for k, v in notifications.items():
|
||||
notifications[k] = v[-3:]
|
||||
|
||||
|
||||
Notifier = Notifier()
|
||||
|
||||
sondes = {"test": schemas.SondeBase(identifiant="test", nom="Testlocal")}
|
||||
for k, sonde in PROBES.items():
|
||||
sondes[k] = schemas.SondeBase(
|
||||
identifiant=sonde["identifiant_sonde"], nom=sonde["nom_sonde"]
|
||||
)
|
||||
|
||||
|
||||
def default_sample():
|
||||
|
|
|
@ -5,6 +5,7 @@ from copy import deepcopy
|
|||
|
||||
import math
|
||||
import itertools
|
||||
import collections
|
||||
import datetime
|
||||
import csv
|
||||
import json
|
||||
|
@ -29,6 +30,16 @@ def get_status(channels, key):
|
|||
return d
|
||||
|
||||
|
||||
def sample2statuscount(prepared):
|
||||
sumup = [
|
||||
"%s: %d" % (k, v)
|
||||
for k, v in collections.Counter(
|
||||
x["status"] for x in prepared["channels"].values()
|
||||
).items()
|
||||
]
|
||||
return sumup
|
||||
|
||||
|
||||
def compare(channels, previous, current):
|
||||
changes, states = [], []
|
||||
for key in channels:
|
||||
|
|
Loading…
Reference in New Issue