Module: check_mk
Branch: master
Commit: 9d89383e6d5998e291ab18e65e7d17271a715ec6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9d89383e6d5998…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Aug 17 14:25:28 2011 +0200
Remove leading/trailing spaces from service description
---
ChangeLog | 2 ++
modules/check_mk.py | 11 ++++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2b4e501..6973784 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
1.1.11i2:
Core, Setup, etc.:
* FIX: sort output of cmk --list-hosts alphabetically
+ * FIX: automatically remove leading and trailing space from service names
+ (this fixes a problem with printer_pages and an empty item)
* Great speed up of cmk -N/-C/-U/-R, especially when number of hosts is
large.
* new main.mk option delay_precompile: if True, check_mk will skip Python
diff --git a/modules/check_mk.py b/modules/check_mk.py
index cacaede..b0af17b 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1012,18 +1012,23 @@ def service_description(checkname, item):
if not descr_format:
descr_format = check_info[checkname][1]
+ # Note: we strip the service description (remove spaces).
+ # One check defines "Pages %s" as a desription, but the item
+ # can by empty in some cases. Nagios silently drops leading
+ # and trailing spaces in the configuration file.
+
if type(item) == str:
# Remove characters from item name that are banned by Nagios
item_safe = "".join([ c for c in item if c not in nagios_illegal_chars
])
if "%s" not in descr_format:
descr_format += " %s"
- return descr_format % (item_safe,)
+ return (descr_format % (item_safe,)).strip()
if type(item) == int or type(item) == long:
if "%s" not in descr_format:
descr_format += " %s"
- return descr_format % (item,)
+ return (descr_format % (item,)).strip()
else:
- return descr_format
+ return descr_format.strip()
# +----------------------------------------------------------------------+
# | ____ __ _ _ _ |