Module: check_mk
Branch: master
Commit: abcf3ea751e29e94f0a22d8cbe670ca139104764
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=abcf3ea751e29e…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Tue Jan 17 15:00:57 2017 +0100
4187 FIX check_mk_agent.linux: better performance for tcp connections query
The previously method to get information about tcp connections will slow
down if the host is under heavy load. The new option to get these information
will be more stable in this point. The legacy method (cat /proc/net/tcp) will
still be used for older linux distributions, where ss may not be available.
Change-Id: If3b8405b956ee33f0481ba4167e41d36d5d968d9
---
.werks/4187 | 12 ++++++++++++
agents/check_mk_agent.linux | 9 ++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/.werks/4187 b/.werks/4187
new file mode 100644
index 0000000..0d3344e
--- /dev/null
+++ b/.werks/4187
@@ -0,0 +1,12 @@
+Title: check_mk_agent.linux: better performance for tcp connections query
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i4
+Date: 1484661608
+Class: fix
+
+The previously method to get information about tcp connections will slow
+down if the host is under heavy load. The new option to get these information
+will be more stable in this point. The legacy method (cat /proc/net/tcp) will
+still be used for older linux distributions, where ss may not be available.
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index cecb049..4e1ec35 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -386,7 +386,14 @@ fi
# Number of TCP connections in the various states
echo '<<<tcp_conn_stats>>>'
-cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk ' /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } }'
+if type waitmax >/dev/null ; then
+ THIS=$(waitmax -s 1 10 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk ' /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } }')
+ if [ $? == 0 ] ; then
+ echo "$THIS"
+ else
+ ss -ant |grep -v ^State | awk ' /:/ { c[$1]++; } END { for (x in c) { print x, c[x]; } }' |sed -e 's/^ESTAB/01/g;s/^SYN-SENT/02/g;s/^SYN-RECV/03/g;s/^FIN-WAIT-1/04/g;s/^FIN-WAIT-2/05/g;s/^TIME-WAIT/06/g;s/^CLOSED/07/g;s/^CLOSE-WAIT/08/g;s/^LAST-ACK/09/g;s/^LISTEN/0A/g;s/^CLOSING/0B/g;'
+ fi
+fi
# Linux Multipathing
if type multipath >/dev/null ; then
Module: check_mk
Branch: master
Commit: b2107a8529bd0c25f5de797a090e46ae75ba616c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2107a8529bd0c…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Mar 13 15:27:31 2017 +0100
4460 BI aggregations: Now able to configure additional message for each rule result
When configuring a rule, you can now set an optional message, which will be displayed
beside the rule result. In earlier versions, a rule result was <i>OK</i>, <i>CRIT</i>, etc.
The new option allows you to provide an additional text for each state.
So the result now may look like <i>CRIT, only 70% of servers are up</i>.
This additional information is also shown in the check plugins <i>check_bi_aggr</i> and <i>check_bi_locals.py</i>.
Change-Id: I898723b3b301d743700bdceb6f25fac6db297835
---
.werks/4460 | 19 +++++++++++++++++++
web/htdocs/bi.py | 37 ++++++++++++++++++++++++++++++-------
web/plugins/wato/bi.py | 22 +++++++++++++++++++++-
3 files changed, 70 insertions(+), 8 deletions(-)
diff --git a/.werks/4460 b/.werks/4460
new file mode 100644
index 0000000..f628528
--- /dev/null
+++ b/.werks/4460
@@ -0,0 +1,19 @@
+Title: BI aggregations: Now able to configure additional message for each rule result
+Level: 1
+Component: bi
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1489414976
+
+When configuring a rule, you can now set an optional message, which will be displayed
+beside the rule result. In earlier versions, a rule result was <i>OK</i>, <i>CRIT</i>, etc.
+The new option allows you to provide an additional text for each state.
+
+
+So the result now may look like <i>CRIT, only 70% of servers are up</i>.
+
+
+This additional information is also shown in the check plugins <i>check_bi_aggr</i> and <i>check_bi_locals.py</i>.
diff --git a/web/htdocs/bi.py b/web/htdocs/bi.py
index 0fc5e0b..3109b62 100644
--- a/web/htdocs/bi.py
+++ b/web/htdocs/bi.py
@@ -2016,15 +2016,17 @@ def compile_aggregation_rule(aggr_type, rule, args, lvl):
# Convert new dictionary style rule into old tuple based
# format
+ # TODO: O.o Remove this code, all of it...
if type(rule) == dict:
rule = (
rule.get("title", _("Untitled BI rule")),
rule.get("params", []),
rule.get("aggregation", "worst"),
- rule.get("nodes", [])
+ rule.get("nodes", []),
+ rule.get("state_messages")
)
- if len(rule) != 4:
+ if len(rule) != 5:
raise MKConfigError(_("<b>Invalid BI aggregation rule</b>: "
"Aggregation rules must contain four elements: description, argument list, "
"aggregation function and list of nodes. Your rule has %d elements: "
@@ -2036,7 +2038,7 @@ def compile_aggregation_rule(aggr_type, rule, args, lvl):
"too many levels or built an infinite recursion. This happened in rule %s")
% pprint.pformat(rule))
- description, arglist, funcname, nodes = rule
+ description, arglist, funcname, nodes, state_messages = rule
# check arguments and convert into dictionary
if len(arglist) != len(args):
@@ -2135,6 +2137,9 @@ def compile_aggregation_rule(aggr_type, rule, args, lvl):
"func" : funcname,
"nodes" : elements}
+ if state_messages:
+ aggregation["state_messages"] = state_messages
+
# Handle REMAINING references, if we are a root node
if lvl == 0:
for hostspec, ref, placeholder in g_remaining_refs:
@@ -2855,6 +2860,17 @@ def ajax_render_tree():
raise MKGeneralException(_("Unknown BI Aggregation %s") % aggr_title)
+def compute_output_message(effective_state, rule):
+ output = []
+ if effective_state["output"]:
+ output.append(effective_state["output"])
+
+ str_state = str(effective_state["state"])
+ if str_state in rule.get("state_messages", {}):
+ output.append(html.attrencode(rule["state_messages"][str_state]))
+
+ return ", ".join(output)
+
def render_tree_json(row):
expansion_level = int(html.var("expansion_level", 999))
@@ -2895,8 +2911,7 @@ def render_tree_json(row):
effective_state = tree[0]
json_node["state"] = effective_state["state"]
- json_node["output"] = effective_state["output"]
-
+ json_node["output"] = compute_output_message(effective_state, tree[2])
return json_node
@@ -3055,13 +3070,18 @@ def aggr_render_node(tree, title, show_host, mousecode=None, img_class=None):
title = ('<img class="icon bi" src="images/icon_outof_serviceperiod.png" title="%s">' % \
_("This element is currently not in its service period.")) + title
+
h = '<span class="content state state%d%s">%s</span>\n' \
% (effective_state["state"] if effective_state["state"] != None else -1, addclass, render_bi_state(effective_state["state"]))
if mousecode:
+ state_message = ""
+ if str(effective_state["state"]) in tree[2].get("state_messages", {}):
+ state_message = "<b class=bullet>♦</b>" + html.attrencode(tree[2]["state_messages"][str(effective_state["state"])])
+
if img_class:
h += '<img src="images/tree_black_closed.png" class="treeangle %s"%s>' % \
(img_class, mousecode)
- h += '<span class="content name" %s>%s</span>' % (mousecode, title)
+ h += '<span class="content name" %s>%s%s</span>' % (mousecode, title, state_message)
else:
h += title
@@ -3174,6 +3194,8 @@ def create_aggregation_row(tree, status_info = None):
if assumed_state != None:
eff_state = assumed_state
+ output = compute_output_message(eff_state, node)
+
return {
"aggr_tree" : tree,
"aggr_treestate" : tree_state,
@@ -3181,7 +3203,7 @@ def create_aggregation_row(tree, status_info = None):
"aggr_assumed_state" : assumed_state, # is None, if there are no assumptions
"aggr_effective_state" : eff_state, # is assumed_state, if there are assumptions, else real state
"aggr_name" : node["title"],
- "aggr_output" : eff_state["output"],
+ "aggr_output" : output,
"aggr_hosts" : node["reqhosts"],
"aggr_function" : node["func"],
}
@@ -3486,3 +3508,4 @@ def migrate_bi_configuration():
config.host_aggregations = map(convert_aggregation, config.host_aggregations)
if config.aggregations and type(config.aggregations[0]) != dict:
config.aggregations = map(convert_aggregation, config.aggregations)
+
diff --git a/web/plugins/wato/bi.py b/web/plugins/wato/bi.py
index f0bc857..bfbf9c4 100644
--- a/web/plugins/wato/bi.py
+++ b/web/plugins/wato/bi.py
@@ -1516,6 +1516,26 @@ class ModeBIEditRule(ModeBI):
title = _("Nodes that are aggregated by this rule"),
),
),
+ ( "state_messages",
+ Optional(
+ Dictionary(
+ elements = map(lambda (state, name):
+ (state, TextAscii(
+ title = _("Message when rule result is %s") % name,
+ default_value = None, size = 80)),
+ [("0", "OK"),
+ ("1", "WARN"),
+ ("2", "CRIT"),
+ ("3", "UNKNOWN")])
+ ),
+ title = _("Additional messages describing rule state"),
+ help = _("This option allows you to display an additional, freely configurable text, to the rule outcome, "
+ "which may describe the state more in detail. For example, instead of <tt>CRIT</tt>, the rule can now "
+ "display <tt>CRIT, less than 70% of servers reachable</tt>. This message is also shown within the BI aggregation "
+ "check plugins."),
+ label = _("Add messages")
+ )
+ )
]
return Dictionary(
@@ -1526,7 +1546,7 @@ class ModeBIEditRule(ModeBI):
headers = [
( _("General Properties"), [ "id", "title", "comment", "params", "disabled" ]),
( _("Child Node Generation"), [ "nodes" ] ),
- ( _("Aggregation Function"), [ "aggregation" ], ),
+ ( _("Aggregation Function"), [ "aggregation", "state_messages" ], ),
]
)