Merge branch 'master' into issue-1
This commit is contained in:
commit
236f7a3774
|
|
@ -1,4 +1,5 @@
|
||||||
def conf_schema_active():
|
def conf_schema_active(
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"description": "whether the check shall be executed",
|
"description": "whether the check shall be executed",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
@ -6,7 +7,8 @@ def conf_schema_active():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def conf_schema_threshold():
|
def conf_schema_threshold(
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"description": "how often a condition has to occur in order to be reported",
|
"description": "how often a condition has to occur in order to be reported",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
@ -15,7 +17,8 @@ def conf_schema_threshold():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def conf_schema_annoy():
|
def conf_schema_annoy(
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"description": "whether notifications shall be kept sending after the threshold has been surpassed",
|
"description": "whether notifications shall be kept sending after the threshold has been surpassed",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
@ -23,7 +26,9 @@ def conf_schema_annoy():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def conf_schema_interval(default):
|
def conf_schema_interval(
|
||||||
|
default
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +51,8 @@ def conf_schema_interval(default):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def conf_schema_schedule():
|
def conf_schema_schedule(
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": False,
|
"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 {
|
return {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"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 {
|
return {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": False,
|
"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):
|
if (type(interval_raw) == int):
|
||||||
return interval_raw
|
return interval_raw
|
||||||
elif (type(interval_raw) == str):
|
elif (type(interval_raw) == str):
|
||||||
|
|
@ -197,7 +210,9 @@ def conf_normalize_interval(interval_raw):
|
||||||
raise ValueError("invalid type for interval value")
|
raise ValueError("invalid type for interval value")
|
||||||
|
|
||||||
|
|
||||||
def conf_normalize_schedule(node):
|
def conf_normalize_schedule(
|
||||||
|
node
|
||||||
|
):
|
||||||
node_ = dict_merge(
|
node_ = dict_merge(
|
||||||
{
|
{
|
||||||
"regular_interval": (60 * 60),
|
"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):
|
if (node["kind"] not in notification_channel_implementations):
|
||||||
raise ValueError("invalid notification kind: %s" % notification["kind"])
|
raise ValueError("invalid notification kind: %s" % notification["kind"])
|
||||||
else:
|
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(
|
node_ = dict_merge(
|
||||||
{
|
{
|
||||||
"active": True,
|
"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):
|
if ("name" not in node):
|
||||||
raise ValueError("missing mandatory field in 'check' node: 'name'")
|
raise ValueError("missing mandatory field in 'check' node: 'name'")
|
||||||
else:
|
else:
|
||||||
|
|
@ -261,17 +287,41 @@ def conf_normalize_check(check_kind_implementations, notification_channel_implem
|
||||||
raise ValueError("invalid check kind: '%s'" % node["kind"])
|
raise ValueError("invalid check kind: '%s'" % node["kind"])
|
||||||
else:
|
else:
|
||||||
node_ = dict_merge(
|
node_ = dict_merge(
|
||||||
|
dict_merge(
|
||||||
|
defaults,
|
||||||
{
|
{
|
||||||
"title": node["name"],
|
"title": node["name"],
|
||||||
"active": defaults["active"],
|
|
||||||
"threshold": defaults["threshold"],
|
|
||||||
"annoy": defaults["annoy"],
|
|
||||||
"schedule": defaults["schedule"],
|
|
||||||
"notifications": defaults["notifications"],
|
|
||||||
"parameters": {},
|
"parameters": {},
|
||||||
},
|
},
|
||||||
|
),
|
||||||
node
|
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 {
|
return {
|
||||||
"name": node_["name"],
|
"name": node_["name"],
|
||||||
"title": node_["title"],
|
"title": node_["title"],
|
||||||
|
|
@ -288,13 +338,21 @@ def conf_normalize_check(check_kind_implementations, notification_channel_implem
|
||||||
"kind": node_["kind"],
|
"kind": node_["kind"],
|
||||||
"parameters": check_kind_implementations[node_["kind"]].normalize_conf_node(node_["parameters"]),
|
"parameters": check_kind_implementations[node_["kind"]].normalize_conf_node(node_["parameters"]),
|
||||||
}
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
def conf_normalize_root(
|
def conf_normalize_root(
|
||||||
check_kind_implementations,
|
check_kind_implementations,
|
||||||
notification_channel_implementations,
|
notification_channel_implementations,
|
||||||
node
|
node,
|
||||||
|
options = None
|
||||||
):
|
):
|
||||||
|
options = dict_merge(
|
||||||
|
{
|
||||||
|
"use_implicit_default_values": True,
|
||||||
|
},
|
||||||
|
({} if (options is None) else options)
|
||||||
|
)
|
||||||
counts = {}
|
counts = {}
|
||||||
checks_raw = (
|
checks_raw = (
|
||||||
node["checks"]
|
node["checks"]
|
||||||
|
|
@ -316,13 +374,18 @@ def conf_normalize_root(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
defaults = conf_normalize_defaults(
|
defaults_raw = (
|
||||||
notification_channel_implementations,
|
|
||||||
(
|
|
||||||
node["defaults"]
|
node["defaults"]
|
||||||
if ("defaults" in node) else
|
if ("defaults" in node) else
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
defaults = (
|
||||||
|
conf_normalize_defaults(
|
||||||
|
notification_channel_implementations,
|
||||||
|
defaults_raw
|
||||||
|
)
|
||||||
|
if options["use_implicit_default_values"] else
|
||||||
|
defaults_raw
|
||||||
)
|
)
|
||||||
includes = (
|
includes = (
|
||||||
node["includes"]
|
node["includes"]
|
||||||
|
|
@ -350,14 +413,18 @@ def conf_load(
|
||||||
check_kind_implementations,
|
check_kind_implementations,
|
||||||
notification_channel_implementations,
|
notification_channel_implementations,
|
||||||
path,
|
path,
|
||||||
already_included = None
|
options = None
|
||||||
):
|
):
|
||||||
if (already_included is None):
|
options = dict_merge(
|
||||||
already_included = set([])
|
{
|
||||||
if (path in already_included):
|
"root": True,
|
||||||
|
"already_included": set([]),
|
||||||
|
},
|
||||||
|
({} if (options is None) else options)
|
||||||
|
)
|
||||||
|
if (path in options["already_included"]):
|
||||||
raise ValueError("circular dependency detected")
|
raise ValueError("circular dependency detected")
|
||||||
else:
|
else:
|
||||||
already_included.add(path)
|
|
||||||
conf_raw = _json.loads(file_read(path))
|
conf_raw = _json.loads(file_read(path))
|
||||||
includes = (
|
includes = (
|
||||||
conf_raw["includes"]
|
conf_raw["includes"]
|
||||||
|
|
@ -374,7 +441,10 @@ def conf_load(
|
||||||
if _os.path.isabs(path_) else
|
if _os.path.isabs(path_) else
|
||||||
_os.path.join(_os.path.dirname(path), path_)
|
_os.path.join(_os.path.dirname(path), path_)
|
||||||
),
|
),
|
||||||
already_included
|
{
|
||||||
|
"root": False,
|
||||||
|
"already_included": (options["already_included"] | {path})
|
||||||
|
}
|
||||||
)
|
)
|
||||||
if (not "checks" in conf_raw):
|
if (not "checks" in conf_raw):
|
||||||
conf_raw["checks"] = []
|
conf_raw["checks"] = []
|
||||||
|
|
@ -401,6 +471,9 @@ def conf_load(
|
||||||
return conf_normalize_root(
|
return conf_normalize_root(
|
||||||
check_kind_implementations,
|
check_kind_implementations,
|
||||||
notification_channel_implementations,
|
notification_channel_implementations,
|
||||||
conf_raw
|
conf_raw,
|
||||||
|
{
|
||||||
|
"use_implicit_default_values": options["root"],
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue