Module: check_mk
Branch: master
Commit: 26f549dfbb063fce0840213e00ea25ac18ddd200
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=26f549dfbb063f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 14 14:54:15 2012 +0100
FIX: Fixed several problems in OMD apache shared mode
---
.bugs/651 | 8 ++++++++
ChangeLog | 1 +
web/htdocs/lib.py | 19 ++++++++++++++++++-
web/htdocs/login.py | 10 +++++++---
web/htdocs/wato.py | 32 ++++++++++++++++----------------
5 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/.bugs/651 b/.bugs/651
new file mode 100644
index 0000000..e640a22
--- /dev/null
+++ b/.bugs/651
@@ -0,0 +1,8 @@
+Title: WAT tag management needs input fields for secondary tags
+Component: wato
+State: open
+Date: 2012-02-14 11:22:42
+Targetversion: future
+Class: nastiness
+
+Is an important feature to be able to manage the tags in wATo.
diff --git a/ChangeLog b/ChangeLog
index cc75d31..de4f913 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
* Better output in case of inventory error
* FIX: fix bug in host_icon rule on non OMD
* FIX: do not use isdisjoint() (was in rule editor on Lenny)
+ * FIX: Fixed several problems in OMD apache shared mode
Checks & Agents:
* hpux_if: fix missing default parameter errors
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 29736ff..0f07142 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import grp, defaults, pprint, os, gettext, __builtin__
+import grp, defaults, pprint, os, errno, gettext, __builtin__
nagios_state_names = { -1: "NODATA", 0: "OK", 1: "WARNING",
2: "CRITICAL", 3: "UNKNOWN", 4: "DEPENDENT" }
nagios_short_state_names = { -1: "PEND", 0: "OK", 1:
"WARN", 2: "CRIT", 3: "UNKN", 4: "DEP" }
@@ -75,6 +75,23 @@ def make_nagios_directory(path):
"<li>Both Nagios and the web server are in the group
<tt>%s</tt>.</ul>Reason: %s" % (
path, defaults.www_group, defaults.www_group, e))
+# Same as make_nagios_directory but also creates parent directories
+# Logic has been copied from os.makedirs()
+def make_nagios_directories(name):
+ head, tail = os.path.split(name)
+ if not tail:
+ head, tail = os.path.split(head)
+ if head and tail and not os.path.exists(head):
+ try:
+ make_nagios_directories(head)
+ except os.OSError, e:
+ # be happy if someone already created the path
+ if e.errno != errno.EEXIST:
+ raise
+ if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
+ return
+ make_nagios_directory(name)
+
def create_user_file(path, mode):
f = file(path, mode, 0)
gid = grp.getgrnam(defaults.www_group).gr_gid
diff --git a/web/htdocs/login.py b/web/htdocs/login.py
index a1a3f8c..b6ea86d 100644
--- a/web/htdocs/login.py
+++ b/web/htdocs/login.py
@@ -73,11 +73,15 @@ def load_htpasswd():
# FIXME: Secret auch replizieren
def load_secret():
secret_path = '%s/auth.secret' % os.path.dirname(defaults.htpasswd_file)
- if not os.path.exists(secret_path):
+ secret = ''
+ if os.path.exists(secret_path):
+ secret = file(secret_path).read().strip()
+
+ # Create new secret when this installation has no secret
+ if secret == '':
secret = md5.md5(str(time.time())).hexdigest()
file(secret_path, 'w').write(secret)
- else:
- secret = file(secret_path).read().strip()
+
return secret
# Generates the hash to be added into the cookie value
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 49188f9..ccc8780 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -483,7 +483,7 @@ def reload_folder(folder):
# Load the information about all folders - except the hosts
def load_all_folders():
if not os.path.exists(root_dir):
- os.makedirs(root_dir)
+ make_nagios_directories(root_dir)
global g_root_folder, g_folders
g_folders = {}
@@ -599,9 +599,9 @@ def save_hosts(folder = None):
dirname = root_dir + folder_path
filename = dirname + "/hosts.mk"
if not os.path.isdir(dirname):
- os.makedirs(dirname)
+ make_nagios_directories(dirname)
- out = file(filename, "w")
+ out = create_user_file(filename, 'w')
hosts = folder.get(".hosts", [])
if len(hosts) == 0:
@@ -4666,7 +4666,7 @@ def save_configuration_settings(vars):
save_configuration_vars(per_domain.get("multisite", {}), multisite_dir +
"global.mk")
def save_configuration_vars(vars, filename):
- out = file(filename, "w")
+ out = create_user_file(filename, 'w')
out.write("# Written by WATO\n# encoding: utf-8\n\n")
for varname, value in vars.items():
out.write("%s = %r\n" % (varname, value))
@@ -4879,7 +4879,7 @@ def load_group_information():
def save_group_information(groups):
make_nagios_directory(root_dir)
- out = file(root_dir + "groups.mk", "w")
+ out = create_user_file(root_dir + "groups.mk", "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
for what in [ "host", "service", "contact" ]:
if what in groups and len(groups[what]) > 0:
@@ -5016,7 +5016,7 @@ def load_timeperiods():
def save_timeperiods(timeperiods):
make_nagios_directory(root_dir)
- out = file(root_dir + "timeperiods.mk", "w")
+ out = create_user_file(root_dir + "timeperiods.mk", "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("timeperiods.update(%s)\n" % pprint.pformat(timeperiods))
@@ -5851,7 +5851,7 @@ def save_sites(sites):
# Important: even write out sites if it's empty. The global 'sites'
# variable will otherwise survive in the Python interpreter of the
# Apache processes.
- out = file(sites_mk, "w")
+ out = create_user_file(sites_mk, "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("sites = \\\n%s\n" % pprint.pformat(sites))
update_distributed_wato_file(sites)
@@ -6446,7 +6446,7 @@ def automation_push_snapshot():
return _("Internal automation error: %s") % e
def create_distributed_wato_file(siteid, mode):
- out = file(defaults.check_mk_configdir + "/distributed_wato.mk",
"w")
+ out = create_user_file(defaults.check_mk_configdir +
"/distributed_wato.mk", "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("# This file has been created by the master site\n"
"# push the configuration to us. It makes sure that\n"
@@ -6459,7 +6459,7 @@ def delete_distributed_wato_file():
# we do not need write permissions to the conf.d
# directory!
if os.path.exists(p):
- file(p, "w").write("")
+ create_user_file(p, "w").write("")
#.
# .-Users/Contacts-------------------------------------------------------.
@@ -7068,14 +7068,14 @@ def save_users(profiles):
# Check_MK's monitoring contacts
filename = root_dir + "contacts.mk"
- out = file(filename, "w")
+ out = create_user_file(filename, "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("contacts.update(\n%s\n)\n" % pprint.pformat(contacts))
# Users with passwords for Multisite
make_nagios_directory(multisite_dir)
filename = multisite_dir + "users.mk"
- out = file(filename, "w")
+ out = create_user_file(filename, "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("multisite_users = \\\n%s\n" % pprint.pformat(users))
@@ -7085,7 +7085,7 @@ def save_users(profiles):
# WATO, you should continue to do so or stop doing to for ever...
# Locked accounts get a '!' before their password. This disable it.
filename = defaults.htpasswd_file
- out = file(filename, "w")
+ out = create_user_file(filename, "w")
for id, user in profiles.items():
if user.get("password"):
if user.get("locked", False):
@@ -7416,7 +7416,7 @@ def load_roles():
try:
vars = { "roles" : roles }
- execfile(filename, vars, vars)
+ exec(filename, vars, vars)
# Reflect the data in the roles dict kept in the config module Needed
# for instant changes in current page while saving modified roles.
# Otherwise the hooks would work with old data when using helper
@@ -7440,7 +7440,7 @@ def save_roles(roles):
make_nagios_directory(multisite_dir)
filename = multisite_dir + "roles.mk"
- out = file(filename, "w")
+ out = create_user_file(filename, "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("roles.update(\n%s)\n" % pprint.pformat(roles))
@@ -7810,7 +7810,7 @@ def load_hosttags():
def save_hosttags(hosttags):
make_nagios_directory(multisite_dir)
- out = file(multisite_dir + "hosttags.mk", "w")
+ out = create_user_file(multisite_dir + "hosttags.mk", "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
out.write("wato_host_tags += \\\n%s\n" % pprint.pformat(hosttags))
@@ -9029,7 +9029,7 @@ def mode_edit_rule(phase):
def save_rulesets(folder, rulesets):
make_nagios_directory(root_dir)
path = root_dir + '/' + folder['.path'] + '/' +
"rules.mk"
- out = file(path, "w")
+ out = create_user_file(path, "w")
out.write("# Written by WATO\n# encoding: utf-8\n\n")
for varname, rulespec in g_rulespecs.items():