Module: check_mk
Branch: master
Commit: 1eef4bf3e98e6134096a303bb5eb9cd321f57aba
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1eef4bf3e98e61…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 20 11:17:51 2014 +0100
Added mail notificaton method to custom user notification dialog
The user notification dialog (currently accessible via WATO > Users > Notify Users)
has been extended by adding a mail notification mechanism.
---
.werks/665 | 9 ++++++
ChangeLog | 3 +-
web/htdocs/notify.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 94 insertions(+), 5 deletions(-)
diff --git a/.werks/665 b/.werks/665
new file mode 100644
index 0000000..4ff353e
--- /dev/null
+++ b/.werks/665
@@ -0,0 +1,9 @@
+Title: Added mail notificaton method to custom user notification dialog
+Level: 1
+Component: multisite
+Version: 1.2.5i1
+Date: 1390213013
+Class: feature
+
+The user notification dialog (currently accessible via WATO > Users > Notify Users)
+has been extended by adding a mail notification mechanism.
diff --git a/ChangeLog b/ChangeLog
index 1cae374..0c55a9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,8 +46,8 @@
* 0568 f5_big_ip_conns: check now supports predictive monitoring and both connections types are merged in one check
* 0257 windows_agent: now reports extended process information (obsoletes psperf.bat plugin)...
* 0457 hitachi_hnas_volume: New check for Usage and Status of Volumes in Hitachi HNAS storage systems
- * 0458 hitachi_hnas_fc_if: New check for FibreChannel Interfaces in Hitachi HNAS storage systems
* 0450 mem.used: Add information about shared memory (on Linux hosts)
+ * 0458 hitachi_hnas_fc_if: New check for FibreChannel Interfaces in Hitachi HNAS storage systems
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
@@ -122,6 +122,7 @@
* 0429 Implemented role permissions for dashboards...
* 0430 It is now possible to define custom time ranges in PNP graph search...
* 0449 Show all custom variables of hosts and services in the detail views...
+ * 0665 Added mail notificaton method to custom user notification dialog...
* 0302 FIX: Fixed highlight of choosen elements in foldertee/views snapin in Chrome/IE
* 0239 FIX: Fixed incorrect html formatting when displaying host or service comments...
* 0307 FIX: Increased performance of multisite GUI with a large userbase...
diff --git a/web/htdocs/notify.py b/web/htdocs/notify.py
index 061c483..ce85ab0 100644
--- a/web/htdocs/notify.py
+++ b/web/htdocs/notify.py
@@ -84,6 +84,10 @@ def load_plugins():
'title': _('Send hint to message inbox (bottom of sidebar)'),
'handler': notify_gui_msg,
},
+ 'mail': {
+ 'title': _('Send an E-Mail'),
+ 'handler': notify_mail,
+ },
}
dest_choices = [
@@ -197,14 +201,21 @@ def page_notify():
recipients = msg['dest'][1]
num_recipients = len(recipients)
+ num_success = 0
+ num_failed = 0
# Now loop all notitification methods to send the notifications
for user_id in recipients:
for method in msg['methods']:
- handler = notify_methods[method]['handler']
- handler(user_id, msg)
-
- msg = _('The notification has been sent to %d recipients.') % num_recipients
+ try:
+ handler = notify_methods[method]['handler']
+ handler(user_id, msg)
+ num_success += 1
+ except MKInternalError, e:
+ num_failed += 1
+ html.show_error(_('Failed to send %s notification to %s: %s') % (method, user_id, e))
+
+ msg = _('The notification has been sent to %d of %d recipients.') % (num_success, num_recipients)
msg += ' <a href="%s">%s</a>' % (html.makeuri([]), _('Back to previous page'))
msg += '<p>Sent notification to: %s</p>' % ', '.join(recipients)
@@ -227,3 +238,71 @@ def notify_gui_msg(user_id, msg):
if msg not in messages:
messages.append(msg)
save_gui_messages(messages, user_id)
+ return True
+
+
+def notify_mail(user_id, msg):
+ import subprocess, time
+ users = userdb.load_users(lock = False)
+ user = users.get(user_id)
+
+ if not user:
+ raise MKInternalError(_('This user does not exist.'))
+
+ if not user.get('email'):
+ raise MKInternalError(_('This user has no mail address configured.'))
+
+ recipient_name = user.get('alias')
+ if not recipient_name:
+ recipient_name = user_id
+
+ sender_name = users[config.user_id].get('alias')
+ if not sender_name:
+ sender_name = user_id
+
+ # Code mostly taken from notify_via_email() from notify.py module
+ subject = _('Check_MK: Notification')
+ body = _('''Greetings %s,
+
+%s sent you a notification:
+
+---
+%s
+---
+
+''') % (recipient_name, sender_name, msg['text'])
+
+ if msg['valid_till']:
+ body += _('This notification has been created at %s and is valid till %s.') % (
+ time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['time'])),
+ time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['valid_till']))
+ )
+
+ # FIXME: Maybe use the configured mail command for Check_MK-Notify one day
+ command = u"mail -s '$SUBJECT$' '$CONTACTEMAIL$'"
+ command_utf8 = command.replace('$SUBJECT$', subject).replace('$CONTACTEMAIL$', user['email']).encode("utf-8")
+
+ # Make sure that mail(x) is using UTF-8. Otherwise we cannot send notifications
+ # with non-ASCII characters. Unfortunately we do not know whether C.UTF-8 is
+ # available. If e.g. nail detects a non-Ascii character in the mail body and
+ # the specified encoding is not available, it will silently not send the mail!
+ # Our resultion in future: use /usr/sbin/sendmail directly.
+ # Our resultion in the present: look with locale -a for an existing UTF encoding
+ # and use that.
+ for encoding in os.popen("locale -a 2>/dev/null"):
+ l = encoding.lower()
+ if "utf8" in l or "utf-8" in l or "utf.8" in l:
+ encoding = encoding.strip()
+ os.putenv("LANG", encoding)
+ break
+ else:
+ raise MKInternalError(_('No UTF-8 encoding found in your locale -a! Please provide C.UTF-8 encoding.'))
+
+ p = subprocess.Popen(command_utf8, shell=True, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+ stdout_txt, stderr_txt = p.communicate(body.encode("utf-8"))
+ exitcode = p.returncode
+ if exitcode != 0:
+ raise MKInternalError(_('Mail could not be delivered. Exit code of command is %r') % exitcode)
+ else:
+ return True
Module: check_mk
Branch: master
Commit: 34f7ccd8da7079b6dbf563e501b9e9145d1ae988
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=34f7ccd8da7079…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Mon Jan 20 09:56:53 2014 +0100
FIX endless waiting for printer queues fixed
When checking the cups printer queues, the agent execution could take very long
if a machine has many many printers. Fixed this by executing the lpstat command
with a timeout.
---
.werks/460 | 10 ++++++++++
ChangeLog | 1 +
agents/check_mk_agent.linux | 2 +-
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/.werks/460 b/.werks/460
new file mode 100644
index 0000000..6f30bea
--- /dev/null
+++ b/.werks/460
@@ -0,0 +1,10 @@
+Title: endless waiting for printer queues fixed
+Level: 1
+Component: checks
+Version: 1.2.5i1
+Date: 1390207997
+Class: fix
+
+When checking the cups printer queues, the agent execution could take very long
+if a machine has many many printers. Fixed this by executing the lpstat command
+with a timeout.
diff --git a/ChangeLog b/ChangeLog
index 3690dbc..8e1b826 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -117,6 +117,7 @@
* 0567 FIX: apc_symmetra: transformation from old tuple to new dict format fixed and improved
* 0432 FIX: stulz_humidity: Fixed syntax error...
* 0120 FIX: stulz_humidity, apc_humidity: Fixed bug while processing check params...
+ * 0460 FIX: endless waiting for printer queues fixed...
Multisite:
* 0371 Added log class filter to hostsvcevents view
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 25132f5..241d01a 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -369,7 +369,7 @@ if type lpstat > /dev/null 2>&1; then
echo '<<<cups_queues>>>'
WAITMAX="waitmax 3"
CPRINTCONF=/etc/cups/printers.conf
- PRINTERS=$(lpstat -a | awk '{print $1}')
+ PRINTERS=$(waitmax 10 lpstat -a | awk '{print $1}')
if [ -r "$CPRINTCONF" ] ; then
for PQ in $PRINTERS ; do
grep -q -x -E "<(Default)?Printer $PQ>" $CPRINTCONF && $WAITMAX lpstat -p $PQ
Module: check_mk
Branch: master
Commit: e58625e116c21b241b061bf8a8aad4161b42cb6c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e58625e116c21b…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Fri Jan 17 15:30:58 2014 +0100
emcvnx_info: New info check providing Model, Revision and Serial Number of EMC VNX storage systems
---
.werks/459 | 8 ++++
ChangeLog | 1 +
agents/special/agent_emcvnx | 6 ++-
checkman/emcvnx_info | 16 ++++++++
checks/emcvnx_info | 86 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/.werks/459 b/.werks/459
new file mode 100644
index 0000000..1654ff5
--- /dev/null
+++ b/.werks/459
@@ -0,0 +1,8 @@
+Title: emcvnx_info: New info check providing Model, Revision and Serial Number of EMC VNX storage systems
+Level: 2
+Component: checks
+Version: 1.2.5i1
+Date: 1389969007
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 670e51e..3690dbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -51,6 +51,7 @@
* 0457 hitachi_hnas_volume: New check for Usage and Status of Volumes in Hitachi HNAS storage systems
* 0450 mem.used: Add information about shared memory (on Linux hosts)
* 0458 hitachi_hnas_fc_if: New check for FibreChannel Interfaces in Hitachi HNAS storage systems
+ * 0459 emcvnx_info: New info check providing Model, Revision and Serial Number of EMC VNX storage systems
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
diff --git a/agents/special/agent_emcvnx b/agents/special/agent_emcvnx
index b401499..2d5b76f 100755
--- a/agents/special/agent_emcvnx
+++ b/agents/special/agent_emcvnx
@@ -159,12 +159,13 @@ cmd=basecmd + "-sp"
if opt_debug:
sys.stderr.write("executing external command: %s\n" % cmd)
+cmdout = []
for line in os.popen(cmd).readlines():
line = line.strip()
+ cmdout.append(line)
tokens = re.split("\s+", line)
if tokens[0] == "Agent" and tokens[1] == "Rev:":
emcvnx_version = "_".join(tokens[2:])
- break
print "Version: %s" % emcvnx_version
@@ -173,6 +174,9 @@ print "Version: %s" % emcvnx_version
# other commandline argument
#print "AgentOs: %s " % emcvnx_model
+print "<<<emcvnx_info>>>"
+for line in cmdout:
+ print line
#
# all other sections of agent output
diff --git a/checkman/emcvnx_info b/checkman/emcvnx_info
new file mode 100644
index 0000000..d37855e
--- /dev/null
+++ b/checkman/emcvnx_info
@@ -0,0 +1,16 @@
+title: EMC VNX Storage: Info about Model, Revision and Serial Number
+agents: emc
+catalog: hw/storagehw/emc
+license: GPL
+distribution: check_mk
+description:
+ Reports information about Model, Revision and Serial Number on EMC VNX
+ storage systems.
+
+ The check always returns {OK}.
+
+ The information is retriefed by the special agent agent_emcvnx which uses
+ EMC's command line tool naviseccli.
+
+inventory:
+ Finds exactly one check on every EMC VNX storage system called EMC VNX Info
diff --git a/checks/emcvnx_info b/checks/emcvnx_info
new file mode 100644
index 0000000..2f2c295
--- /dev/null
+++ b/checks/emcvnx_info
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 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.
+
+# Example output from agent:
+# <<<emcvnx_info>>>
+#
+#
+# Server IP Address: 10.1.36.13
+# Agent Rev: 7.32.25 (1.56)
+#
+#
+# Agent/Host Information
+# -----------------------
+#
+#
+#
+# Agent Rev: 7.32.25 (1.56)
+# Name: K10
+# Desc:
+# Node: A-CKM00114701225
+# Physical Node: K10
+# Signature: 3195192
+# Peer Signature: 3187006
+# Revision: 05.32.000.5.201
+# SCSI Id: 0
+# Model: VNX5300
+# Model Type: Rackmount
+# Prom Rev: 7.00.00
+# SP Memory: 8192
+# Serial No: CKM00114701225
+# SP Identifier: A
+# Cabinet: DPE7
+#
+# Name of the software package: -Compression
+# Revision of the software package: -
+# Commit Required: NO
+# Revert Possible: NO
+# Active State: YES
+# Is installation completed: YES
+# Is this System Software: NO
+#
+# [... more software packages follow ...]
+
+
+def inventory_emcvnx_info(info):
+ return [ (None, None) ]
+
+
+def check_emcvnx_info(item, _no_params, info):
+ message = ""
+ for line in info:
+ if len(line) > 1 and line[0] in ("Revision:", "Model:", "Serial"):
+ if message != "":
+ message += ", "
+ message += " ".join(line)
+ return 0, message
+
+
+check_info['emcvnx_info'] = {
+ "inventory_function" : inventory_emcvnx_info,
+ "check_function" : check_emcvnx_info,
+ "service_description" : "EMC VNX Info"
+}
Module: check_mk
Branch: master
Commit: e9abe4a2c7b1a83169a320b1d9a2370e66d24add
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e9abe4a2c7b1a8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 17 12:54:08 2014 +0100
Speedup generation of configuration
The configuration generation for the core (Nagios/CMC) in large setups has been
sped up. This hold especially for situations with many rules and/or many
cluster definitions.
---
.werks/452 | 11 ++++
ChangeLog | 1 +
modules/check_mk.py | 142 +++++++++++++++++++++++++++++++++-------------
modules/check_mk_base.py | 8 +++
4 files changed, 121 insertions(+), 41 deletions(-)
diff --git a/.werks/452 b/.werks/452
new file mode 100644
index 0000000..3ce24ba
--- /dev/null
+++ b/.werks/452
@@ -0,0 +1,11 @@
+Title: Speedup generation of configuration
+Level: 2
+Component: core
+Class: feature
+State: unknown
+Version: 1.2.5i1
+Date: 1389959599
+
+The configuration generation for the core (Nagios/CMC) in large setups has been
+sped up. This hold especially for situations with many rules and/or many
+cluster definitions.
diff --git a/ChangeLog b/ChangeLog
index d127589..fc4488c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
1.2.5i1:
Core & Setup:
* 0386 Added all active checks to check_mk -L output...
+ * 0452 Speedup generation of configuration...
* 0087 FIX: Fixed possible locking issue when using datasource program with long output...
* 0313 FIX: Avoid duplicate reading of configuration file on --create-rrd...
* 0379 FIX: check_mk -c: Now also rewrites the location of conf.d directory
diff --git a/modules/check_mk.py b/modules/check_mk.py
index defccfe..0c03c6a 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1692,29 +1692,116 @@ def get_rule_options(entry):
return entry, {}
-# Compute list of service_groups or contact_groups of service
-# conf is either service_groups or service_contactgroups
-def service_extra_conf(hostname, service, conf):
- entries = []
- for entry in conf:
- entry, rule_options = get_rule_options(entry)
+def all_matching_hosts(tags, hostlist):
+ matching = set([])
+ for taggedhost in all_hosts + clusters.keys():
+ parts = taggedhost.split("|")
+ hostname = parts[0]
+ hosttags = parts[1:]
+
+ if hosttags_match_taglist(hosttags, tags) and \
+ in_extraconf_hostlist(hostlist, hostname):
+ matching.add(hostname)
+ return matching
+
+
+def convert_service_ruleset(ruleset):
+ new_rules = []
+ for rule in ruleset:
+ rule, rule_options = get_rule_options(rule) # Das könnte man einmal umbauen und so lassen (8 sec von 137)
if rule_options.get("disabled"):
continue
- if len(entry) == 3:
- item, hostlist, servlist = entry
+ if len(rule) == 3:
+ item, hostlist, servlist = rule
tags = []
- elif len(entry) == 4:
- item, tags, hostlist, servlist = entry
+ elif len(rule) == 4:
+ item, tags, hostlist, servlist = rule
else:
- raise MKGeneralException("Invalid entry '%r' in service configuration list: must have 3 or 4 elements" % (entry,))
+ raise MKGeneralException("Invalid rule '%r' in service configuration list: must have 3 or 4 elements" % (rule,))
- if hosttags_match_taglist(tags_of_host(hostname), tags) and \
- in_extraconf_hostlist(hostlist, hostname) and \
- in_extraconf_servicelist(servlist, service):
+ # Directly compute set of all matching hosts here, this
+ # will avoid recomputation later
+ hosts = all_matching_hosts(tags, hostlist)
+ new_rules.append((item, hosts, servlist))
+
+ # Replace rules inplace. This finally modifies it, so we
+ # need this conversion only once
+ ruleset[:] = new_rules
+
+def serviceruleset_is_converted(ruleset):
+ if not ruleset:
+ return True # empty rulesets are converted in a trivial way
+
+ if type(ruleset[0]) != tuple:
+ return False
+
+ return type(ruleset[0][1]) == set
+
+
+# Compute outcome of a service rule set that has an item
+def service_extra_conf(hostname, service, ruleset):
+ if not serviceruleset_is_converted(ruleset):
+ convert_service_ruleset(ruleset)
+
+ entries = []
+ for item, hosts, servlist in ruleset:
+ if hostname in hosts and in_extraconf_servicelist(servlist, service):
entries.append(item)
return entries
+def convert_boolean_service_ruleset(ruleset):
+ new_rules = []
+ for rule in ruleset:
+ entry, rule_options = get_rule_options(rule)
+ if rule_options.get("disabled"):
+ continue
+
+ if entry[0] == NEGATE: # this entry is logically negated
+ negate = True
+ entry = entry[1:]
+ else:
+ negate = False
+
+ if len(entry) == 2:
+ hostlist, servlist = entry
+ tags = []
+ elif len(entry) == 3:
+ tags, hostlist, servlist = entry
+ else:
+ raise MKGeneralException("Invalid entry '%r' in configuration: must have 2 or 3 elements" % (entry,))
+
+ # Directly compute set of all matching hosts here, this
+ # will avoid recomputation later
+ hosts = all_matching_hosts(tags, hostlist)
+ new_rules.append((negate, hosts, servlist))
+
+ # Replace rules inplace. This finally modifies it, so we
+ # need this conversion only once
+ ruleset[:] = new_rules
+
+
+def boolean_serviceruleset_is_converted(ruleset):
+ if not ruleset:
+ return True # empty rulesets are converted in a trivial way
+
+ if type(ruleset[0]) != tuple:
+ return False
+
+ return type(ruleset[0][1]) == set
+
+
+# Compute outcome of a service rule set that just say yes/no
+def in_boolean_serviceconf_list(hostname, service_description, ruleset):
+ if not boolean_serviceruleset_is_converted(ruleset):
+ convert_boolean_service_ruleset(ruleset)
+
+ for negate, hosts, servlist in ruleset:
+ if hostname in hosts and \
+ in_extraconf_servicelist(servlist, service_description):
+ return not negate
+ return False # no match. Do not ignore
+
# Entries in list are (tagged) hostnames that must equal the
@@ -2874,33 +2961,6 @@ def service_ignored(hostname, checktype, service_description):
return False
-def in_boolean_serviceconf_list(hostname, service_description, conflist):
- for entry in conflist:
- entry, rule_options = get_rule_options(entry)
- if rule_options.get("disabled"):
- continue
-
- if entry[0] == NEGATE: # this entry is logically negated
- negate = True
- entry = entry[1:]
- else:
- negate = False
-
- if len(entry) == 2:
- hostlist, servlist = entry
- tags = []
- elif len(entry) == 3:
- tags, hostlist, servlist = entry
- else:
- raise MKGeneralException("Invalid entry '%r' in configuration: must have 2 or 3 elements" % (entry,))
-
- if hosttags_match_taglist(tags_of_host(hostname), tags) and \
- in_extraconf_hostlist(hostlist, hostname) and \
- in_extraconf_servicelist(servlist, service_description):
- return not negate
- return False # no match. Do not ignore
-
-
# Remove all autochecks of certain types of a certain host
def remove_autochecks_of(hostname, checktypes = None): # None = all
removed = 0
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 196371a..c2522d0 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1347,10 +1347,18 @@ def i_am_root():
# Returns the nodes of a cluster, or None if hostname is
# not a cluster
+g_nodesof_cache = {}
def nodes_of(hostname):
+ nodes = g_nodesof_cache.get(hostname, False)
+ if nodes != False:
+ return nodes
+
for tagged_hostname, nodes in clusters.items():
if hostname == tagged_hostname.split("|")[0]:
+ g_nodesof_cache[hostname] = nodes
return nodes
+
+ g_nodesof_cache[hostname] = None
return None
def pnp_cleanup(s):
Module: check_mk
Branch: master
Commit: ad157aaa1c38ccc5ac9a1419632eee14fad23cbb
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ad157aaa1c38cc…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Jan 17 12:11:53 2014 +0100
FIX Fixed htpasswd permission problem in check_mk standalone installation
In a standalone installation the path <tt>/usr/local/nagios/etc</tt> is not writable by the apache user.<br>
The user management module tried to create a file <tt>/usr/local/nagios/etc/htpasswd.new</tt> and rename it to
<tt>/usr/local/nagios/etc/htpasswd</tt> afterwards -> failed<br>
The workaround is that no <tt>htpasswd.new</tt> file will be created on standalone installations.
The user management module now directly writes in <tt>htpasswd</tt>.
---
.werks/259 | 12 ++++++++++++
ChangeLog | 1 +
web/plugins/userdb/htpasswd.py | 11 +++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/.werks/259 b/.werks/259
new file mode 100644
index 0000000..1bedbd1
--- /dev/null
+++ b/.werks/259
@@ -0,0 +1,12 @@
+Title: Fixed htpasswd permission problem in check_mk standalone installation
+Level: 1
+Component: core
+Version: 1.2.5i1
+Date: 1389956512
+Class: fix
+
+In a standalone installation the path <tt>/usr/local/nagios/etc</tt> is not writable by the apache user.<br>
+The user management module tried to create a file <tt>/usr/local/nagios/etc/htpasswd.new</tt> and rename it to
+<tt>/usr/local/nagios/etc/htpasswd</tt> afterwards -> failed<br>
+The workaround is that no <tt>htpasswd.new</tt> file will be created on standalone installations.
+The user management module now directly writes in <tt>htpasswd</tt>.
diff --git a/ChangeLog b/ChangeLog
index d127589..ed3339b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
* 0402 FIX: Fix exception in case of missing agent sections of cluster-aware checks...
* 0426 FIX: Fixed processing of cached agent plugins / local scripts...
* 0451 FIX: Ignore missing check types when creating configuration for Nagios
+ * 0259 FIX: Fixed htpasswd permission problem in check_mk standalone installation...
Checks & Agents:
* 0306 esx_vsphere_counters: added missing ramdisk levels sfcbtickets
diff --git a/web/plugins/userdb/htpasswd.py b/web/plugins/userdb/htpasswd.py
index 883e3f1..0839394 100644
--- a/web/plugins/userdb/htpasswd.py
+++ b/web/plugins/userdb/htpasswd.py
@@ -108,7 +108,13 @@ def htpasswd_save(users):
# 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 + '.new'
- out = create_user_file(filename, "w")
+ rename_file = True
+ try:
+ out = create_user_file(filename, "w")
+ except:
+ rename_file = False
+ out = create_user_file(defaults.htpasswd_file, "w")
+
for id, user in users.items():
# only process users which are handled by htpasswd connector
if user.get('connector', 'htpasswd') != 'htpasswd':
@@ -121,7 +127,8 @@ def htpasswd_save(users):
locksym = ""
out.write("%s:%s%s\n" % (id, locksym, user["password"]))
out.close()
- os.rename(filename, filename[:-4])
+ if rename_file:
+ os.rename(filename, filename[:-4])
multisite_user_connectors.append({
'id': 'htpasswd',