Module: check_mk
Branch: master
Commit: 8d44d13e76c0f9395768104bc3614a70362005fa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8d44d13e76c0f9…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jun 4 17:43:46 2013 +0200
Multisite: enable liveproxyd
---
doc/treasures/liveproxy/liveproxyd | 7 +-
web/htdocs/index.py | 5 ++
web/htdocs/wato.py | 135 +++++++++++++++++++++++++++++-------
web/plugins/config/builtin.py | 3 +
4 files changed, 123 insertions(+), 27 deletions(-)
diff --git a/doc/treasures/liveproxy/liveproxyd b/doc/treasures/liveproxy/liveproxyd
index 2bb98a3..b77d0b7 100755
--- a/doc/treasures/liveproxy/liveproxyd
+++ b/doc/treasures/liveproxy/liveproxyd
@@ -86,7 +86,7 @@ def initiate_connections():
sitestate = g_sites[sitename]
channels = sitestate["channels"]
if len(channels) < siteconf["channels"]:
- if time.time() - sitestate["last_failed_connect"] >=
siteconf["retry"]:
+ if time.time() - sitestate["last_failed_connect"] >=
siteconf["connect_retry"]:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
try:
@@ -693,6 +693,11 @@ def read_configuration():
# Create state object for all sites
for sitename, siteconf in sites.items():
+ siteconf.setdefault("channels", 5)
+ siteconf.setdefault("heartbeat", (5, 2.0))
+ siteconf.setdefault("channel_timeout", 3.0)
+ siteconf.setdefault("query_timeout", 120.0)
+ siteconf.setdefault("connect_retry", 4.0)
g_sites[sitename] = {
"state": "starting",
"channels" : [],
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 763f3c3..f70d908 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -112,6 +112,11 @@ def connect_to_livestatus(html):
for sitename, site in config.allsites().items():
siteconf = config.user_siteconf.get(sitename, {})
+ # Convert livestatus-proxy links into UNIX socket
+ s = site["socket"]
+ if type(s) == tuple and s[0] == "proxy":
+ site["socket"] = "unix:" +
defaults.livestatus_unix_socket + "proxy/" + sitename
+
if siteconf.get("disabled", False):
html.site_status[sitename] = { "state" : "disabled",
"site" : site }
disabled_sites[sitename] = site
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 64f3961..6aed65c 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3780,14 +3780,15 @@ def log_pending(status, linkinfo, what, message):
def cmc_rush_ahead():
if defaults.omd_root:
socket_path = defaults.omd_root + "/tmp/run/cmcrush"
- try:
- changeid = str(random.randint(1, 100000000000000000))
- file(log_dir + "changeid", "w").write(changeid +
"\n")
- socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) \
- .sendto(changeid, socket_path)
- except:
- if config.debug:
- raise
+ if os.path.exists(socket_path):
+ try:
+ changeid = str(random.randint(1, 100000000000000000))
+ file(log_dir + "changeid", "w").write(changeid +
"\n")
+ socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) \
+ .sendto(changeid, socket_path)
+ except:
+ if config.debug:
+ raise
def log_commit_pending():
@@ -6531,7 +6532,11 @@ def mode_sites(phase):
socket = site.get("socket", _("local site"))
if socket == "disabled:":
socket = _("don't query status")
- table.cell(_("Socket"), socket)
+ table.cell(_("Socket"))
+ if type(socket) == tuple and socket[0] == "proxy":
+ html.write(_("Use livestatus Proxy-Daemon"))
+ else:
+ html.write(socket)
# Status host
if "status_host" in site:
@@ -6602,23 +6607,77 @@ def mode_edit_site(phase):
else:
site = sites.get(siteid, {})
+ vs_tcp_port = Tuple(
+ title = _("TCP Port to connect to"),
+ orientation = "float",
+ elements = [
+ TextAscii(label = _("Host:"), allow_empty = False, size=15),
+ Integer(label = _("Port:"), minvalue=1, maxvalue=65535,
default_value=6557),
+ ])
+ conn_choices = [
+ ( None, _("Connect to the local site") ),
+ ( "tcp", _("Connect via TCP"), vs_tcp_port),
+ ( "unix", _("Connect via UNIX socket"), TextAscii(
+ label = _("Path:"),
+ size = 40,
+ allow_empty = False)),
+ ( "disabled", _("Do not connect")),
+ ]
+ if config.liveproxyd_enabled:
+ conn_choices[2:2] = [
+ ( "proxy", _("Use Livestatus Proxy-Daemon"),
+ Dictionary(
+ optional_keys = False,
+ columns = 1,
+ elements = [
+ ( "socket", vs_tcp_port ),
+ ( "channels",
+ Integer(
+ title = _("Number of channels to keep open"),
+ minvalue = 2,
+ maxvalue = 50,
+ default_value = 5)),
+ ( "heartbeat",
+ Tuple(
+ title = _("Regular heartbeat"),
+ orientation = "float",
+ elements = [
+ Integer(label = _("Rate:"),
unit=_("/sec"), minvalue=1, default_value = 5),
+ Float(label = _("Timeout:"),
unit=_("sec"), minvalue=0.1, default_value = 2.0),
+ ])),
+ ( "channel_timeout",
+ Float(
+ title = _("Timeout waiting for a free channel"),
+ minvalue = 0.1,
+ default_value = 3,
+ unit = _("sec"),
+ )
+ ),
+ ( "query_timeout",
+ Float(
+ title = _("Total query timeout"),
+ minvalue = 0.1,
+ unit = _("sec"),
+ default_value = 120,
+ )
+ ),
+ ( "connect_retry",
+ Float(
+ title = _("Wait time after failed connect"),
+ minvalue = 0.1,
+ unit = _("sec"),
+ default_value = 4.0,
+ )),
+ ]
+ )
+ )
+ ]
+
# ValueSpecs for the more complex input fields
vs_conn_method = CascadingDropdown(
html_separator = " ",
- choices = [
- ( None, _("Connect to the local site") ),
- ( "tcp", _("Connect via TCP"), Tuple(
- orientation = "float",
- elements = [
- TextAscii(label = _("Host:"), allow_empty = False,
size=15),
- Integer(label = _("Port:"), minvalue=1, maxvalue=65535,
default_value=6557),
- ])),
- ( "unix", _("Connect via UNIX socket"), TextAscii(
- label = _("Path:"),
- size = 30,
- allow_empty = False)),
- ( "disabled", _("Do not connect")),
- ])
+ choices = conn_choices,
+ )
if phase == "action":
@@ -6657,7 +6716,7 @@ def mode_edit_site(phase):
# Connection
method = vs_conn_method.from_html_vars("method")
vs_conn_method.validate_value(method, "method")
- if type(method) == tuple:
+ if type(method) == tuple and method[0] in [ "unix", "tcp"]:
if method[0] == "unix":
new_site["socket"] = "unix:" + method[1]
else:
@@ -6776,9 +6835,9 @@ def mode_edit_site(phase):
forms.header(_("Livestatus settings"))
forms.section(_("Connection"))
method = site.get("socket", None)
- if method and method.startswith("unix:"):
+ if type(method) == str and method.startswith("unix:"):
method = ('unix', method[5:])
- elif method and method.startswith("tcp:"):
+ elif type(method) == str and method.startswith("tcp:"):
method = ('tcp', tuple(method.split(":")[1:]))
vs_conn_method.render_input("method", method)
@@ -6904,6 +6963,7 @@ def load_sites():
def save_sites(sites):
make_nagios_directory(multisite_dir)
+
# Important: even write out sites if it's empty. The global 'sites'
# variable will otherwise survive in the Python interpreter of the
# Apache processes.
@@ -6916,9 +6976,32 @@ def save_sites(sites):
rewrite_config_files_below(g_root_folder) # fix site attributes
need_sidebar_reload()
+ if config.liveproxyd_enabled:
+ save_liveproxyd_config(sites)
+
# Call the sites saved hook
call_hook_sites_saved(sites)
+def save_liveproxyd_config(sites):
+ path = defaults.default_config_dir + "/liveproxyd.mk"
+ out = create_user_file(path, "w")
+ out.write("# Written by WATO\n# encoding: utf-8\n\n")
+
+ conf = {}
+ for siteid, siteconf in sites.items():
+ s = siteconf.get("socket")
+ if type(s) == tuple and s[0] == "proxy":
+ conf[siteid] = s[1]
+
+ out.write("sites = \\\n%s\n" % pprint.pformat(conf))
+ try:
+ pidfile = defaults.livestatus_unix_socket + "proxyd.pid"
+ pid = int(file(pidfile).read().strip())
+ os.kill(pid, 10)
+ except Exception, e:
+ html.show_error(_("Warning: cannot reload Livestatus Proxy-Daemon: %s"
% e))
+
+
# Makes sure, that in distributed mode we monitor only
# the hosts that are directly assigned to our (the local)
# site.
diff --git a/web/plugins/config/builtin.py b/web/plugins/config/builtin.py
index 8011c12..0cfdaa6 100644
--- a/web/plugins/config/builtin.py
+++ b/web/plugins/config/builtin.py
@@ -123,6 +123,9 @@ debug_livestatus_queries = False
# not reachable.
show_livestatus_errors = True
+# Whether the livestatu proxy daemon is available
+liveproxyd_enabled = False
+
# Set this to a list in order to globally control which views are
# being displayed in the sidebar snapin "Views"
visible_views = None