93 lines
2.5 KiB
Python
93 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
|
|
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
|
|
# conditions defined in the file COPYING, which is part of this source code package.
|
|
|
|
from cmk.gui.i18n import _
|
|
from cmk.gui.plugins.wato.utils import (
|
|
CheckParameterRulespecWithItem,
|
|
rulespec_registry,
|
|
RulespecGroupCheckParametersDiscovery,
|
|
)
|
|
from cmk.gui.valuespec import Dictionary, Float, Tuple
|
|
|
|
defaults={
|
|
"im_rate_upper": 999999,
|
|
"im_rate_lower": 0,
|
|
"rs_rate_upper": 999999,
|
|
"rs_rate_lower": 0,
|
|
}
|
|
mappings={
|
|
"im": "messages",
|
|
"rs": "bytes",
|
|
"upper": "above",
|
|
"lower": "below",
|
|
}
|
|
|
|
|
|
def _rate(metric, time, level):
|
|
unit=mappings[metric]
|
|
direction=mappings[level]
|
|
return (
|
|
f"{metric}_{time}_rate_{level}",
|
|
Tuple(
|
|
title=_(f"{level.capitalize()} level"),
|
|
elements=[
|
|
Float(
|
|
title=_(f"Warning {direction}"),
|
|
unit=f"{unit}/{time[1:]}min",
|
|
default_value=defaults[f"{metric}_rate_{level}"],
|
|
),
|
|
Float(
|
|
title=_(f"Critical {direction}"),
|
|
unit=f"{unit}/{time[1:]}min",
|
|
default_value=defaults[f"{metric}_rate_{level}"],
|
|
),
|
|
],
|
|
),
|
|
)
|
|
|
|
|
|
def _element(metric, time):
|
|
return (
|
|
f"{metric}_{time}_rate",
|
|
Dictionary(
|
|
title=_(f"Incoming {mappings[metric]} for past {time[1:]} minute"),
|
|
elements=[
|
|
_rate(metric, time, "upper"),
|
|
_rate(metric, time, "lower")
|
|
]
|
|
),
|
|
)
|
|
|
|
|
|
def _parameter_valuespec_graylog_input_metrics():
|
|
matrix=[
|
|
("im", "m1"), ("im", "m5"), ("im", "m15"),
|
|
("rs", "m1"), ("rs", "m5"), ("rs", "m15"),
|
|
]
|
|
|
|
elements=[
|
|
_element(metric, time) for metric, time in matrix
|
|
]
|
|
|
|
return Dictionary(
|
|
title=_("Message and data rates"),
|
|
help=_(
|
|
"These rates are queried directly from the Graylog instance. "
|
|
"Upper and lower levels can be specified for individual metric."
|
|
),
|
|
elements=elements
|
|
)
|
|
|
|
|
|
rulespec_registry.register(
|
|
CheckParameterRulespecWithItem(
|
|
check_group_name="graylog_input_metrics",
|
|
group=RulespecGroupCheckParametersDiscovery,
|
|
match_type="dict",
|
|
parameter_valuespec=_parameter_valuespec_graylog_input_metrics,
|
|
title=lambda: _("Graylog input metrics"),
|
|
)
|
|
)
|