Module: check_mk
Branch: master
Commit: 4bb8ab0e91403436b2d113d2c1599708961b3f00
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4bb8ab0e914034…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun May 6 19:51:46 2012 +0200
FIX: fix remote inventory with hosts with >2k services
---
ChangeLog | 2 ++
web/htdocs/config.py | 2 +-
web/htdocs/wato.py | 24 ++++++++++++++----------
web/plugins/wato/auth.py | 2 ++
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 974a60e..964da72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@
* FIX: detect non-local site even if unix: is being used
* FIX: better error message if not logged into site during
action that needs remote access
+ * FIX: send automation data via POST not GET. This fixes inventory
+ on hosts with up to 2000 services
Multisite:
* FIX: fixed filter of recent event views (4 hours didn't catch)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 39767b7..82fd60e 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -441,7 +441,7 @@ def site(name):
def site_is_local(name):
s = sites.get(name, {})
sock = s.get("socket")
- return not sock or sock == defaults.livestatus_unix_socket
+ return not sock or sock == "unix:" + defaults.livestatus_unix_socket
def is_multisite():
if len(sites) > 1:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 5bbec4e..2f9511f 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2963,8 +2963,6 @@ def configure_gateway(state, site_id, folder, host, effective,
gateway):
gwcreat = False
if gateway:
- if len(gateway) != 3:
- raise Exception("Gateway ist %r" % (gateway,))
gw_host, gw_ip, dns_name = gateway
if not gw_host:
if where == "nowhere":
@@ -3853,7 +3851,6 @@ def check_mk_local_automation(command, args=[],
indata=""):
html.show_error("<h3>Cannot activate changes</h3>%s" %
e)
return
-
if config.debug:
log_audit(None, "automation", "Automation: %s" % "
".join(cmd))
try:
@@ -3878,6 +3875,7 @@ def check_mk_local_automation(command, args=[],
indata=""):
raise MKGeneralException("Error running <tt>%s</tt> (exit code
%d): <pre>%s</pre>%s" %
(" ".join(cmd), exitcode, hilite_errors(outdata),
outdata.lstrip().startswith('sudo:') and sudo_msg or ''))
+
# On successful "restart" command execute the activate changes hook
if command == 'restart':
call_hook_activate_changes()
@@ -6649,7 +6647,7 @@ def do_site_login(site_id, name, password):
def upload_file(url, file_path, insecure):
return get_url(url, insecure, params = ' -F snapshot=@%s' % file_path)
-def get_url(url, insecure, user=None, password=None, params = ''):
+def get_url(url, insecure, user=None, password=None, params = '', post_data =
None):
cred = ''
if user:
cred = ' -u "%s:%s"' % (user, password)
@@ -6659,7 +6657,10 @@ def get_url(url, insecure, user=None, password=None, params =
''):
# -s: silent
# -S: show errors
# -w '%{http_code}': add the http status code to the end of the output
- response = os.popen('curl -w "\n%%{http_code}" -s -S%s%s%s
"%s" 2>&1' % (insecure, cred, params, url)).read().strip()
+ command = 'curl -w "\n%%{http_code}" -s -S%s%s%s "%s"
2>&1' % (insecure, cred, params, url)
+ if post_data != None:
+ command += ' --data-binary "%s"' % post_data
+ response = os.popen(command).read().strip()
try:
status_code = int(response[-3:])
response_body = response[:-3]
@@ -6705,8 +6706,10 @@ def do_remote_automation(site, command, vars):
("command", command),
("secret", secret),
("debug", config.debug and '1' or '')
- ] + vars)
- response = get_url(url, site.get('insecure', False))
+ ])
+ vars_encoded = htmllib.urlencode_vars(vars)
+ response = get_url(url, site.get('insecure', False),
+ post_data=vars_encoded)
if not response:
raise MKAutomationException("Empty output from remote site.")
try:
@@ -7124,6 +7127,9 @@ def page_automation():
if secret != get_login_secret():
raise MKAuthException(_("Invalid automation secret."))
+ # Initialise g_root_folder, load all folder information
+ prepare_folder_info()
+
command = html.var("command")
if command == "checkmk-automation":
cmk_command = html.var("automation")
@@ -7138,9 +7144,6 @@ def page_automation():
def automation_push_snapshot():
try:
- # Initialise g_root_folder, load all folder information
- prepare_folder_info()
-
site_id = html.var("siteid")
if not site_id:
raise MKGeneralException(_("Missing variable siteid"))
@@ -11001,6 +11004,7 @@ def call_hook_pre_activate_changes():
# the hosts as values.
def call_hook_activate_changes():
if hook_registered('activate-changes'):
+ hosts = collect_hosts(g_root_folder)
call_hooks("activate-changes", collect_hosts(g_root_folder))
# This hook is executed when the save_users() function is called
diff --git a/web/plugins/wato/auth.py b/web/plugins/wato/auth.py
index 19e1a02..5a0e450 100644
--- a/web/plugins/wato/auth.py
+++ b/web/plugins/wato/auth.py
@@ -189,4 +189,6 @@ def create_auth_file(users):
api.register_hook('users-saved', create_auth_file)
api.register_hook('roles-saved', lambda x: create_auth_file(load_users()))
+# TODO: optimize: This hook does not use the list of the collected
+# hosts. And collicting the hosts is a lengthy operation.
api.register_hook('activate-changes', lambda x: create_auth_file(load_users()))