Switch graylog input metrics plugin to support <= instead of <
This commit is contained in:
parent
0e59597d5d
commit
387b103dcc
BIN
graylog-metrics/2.3/graylog_input_metrics-0.4.0.mkp
Executable file
BIN
graylog-metrics/2.3/graylog_input_metrics-0.4.0.mkp
Executable file
Binary file not shown.
@ -21,7 +21,7 @@ mappings={
|
|||||||
"im": "messages",
|
"im": "messages",
|
||||||
"rs": "bytes",
|
"rs": "bytes",
|
||||||
"upper": "above",
|
"upper": "above",
|
||||||
"lower": "below",
|
"lower": "below or equal",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -7,7 +7,7 @@
|
|||||||
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
|
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
|
||||||
# it might also remove variables needed for accessing discovery rulesets.
|
# it might also remove variables needed for accessing discovery rulesets.
|
||||||
import json
|
import json
|
||||||
from cmk.base.check_api import check_levels, LegacyCheckDefinition
|
from cmk.base.check_api import LegacyCheckDefinition
|
||||||
from cmk.base.config import check_info
|
from cmk.base.config import check_info
|
||||||
from cmk.agent_based.v2 import Service
|
from cmk.agent_based.v2 import Service
|
||||||
|
|
||||||
@ -74,6 +74,79 @@ def check_graylog_input_metrics(item, params, parsed):
|
|||||||
infoname=infotext
|
infoname=infotext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# A customer wanted us to support <= for "below", not <. This meant copying
|
||||||
|
# check_levels() and child functions wholesale out of
|
||||||
|
# lib/python3/cmk/base/check_api.py just to change < to <= in this function.
|
||||||
|
# Sometimes a sledgehammer is what it takes... D:
|
||||||
|
# Start copy ===================================================================
|
||||||
|
from cmk.agent_based import v1 as _v1
|
||||||
|
|
||||||
|
def _do_check_levels(value, levels, human_readable_func):
|
||||||
|
warn_upper, crit_upper, warn_lower, crit_lower = levels
|
||||||
|
|
||||||
|
# Critical cases
|
||||||
|
if crit_upper is not None and value >= crit_upper:
|
||||||
|
return 2, _levelsinfo_ty("at", warn_upper, crit_upper, human_readable_func)
|
||||||
|
if crit_lower is not None and value <= crit_lower:
|
||||||
|
return 2, _levelsinfo_ty("below", warn_lower, crit_lower, human_readable_func)
|
||||||
|
|
||||||
|
# Warning cases
|
||||||
|
if warn_upper is not None and value >= warn_upper:
|
||||||
|
return 1, _levelsinfo_ty("at", warn_upper, crit_upper, human_readable_func)
|
||||||
|
if warn_lower is not None and value <= warn_lower:
|
||||||
|
return 1, _levelsinfo_ty("below", warn_lower, crit_lower, human_readable_func)
|
||||||
|
return 0, ""
|
||||||
|
|
||||||
|
def _levelsinfo_ty(ty, warn, crit, human_readable_func):
|
||||||
|
warn_str = "never" if warn is None else f"{human_readable_func(warn)}"
|
||||||
|
crit_str = "never" if crit is None else f"{human_readable_func(crit)}"
|
||||||
|
return f" (warn/crit {ty} {warn_str}/{crit_str})"
|
||||||
|
|
||||||
|
def _build_perfdata(dsname, value, levels, boundaries):
|
||||||
|
used_boundaries = boundaries if isinstance(boundaries, tuple) and len(boundaries) == 2 else ()
|
||||||
|
return [(dsname, value, levels[0], levels[1], *used_boundaries)]
|
||||||
|
|
||||||
|
def check_levels(value, dsname, params, unit, human_readable_func, infoname, boundaries=None):
|
||||||
|
def render_func(x):
|
||||||
|
return "%s%s" % (human_readable_func(x), unit)
|
||||||
|
|
||||||
|
if params and isinstance(params, dict):
|
||||||
|
result, *metrics = _v1.check_levels_predictive(
|
||||||
|
value,
|
||||||
|
levels=params,
|
||||||
|
metric_name=dsname,
|
||||||
|
render_func=render_func,
|
||||||
|
label=infoname,
|
||||||
|
boundaries=boundaries,
|
||||||
|
)
|
||||||
|
assert isinstance(result, _v1.Result)
|
||||||
|
return (
|
||||||
|
int(result.state),
|
||||||
|
result.summary,
|
||||||
|
[
|
||||||
|
(m.name, m.value, *m.levels, *m.boundaries)
|
||||||
|
for m in metrics
|
||||||
|
if isinstance(m, _v1.Metric)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
infotext = f"{render_func(value)}"
|
||||||
|
if infoname:
|
||||||
|
infotext = f"{infoname}: {infotext}"
|
||||||
|
|
||||||
|
levels = params
|
||||||
|
|
||||||
|
state, levelstext = _do_check_levels(value, levels, render_func)
|
||||||
|
state, levelstext = _do_check_levels(value, levels, render_func)
|
||||||
|
return (
|
||||||
|
state,
|
||||||
|
infotext + levelstext,
|
||||||
|
_build_perfdata(dsname, value, levels, boundaries),
|
||||||
|
)
|
||||||
|
# End copy ====================================================================
|
||||||
|
|
||||||
|
|
||||||
check_info["graylog_input_metrics"] = LegacyCheckDefinition(
|
check_info["graylog_input_metrics"] = LegacyCheckDefinition(
|
||||||
parse_function = parse_graylog_input_metrics,
|
parse_function = parse_graylog_input_metrics,
|
||||||
check_function = check_graylog_input_metrics,
|
check_function = check_graylog_input_metrics,
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user