[issue-3] [add] conf:reminding_interval [mod] main:heed reminding_interval and last_notification_timestamp

This commit is contained in:
Christian Fraß 2023-03-22 11:40:28 +01:00
parent 3ae65c08db
commit 554ca49c49
4 changed files with 47 additions and 23 deletions

View file

@ -2,7 +2,8 @@
"defaults": {
"schedule": {
"regular_interval": 10,
"attentive_interval": 1
"attentive_interval": 1,
"reminding_interval": 20
},
"threshold": 1,
"notifications": [

View file

@ -27,13 +27,14 @@ def conf_schema_annoy(
def conf_schema_interval(
allow_null,
default
):
return {
"anyOf": [
{
"description": "in seconds",
"type": "integer",
"type": ("integer" if allow_null else ["null", "integer"]),
"exclusiveMinimum": 0,
},
{
@ -57,8 +58,9 @@ def conf_schema_schedule(
"type": "object",
"additionalProperties": False,
"properties": {
"regular_interval": conf_schema_interval(60 * 60),
"attentive_interval": conf_schema_interval(60 * 2),
"regular_interval": conf_schema_interval(False, (60 * 60)),
"attentive_interval": conf_schema_interval(False, (60 * 2)),
"reminding_interval": conf_schema_interval(True, (60 * 60 * 24)),
},
"required": [
],
@ -193,22 +195,25 @@ def conf_schema_root(
def conf_normalize_interval(
interval_raw
):
if (type(interval_raw) == int):
return interval_raw
elif (type(interval_raw) == str):
map_ = {
"minute": (60),
"hour": (60 * 60),
"day": (60 * 60 * 24),
"week": (60 * 60 * 24 * 7),
}
if (interval_raw not in map_):
raise ValueError("invalid string interval value: %s" % interval_raw)
else:
return map_[interval_raw]
if (interval_raw is None):
return None
else:
raise ValueError("invalid type for interval value")
if (type(interval_raw) == int):
return interval_raw
elif (type(interval_raw) == str):
map_ = {
"minute": (60),
"hour": (60 * 60),
"day": (60 * 60 * 24),
"week": (60 * 60 * 24 * 7),
}
if (interval_raw not in map_):
raise ValueError("invalid string interval value: %s" % interval_raw)
else:
return map_[interval_raw]
else:
raise ValueError("invalid type for interval value")
def conf_normalize_schedule(
node
@ -217,12 +222,14 @@ def conf_normalize_schedule(
{
"regular_interval": (60 * 60),
"attentive_interval": (60 * 2),
"reminding_interval": (60 * 60 * 24),
},
node
)
return {
"regular_interval": conf_normalize_interval(node["regular_interval"]),
"attentive_interval": conf_normalize_interval(node["attentive_interval"]),
"reminding_interval": conf_normalize_interval(node["reminding_interval"]),
}
@ -251,6 +258,7 @@ def conf_normalize_defaults(
"schedule": {
"regular_interval": (60 * 60),
"attentive_interval": (60 * 2),
"reminding_interval": (60 * 60 * 24),
},
"notifications": [
],

View file

@ -266,6 +266,24 @@ def main():
and
check_data["annoy"]
)
or
(
(count is None)
and
(
(old_item_state is not None)
and
(old_item_state["last_notification_timestamp"] is not None)
and
(check_data["schedule"]["reminding_interval"] is not None)
and
(
(timestamp - old_item_state["last_notification_timestamp"])
>=
check_data["schedule"]["reminding_interval"]
)
)
)
)
and
(

View file

@ -1,8 +1,5 @@
- parallele Zugriffe auf die Zustands-Datei verhindern
- mutex?
- auf DB umstellen?
- auf DB umstellen?
- Benachrichtigungen versenden, wenn ein Zustand sich wieder normalisiert hat (aber vorher über dem Schwellwert oft nicht OK war)
- erneute Benachrichtigung über nicht-OK-Zustand nach einer Weile (siehe https://gitlab.greenscale.de/tools/heimdall/-/issues/3)
- längere Statistiken über Metriken führen um auch Anstiege/Abfälle auszuwerten (z.B. "Speicherplatzverbrauch innerhalb einer Woche um 5GB gestiegen")
- Selbst-Test
- Benachrichtigungs-Kanäle: