Module: check_mk
Branch: master
Commit: a6829d50417692b6934fd15a2ae61005eab0e0a8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a6829d50417692…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Dec 22 15:49:25 2015 +0100
GUI-Tests: new page for scheduling all checks and waiting for the results
---
web/htdocs/guitester.py | 44 ++++++++++++++++++++++++++++++++++++++++
web/htdocs/html_mod_python.py | 1 +
web/htdocs/wato.py | 3 +++
web/plugins/pages/guitester.py | 31 ++++++++++++++++++++++++++++
4 files changed, 79 insertions(+)
diff --git a/web/htdocs/guitester.py b/web/htdocs/guitester.py
index 1d93788..5a31050 100644
--- a/web/htdocs/guitester.py
+++ b/web/htdocs/guitester.py
@@ -25,6 +25,9 @@
# Boston, MA 02110-1301 USA.
import re
+import time
+
+import config
import defaults
from lib import *
@@ -311,3 +314,44 @@ def guitest_drop_dynamic_ids_in_text(text):
text = re.sub(year_regex, "YEAR", text)
text = re.sub(english_date_regex, "DATE", text)
return text
+
+
+def pending_hosts():
+ html.live.set_prepend_site(True)
+ hosts = html.live.query("GET hosts\nFilter: has_been_checked = 0\nColumns:
name")
+ html.live.set_prepend_site(False)
+ return hosts
+
+
+def pending_active_services():
+ html.live.set_prepend_site(True)
+ services = html.live.query("GET services\nFilter: has_been_checked = 0\nFilter:
check_type = 0\nColumns: host_name description")
+ html.live.set_prepend_site(False)
+ entries = [ (site, "%s;%s" % (host_name, service_description))
+ for (site, host_name, service_description) in services ]
+ return entries
+
+
+def page_reschedule_all():
+ if not config.guitests_enabled:
+ raise MKAuthException(_("GUI Tests are disabled."))
+
+ html.header(_("Rescheduling and waiting for check results"),
stylesheets=["status", "pages"])
+ wait_for_pending("host", pending_hosts, 10)
+ wait_for_pending("service", pending_active_services, 50)
+ html.footer()
+
+
+def wait_for_pending(what, generator_function, tries):
+ for try_number in range(tries):
+ entries = generator_function()
+ if not entries:
+ html.message("All %ss are checked.\n" % what)
+ break
+ for site, entry in entries:
+ html.live.command("[1231231233] SCHEDULE_FORCED_%s_CHECK;%s;%d" %
(what.upper(), entry, time.time()), sitename = site)
+ time.sleep(0.5)
+
+ else:
+ html.message("Reschedule failed after %d tries. Still pending %ss:
%s\n" % (tries, what, ", ".join([e[1] for e in entries])))
+
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index 6b14d19..a646b36 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -350,6 +350,7 @@ def connect_to_livestatus():
enabled_sites = {}
disabled_sites = {}
+
for sitename, site in config.allsites().items():
siteconf = config.user_siteconf.get(sitename, {})
# Convert livestatus-proxy links into UNIX socket
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 14202cc..d70f8a1 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3955,6 +3955,9 @@ def mode_changelog(phase):
if config.may("wato.auditlog"):
html.context_button(_("Audit Log"),
folder_preserving_link([("mode", "auditlog")]), "auditlog")
+ if config.guitests_enabled:
+ html.context_button(_("Reschedule All"),
"guitest_reschedule_all.py", "guitest")
+
elif phase == "action":
action = html.var("_action", html.var("_siteaction"))
if action == "activate":
diff --git a/web/plugins/pages/guitester.py b/web/plugins/pages/guitester.py
new file mode 100644
index 0000000..a7693ed
--- /dev/null
+++ b/web/plugins/pages/guitester.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+import guitester
+
+pagehandlers.update({
+ "guitest_reschedule_all" : guitester.page_reschedule_all,
+})