diff --git a/examples/main.hmdl.json b/examples/main.hmdl.json index 7b6abb1..bdbc795 100644 --- a/examples/main.hmdl.json +++ b/examples/main.hmdl.json @@ -2,7 +2,8 @@ "defaults": { "schedule": { "regular_interval": 10, - "attentive_interval": 1 + "attentive_interval": 1, + "reminding_interval": 20 }, "threshold": 1, "notifications": [ diff --git a/source/logic/conf.py b/source/logic/conf.py index eba6e5f..19e407b 100644 --- a/source/logic/conf.py +++ b/source/logic/conf.py @@ -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": [ ], diff --git a/source/logic/main.py b/source/logic/main.py index 3c3404c..4e08bc8 100644 --- a/source/logic/main.py +++ b/source/logic/main.py @@ -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 ( diff --git a/todo.md b/todo.md index db8e275..9239ecb 100644 --- a/todo.md +++ b/todo.md @@ -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: