Module: check_mk
Branch: master
Commit: 5d4411f4513f870f022416efe982b65721dfede8
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5d4411f4513f87…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 3 11:04:26 2016 +0100
Custom graphs can now be added to dashboards using the context menu
---
web/htdocs/dashboard.py | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 9472325..8d4d5f8 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -1249,20 +1249,31 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context, params):
return
if dashlet_type == "pnpgraph":
- # Context will always be None here, but the graph reference (in params)
- # will contain it. Example:
+ # Context will always be None here, but the graph_specification (in params)
+ # will contain it. Transform the data to the format needed by the dashlets.
+ # Example:
# params = [ 'template', {'service_description': 'CPU load', 'site': 'mysite',
# 'graph_index': 0, 'host_name': 'server123'}])
- graph_info = params[1]
+ graph_specification = params[1]
if params[0] == "template":
context = {
- "host" : graph_info["host_name"]
+ "host" : graph_specification["host_name"]
}
- if graph_info.get("service_description") != "_HOST_":
- context["service"] = graph_info["service_description"]
+ if graph_specification.get("service_description") != "_HOST_":
+ context["service"] = graph_specification["service_description"]
params = {
- "source" : graph_info["graph_index"] + 1
+ "source" : graph_specification["graph_index"] + 1
+ }
+
+ elif params[0] == "custom":
+ # Override the dashlet type here. It would be better to get the
+ # correct dashlet type from the menu. But this does not seem to
+ # be a trivial change.
+ dashlet_type = "custom_graph"
+ context = {}
+ params = {
+ "custom_graph": params[1],
}
@@ -1286,8 +1297,9 @@ def popup_add_dashlet(dashboard_name, dashlet_type, context, params):
# save the original context and override the context provided by the view
context = dashlet['context']
load_view_into_dashlet(dashlet, len(dashboard['dashlets']), view_name, add_context=context)
- elif dashlet_type == "pnpgraph":
- # The "add to visual" popup does not provide a timerang information,
+
+ elif dashlet_type in [ "pnpgraph", "custom_graph" ]:
+ # The "add to visual" popup does not provide a timerange information,
# but this is not an optional value. Set it to 25h initially.
dashlet.setdefault("timerange", "1")
Module: check_mk
Branch: master
Commit: fe8aeafe32f7bdd7d76ee298c37be1a72f7d9d5a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe8aeafe32f7bd…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Feb 3 10:45:02 2016 +0100
When a timeperiod check in Check_MK modules fails now assume active, not inactive
This is e.g. used during notifications. If for any reason the core does not work
during a notification then we better assume that all timeperiods are active so
in this error case users will rather get too many notifications than too few.
---
modules/check_mk_base.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 67c20ac..dcc3d20 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -2283,7 +2283,7 @@ def check_timeperiod(timeperiod):
raise
else:
# If the query is not successful better skip this check then fail
- return False
+ return True
return timeperiod not in g_inactive_timerperiods
Module: check_mk
Branch: master
Commit: 541ec43a88006008d9551a8ff2937020c04ab949
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=541ec43a880060…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Feb 3 10:45:28 2016 +0100
Extracted small Livestatus function for general purpose
---
modules/check_mk_base.py | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index dcc3d20..de317e4 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -2262,6 +2262,24 @@ def camelcase_to_underscored(name):
result += c
return result
+
+# Return plain response from local Livestatus - without any parsing
+def simple_livestatus_query(lql):
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.connect(livestatus_unix_socket)
+ # We just get the currently inactive timeperiods. All others
+ # (also non-existing) are considered to be active
+ s.send(lql)
+ s.shutdown(socket.SHUT_WR)
+ response = ""
+ while True:
+ chunk = s.recv(4096)
+ if not chunk:
+ break
+ response += chunk
+ return response
+
+
# Check if a timeperiod is currently active. We have no other way than
# doing a Livestatus query. This is not really nice, but if you have a better
# idea, please tell me...
@@ -2270,14 +2288,8 @@ def check_timeperiod(timeperiod):
# Let exceptions happen, they will be handled upstream.
if g_inactive_timerperiods == None:
try:
- import socket
- s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- s.connect(livestatus_unix_socket)
- # We just get the currently inactive timeperiods. All others
- # (also non-existing) are considered to be active
- s.send("GET timeperiods\nColumns: name\nFilter: in = 0\n")
- s.shutdown(socket.SHUT_WR)
- g_inactive_timerperiods = s.recv(10000000).splitlines()
+ response = simple_livestatus_query("GET timeperiods\nColumns: name\nFilter: in = 0\n")
+ g_inactive_timerperiods = response.splitlines()
except Exception, e:
if opt_debug:
raise
@@ -2287,6 +2299,7 @@ def check_timeperiod(timeperiod):
return timeperiod not in g_inactive_timerperiods
+
# retrive the service level that applies to the calling check.
def get_effective_service_level():
service_levels = service_extra_conf(g_hostname, g_service_description,