Merge branch 'master' into issue-1

This commit is contained in:
Christian Fraß 2023-03-04 14:08:25 +01:00
commit 236f7a3774

View file

@ -1,4 +1,5 @@
def conf_schema_active():
def conf_schema_active(
):
return {
"description": "whether the check shall be executed",
"type": "boolean",
@ -6,7 +7,8 @@ def conf_schema_active():
}
def conf_schema_threshold():
def conf_schema_threshold(
):
return {
"description": "how often a condition has to occur in order to be reported",
"type": "integer",
@ -15,7 +17,8 @@ def conf_schema_threshold():
}
def conf_schema_annoy():
def conf_schema_annoy(
):
return {
"description": "whether notifications shall be kept sending after the threshold has been surpassed",
"type": "boolean",
@ -23,7 +26,9 @@ def conf_schema_annoy():
}
def conf_schema_interval(default):
def conf_schema_interval(
default
):
return {
"anyOf": [
{
@ -46,7 +51,8 @@ def conf_schema_interval(default):
}
def conf_schema_schedule():
def conf_schema_schedule(
):
return {
"type": "object",
"additionalProperties": False,
@ -59,7 +65,9 @@ def conf_schema_schedule():
}
def conf_schema_notifications(notification_channel_implementations):
def conf_schema_notifications(
notification_channel_implementations
):
return {
"type": "array",
"items": {
@ -95,7 +103,10 @@ def conf_schema_notifications(notification_channel_implementations):
}
def conf_schema_root(check_kind_implementations, notification_channel_implementations):
def conf_schema_root(
check_kind_implementations,
notification_channel_implementations
):
return {
"type": "object",
"additionalProperties": False,
@ -179,7 +190,9 @@ def conf_schema_root(check_kind_implementations, notification_channel_implementa
}
def conf_normalize_interval(interval_raw):
def conf_normalize_interval(
interval_raw
):
if (type(interval_raw) == int):
return interval_raw
elif (type(interval_raw) == str):
@ -197,7 +210,9 @@ def conf_normalize_interval(interval_raw):
raise ValueError("invalid type for interval value")
def conf_normalize_schedule(node):
def conf_normalize_schedule(
node
):
node_ = dict_merge(
{
"regular_interval": (60 * 60),
@ -211,7 +226,10 @@ def conf_normalize_schedule(node):
}
def conf_normalize_notification(notification_channel_implementations, node):
def conf_normalize_notification(
notification_channel_implementations,
node
):
if (node["kind"] not in notification_channel_implementations):
raise ValueError("invalid notification kind: %s" % notification["kind"])
else:
@ -221,7 +239,10 @@ def conf_normalize_notification(notification_channel_implementations, node):
}
def conf_normalize_defaults(notification_channel_implementations, node):
def conf_normalize_defaults(
notification_channel_implementations,
node
):
node_ = dict_merge(
{
"active": True,
@ -250,7 +271,12 @@ def conf_normalize_defaults(notification_channel_implementations, node):
}
def conf_normalize_check(check_kind_implementations, notification_channel_implementations, defaults, node):
def conf_normalize_check(
check_kind_implementations,
notification_channel_implementations,
defaults,
node
):
if ("name" not in node):
raise ValueError("missing mandatory field in 'check' node: 'name'")
else:
@ -261,17 +287,41 @@ def conf_normalize_check(check_kind_implementations, notification_channel_implem
raise ValueError("invalid check kind: '%s'" % node["kind"])
else:
node_ = dict_merge(
dict_merge(
defaults,
{
"title": node["name"],
"active": defaults["active"],
"threshold": defaults["threshold"],
"annoy": defaults["annoy"],
"schedule": defaults["schedule"],
"notifications": defaults["notifications"],
"parameters": {},
},
),
node
)
node__ = {}
if True:
node__["name"] = node_["name"]
if True:
node__["title"] = node_["title"]
if ("active" in node_):
node__["active"] = node_["active"]
if ("threshold" in node_):
node__["threshold"] = node_["threshold"]
if ("annoy" in node_):
node__["annoy"] = node_["annoy"]
if ("schedule" in node_):
node__["schedule"] = conf_normalize_schedule(node_["schedule"])
if ("notification" in node_):
node__["notification"] = list(
map(
lambda x: conf_normalize_notification(notification_channel_implementations, x),
node_["notifications"]
)
)
if ("kind" in node_):
node__["kind"] = node_["kind"]
if True:
node__["parameters"] = check_kind_implementations[node_["kind"]].normalize_conf_node(node_["parameters"])
return node__
'''
return {
"name": node_["name"],
"title": node_["title"],
@ -288,13 +338,21 @@ def conf_normalize_check(check_kind_implementations, notification_channel_implem
"kind": node_["kind"],
"parameters": check_kind_implementations[node_["kind"]].normalize_conf_node(node_["parameters"]),
}
'''
def conf_normalize_root(
check_kind_implementations,
notification_channel_implementations,
node
node,
options = None
):
options = dict_merge(
{
"use_implicit_default_values": True,
},
({} if (options is None) else options)
)
counts = {}
checks_raw = (
node["checks"]
@ -316,13 +374,18 @@ def conf_normalize_root(
)
)
else:
defaults = conf_normalize_defaults(
notification_channel_implementations,
(
defaults_raw = (
node["defaults"]
if ("defaults" in node) else
{}
)
defaults = (
conf_normalize_defaults(
notification_channel_implementations,
defaults_raw
)
if options["use_implicit_default_values"] else
defaults_raw
)
includes = (
node["includes"]
@ -350,14 +413,18 @@ def conf_load(
check_kind_implementations,
notification_channel_implementations,
path,
already_included = None
options = None
):
if (already_included is None):
already_included = set([])
if (path in already_included):
options = dict_merge(
{
"root": True,
"already_included": set([]),
},
({} if (options is None) else options)
)
if (path in options["already_included"]):
raise ValueError("circular dependency detected")
else:
already_included.add(path)
conf_raw = _json.loads(file_read(path))
includes = (
conf_raw["includes"]
@ -374,7 +441,10 @@ def conf_load(
if _os.path.isabs(path_) else
_os.path.join(_os.path.dirname(path), path_)
),
already_included
{
"root": False,
"already_included": (options["already_included"] | {path})
}
)
if (not "checks" in conf_raw):
conf_raw["checks"] = []
@ -401,6 +471,9 @@ def conf_load(
return conf_normalize_root(
check_kind_implementations,
notification_channel_implementations,
conf_raw
conf_raw,
{
"use_implicit_default_values": options["root"],
}
)