Module: check_mk
Branch: master
Commit: 81c5fbc77f487eca434dc18037074dae42ebad56
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=81c5fbc77f487e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Apr 11 14:24:57 2013 +0200
FIX: vsphere_agent: fix problems whith ! and \ in username or password
---
ChangeLog | 4 ++++
modules/check_mk.py | 13 +++++++++----
modules/check_mk_base.py | 6 ++----
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 664c7e4..da0864d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -99,6 +99,10 @@
1.2.2p1:
Core:
* FIX: correctly quote ! and \ in active checks for Nagios
+
+ Checks & Agents:
+ * FIX: vsphere_agent: fix problems whith ! and \ in username or password
+
1.2.2:
Core:
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 9fa4c64..6cad5ed 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1584,8 +1584,6 @@ def create_nagios_config(outfile = sys.stdout, hostnames = None):
outfile.write("\n# extra_nagios_conf\n\n")
outfile.write(extra_nagios_conf)
-
-
def create_nagios_config_host(outfile, hostname):
outfile.write("\n#
----------------------------------------------------\n")
outfile.write("# %s\n" % hostname)
@@ -1927,7 +1925,8 @@ define service {
for acttype, act_info, params in actchecks:
has_perfdata = act_info.get('has_perfdata', False)
description = act_info["service_description"](params)
- args = act_info["argument_function"](params)
+ # compute argument, and quote ! and \ for Nagios
+ args =
act_info["argument_function"](params).replace("\\",
"\\\\").replace("!", "\\!")
if description in used_descriptions:
cn, it = used_descriptions[description]
@@ -1987,7 +1986,7 @@ define service {
freshness = " check_freshness\t\t1\n" + \
" freshness_threshold\t\t%d\n" % (60 *
entry["freshness"]["interval"])
command_line = "echo %s && exit %d" % (
-
quote_shell_string(entry["freshness"]["output"]),
entry["freshness"]["state"])
+
quote_nagios_string(entry["freshness"]["output"]),
entry["freshness"]["state"])
else:
freshness = ""
@@ -2213,6 +2212,12 @@ def create_nagios_config_contacts(outfile):
outfile.write("}\n\n")
+# Quote string for use in a nagios command execution.
+# Please note that also quoting for ! and \ vor Nagios
+# itself takes place here.
+def quote_nagios_string(s):
+ return "'" + s.replace('\\',
'\\\\').replace("'",
"'\"'\"'").replace('!', '\\!') +
"'"
+
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index fc3d770..1585a8c 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1462,11 +1462,9 @@ def get_age_human_readable(secs):
return "%d days, %d hours" % (days, hours)
return "%d days" % days
-# Quote string for use as arguments on the shell (for usage
-# in command definitions as $ARG1$). Please note that also
-# quoting for ! and \ vor Nagios itself takes place here.
+# Quote string for use as arguments on the shell
def quote_shell_string(s):
- return "'" + s.replace('\\',
'\\\\').replace("'",
"'\"'\"'").replace('!', '\\!') +
"'"
+ return "'" + s.replace("'",
"'\"'\"'") + "'"
# Check if a timeperiod is currently active. We have no other way than