Module: check_mk
Branch: master
Commit: 48f3ebd485ade37275f7a0d514f203e482a408dc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=48f3ebd485ade3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 16 18:48:52 2018 +0100
Moved pnp_cleanup() to cmk.utils
Change-Id: I47977771bf42db7e51581085229bd83c46ea32a7
---
cmk/utils.py | 10 ++++++++++
cmk_base/prediction.py | 11 ++---------
web/htdocs/lib.py | 8 --------
web/htdocs/metrics.py | 10 +++++-----
web/htdocs/prediction.py | 5 ++++-
web/plugins/icons/builtin.py | 6 ++++--
6 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/cmk/utils.py b/cmk/utils.py
index 9baf269..2918bf2 100644
--- a/cmk/utils.py
+++ b/cmk/utils.py
@@ -39,3 +39,13 @@ def make_utf8(x):
def quote_shell_string(s):
"""Quote string for use as arguments on the shell"""
return "'" + s.replace("'",
"'\"'\"'") + "'"
+
+
+# TODO: Change to better name like: quote_pnp_string()
+def pnp_cleanup(s):
+ """Quote a string (host name or service description) in PNP4Nagios
format"""
+ return s \
+ .replace(' ', '_') \
+ .replace(':', '_') \
+ .replace('/', '_') \
+ .replace('\\', '_')
diff --git a/cmk_base/prediction.py b/cmk_base/prediction.py
index be6bc7a..ee57d51 100644
--- a/cmk_base/prediction.py
+++ b/cmk_base/prediction.py
@@ -35,6 +35,7 @@ import livestatus
import cmk.paths
import cmk.debug
+import cmk.utils
from cmk.exceptions import MKGeneralException
@@ -219,7 +220,7 @@ def get_levels(hostname, service_description, dsname, params, cf,
levels_factor=
# Compute directory for prediction data
dir = "%s/prediction/%s/%s/%s" % (cmk.paths.var_dir, hostname,
- pnp_cleanup(service_description), pnp_cleanup(dsname))
+ cmk.utils.pnp_cleanup(service_description), cmk.utils.pnp_cleanup(dsname))
if not os.path.exists(dir):
os.makedirs(dir)
@@ -320,11 +321,3 @@ def get_levels(hostname, service_description, dsname, params, cf,
levels_factor=
levels.append((None, None))
return ref_value, levels
-
-
-def pnp_cleanup(s):
- return s \
- .replace(' ', '_') \
- .replace(':', '_') \
- .replace('/', '_') \
- .replace('\\', '_')
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 9118a5f..e1a1c0c 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -120,14 +120,6 @@ def local_web_plugins_have_changed():
return have_changed
-def pnp_cleanup(s):
- return s \
- .replace(' ', '_') \
- .replace(':', '_') \
- .replace('/', '_') \
- .replace('\\', '_')
-
-
def log_exception(msg=None):
if msg is None:
msg = _('Internal error')
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 6d74088..3480381 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -565,7 +565,7 @@ def parse_perf_data(perf_data_string, check_command=None):
for part in parts:
try:
varname, values = part.split("=", 1)
- varname = pnp_cleanup(varname.replace("\"",
"").replace("\'", ""))
+ varname = cmk.utils.pnp_cleanup(varname.replace("\"",
"").replace("\'", ""))
value_parts = values.split(";")
while len(value_parts) < 5:
@@ -1703,8 +1703,8 @@ def page_host_service_graph_popup():
def host_service_graph_popup_pnp(site, host_name, service_description):
- pnp_host = pnp_cleanup(host_name)
- pnp_svc = pnp_cleanup(service_description)
+ pnp_host = cmk.utils.pnp_cleanup(host_name)
+ pnp_svc = cmk.utils.pnp_cleanup(service_description)
url_prefix = config.site(site)["url_prefix"]
if html.mobile:
@@ -1821,8 +1821,8 @@ def host_service_graph_dashlet_pnp(graph_identification):
site = graph_identification[1]["site"]
source = int(graph_identification[1]["graph_index"])
- pnp_host = pnp_cleanup(graph_identification[1]["host_name"])
- pnp_svc = pnp_cleanup(graph_identification[1]["service_description"])
+ pnp_host = cmk.utils.pnp_cleanup(graph_identification[1]["host_name"])
+ pnp_svc =
cmk.utils.pnp_cleanup(graph_identification[1]["service_description"])
url_prefix = config.site(site)["url_prefix"]
html.write(url_prefix +
"pnp4nagios/index.php/image?host=%s&srv=%s&source=%d&view=%s&theme=multisite"
% \
diff --git a/web/htdocs/prediction.py b/web/htdocs/prediction.py
index 74744ac..6fadc5e 100644
--- a/web/htdocs/prediction.py
+++ b/web/htdocs/prediction.py
@@ -34,6 +34,7 @@ import sites
import livestatus
from lib import *
from gui_exceptions import MKGeneralException
+import cmk.utils
import cmk.store as store
@@ -54,7 +55,9 @@ def page_graph():
current_value = get_current_perfdata(host, service, dsname)
dir = "%s/prediction/%s/%s/%s" % (
- cmk.paths.var_dir, host, pnp_cleanup(service), pnp_cleanup(dsname))
+ cmk.paths.var_dir, host,
+ cmk.utils.pnp_cleanup(service),
+ cmk.utils.pnp_cleanup(dsname))
if not os.path.exists(dir):
raise MKGeneralException(_("There is currently no prediction information
"
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index ab96cdd..c7ab694 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -57,6 +57,8 @@
# 'paint': paint_icon_image,
#})
+import cmk.utils
+
# .--Action Menu---------------------------------------------------------.
# | _ _ _ __ __ |
# | / \ ___| |_(_) ___ _ __ | \/ | ___ _ __ _ _ |
@@ -280,11 +282,11 @@ multisite_icons_and_actions['status_acknowledged'] = {
# Intelligent Links to PNP4Nagios 0.6.X
def pnp_url(row, what, how = 'graph'):
sitename = row["site"]
- host = pnp_cleanup(row["host_name"])
+ host = cmk.utils.pnp_cleanup(row["host_name"])
if what == "host":
svc = "_HOST_"
else:
- svc = pnp_cleanup(row["service_description"])
+ svc = cmk.utils.pnp_cleanup(row["service_description"])
url_prefix = config.site(sitename)["url_prefix"]
if html.mobile:
url = url_prefix + ("pnp4nagios/index.php?kohana_uri=/mobile/%s/%s/%s"
% \