Module: check_mk
Branch: master
Commit: a4e8c87b5a4dd91964bb9e2699286fecdab48472
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a4e8c87b5a4dd9…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Apr 5 12:12:04 2019 +0200
7393 FIX mongodb_collections: New WATO rule and fixed output
The storage size is no longer wrongly treated as total available space,
which led to a {CRIT} state.
Users who had a rule configured for Mongo DB collections need to set
up a new one.
CMK-1885
Change-Id: I9333cc75e8151aca4dde7a06df8689a4c441a50c
---
.werks/7393 | 13 +++
checks/mongodb_collections | 25 ++---
.../wato/check_parameters/mongodb_collections.py | 26 ++---
.../generictests/datasets/mongodb_collections_1.py | 107 ++++-----------------
4 files changed, 63 insertions(+), 108 deletions(-)
diff --git a/.werks/7393 b/.werks/7393
new file mode 100644
index 0000000..20021f5
--- /dev/null
+++ b/.werks/7393
@@ -0,0 +1,13 @@
+Title: mongodb_collections: New WATO rule and fixed output
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.6.0i1
+Date: 1554458898
+Class: fix
+
+The storage size is no longer wrongly treated as total available space,
+which led to a {CRIT} state.
+Users who had a rule configured for Mongo DB collections need to set
+up a new one.
diff --git a/checks/mongodb_collections b/checks/mongodb_collections
index 5c5208c..d425c08 100644
--- a/checks/mongodb_collections
+++ b/checks/mongodb_collections
@@ -52,14 +52,19 @@ def parse_mongodb_collections(info):
return parsed
-def check_mongodb_collections(item, params, parsed):
- fslist_blocks = []
- for coll_item, values in parsed.items():
- used_mb = values["size"] / 1024.0**2
- total_mb = values["storageSize"] / 1024.0**2
- fslist_blocks.append((coll_item, total_mb, total_mb - used_mb, 0))
-
- return df_check_filesystem_list(item, params, fslist_blocks)
+@get_parsed_item_data
+def check_mongodb_collections(_no_item, params, data):
+ for key, label in (
+ ("size", "Uncompressed size in memory"),
+ ("storageSize", "Allocated for document storage"),
+ ):
+ if key not in data:
+ continue
+ levels = params.get("levels_%s" % key.lower())
+ if levels is not None:
+ levels = (levels[0] * 1024**2, levels[1] * 1024**2)
+ yield check_levels(
+ data[key], None, levels, human_readable_func=get_bytes_human_readable,
infoname=label)
check_info["mongodb_collections"] = {
@@ -68,7 +73,5 @@ check_info["mongodb_collections"] = {
"check_function": check_mongodb_collections,
"service_description": "MongoDB Collection %s",
"group": "mongodb_collections",
- "default_levels_variable": "filesystem_default_levels",
- "includes": ["size_trend.include", "df.include"],
- "has_perfdata": True,
+ "has_perfdata": False,
}
diff --git a/cmk/gui/plugins/wato/check_parameters/mongodb_collections.py
b/cmk/gui/plugins/wato/check_parameters/mongodb_collections.py
index b805c30..dbe2502 100644
--- a/cmk/gui/plugins/wato/check_parameters/mongodb_collections.py
+++ b/cmk/gui/plugins/wato/check_parameters/mongodb_collections.py
@@ -25,19 +25,12 @@
# Boston, MA 02110-1301 USA.
from cmk.gui.i18n import _
-from cmk.gui.valuespec import (
- Dictionary,
- TextAscii,
-)
from cmk.gui.plugins.wato import (
- RulespecGroupCheckParametersStorage,
CheckParameterRulespecWithItem,
+ RulespecGroupCheckParametersStorage,
rulespec_registry,
)
-from cmk.gui.plugins.wato.check_parameters.utils import (
- fs_levels_elements,
- size_trend_elements,
-)
+from cmk.gui.valuespec import Dictionary, Integer, TextAscii, Tuple
@rulespec_registry.register
@@ -60,8 +53,19 @@ class
RulespecCheckgroupParametersMongodbCollections(CheckParameterRulespecWithI
@property
def parameter_valuespec(self):
- return Dictionary(elements=fs_levels_elements + size_trend_elements)
+ return Dictionary(elements=[
+ ("levels_size", self._size_tuple("Uncompressed size in
memory", "above")),
+ ("levels_storagesize", self._size_tuple("Allocated for
document storage", "above")),
+ ])
+
+ def _size_tuple(self, title, course):
+ return Tuple(
+ title=_(title),
+ elements=[
+ Integer(title=_("Warning if %s") % course,
unit=_("MiB"), minvalue=0),
+ Integer(title=_("Critical if %s") % course,
unit=_("MiB"), minvalue=0),
+ ])
@property
def item_spec(self):
- return TextAscii(title=_("Collection name"),)
+ return TextAscii(title=_("Database/Collection name ('<DB name>
<collection name>')"),)
diff --git a/tests/unit/checks/generictests/datasets/mongodb_collections_1.py
b/tests/unit/checks/generictests/datasets/mongodb_collections_1.py
index 7650011..9980fa8 100644
--- a/tests/unit/checks/generictests/datasets/mongodb_collections_1.py
+++ b/tests/unit/checks/generictests/datasets/mongodb_collections_1.py
@@ -4,8 +4,7 @@
checkname = 'mongodb_collections'
-info = [
- [u'admin', u'system.version', u'avgObjSize',
u'59'],
+info = [[u'admin', u'system.version', u'avgObjSize',
u'59'],
[u'admin', u'system.version', u'totalIndexSize',
u'16384'],
[u'admin', u'system.version', u'storageSize',
u'16384'],
[u'admin', u'system.version', u'indexSizes',
u"{u'_id_': 16384}"],
@@ -39,87 +38,23 @@ discovery = {'': [(u'admin system.version', {}),
(u'test zips', {})]}
-checks = {'': [(u'admin system.version',
- {'inodes_levels': (10.0, 5.0),
- 'levels': (80.0, 90.0),
- 'levels_low': (50.0, 60.0),
- 'magic_normsize': 20,
- 'show_inodes': 'onlow',
- 'show_levels': 'onmagic',
- 'show_reserved': False,
- 'trend_perfdata': True,
- 'trend_range': 24},
- [(0,
- '0.36% used (59.00 B of 16.00 kB), trend: 0.00 B / 24 hours',
- [(u'admin_system.version',
- 5.626678466796875e-05,
- 0.0125,
- 0.0140625,
- 0,
- 0.015625),
- ('fs_size', 0.015625, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 0.0006510416666666666)])]),
- (u'config system.sessions',
- {'inodes_levels': (10.0, 5.0),
- 'levels': (80.0, 90.0),
- 'levels_low': (50.0, 60.0),
- 'magic_normsize': 20,
- 'show_inodes': 'onlow',
- 'show_levels': 'onmagic',
- 'show_reserved': False,
- 'trend_perfdata': True,
- 'trend_range': 24},
- [(0,
- '2.42% used (594.00 B of 24.00 kB), trend: 0.00 B / 24 hours',
- [(u'config_system.sessions',
- 0.0005664825439453125,
- 0.01875,
- 0.02109375,
- 0,
- 0.0234375),
- ('fs_size', 0.0234375, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 0.0009765625)])]),
- (u'local startup_log',
- {'inodes_levels': (10.0, 5.0),
- 'levels': (80.0, 90.0),
- 'levels_low': (50.0, 60.0),
- 'magic_normsize': 20,
- 'show_inodes': 'onlow',
- 'show_levels': 'onmagic',
- 'show_reserved': False,
- 'trend_perfdata': True,
- 'trend_range': 24},
- [(0,
- '15.9% used (5.71 of 36.00 kB), trend: 0.00 B / 24 hours',
- [(u'local_startup_log',
- 0.005573272705078125,
- 0.028125,
- 0.031640625,
- 0,
- 0.03515625),
- ('fs_size', 0.03515625, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 0.00146484375)])]),
- (u'test zips',
- {'inodes_levels': (10.0, 5.0),
- 'levels': (80.0, 90.0),
- 'levels_low': (50.0, 60.0),
- 'magic_normsize': 20,
- 'show_inodes': 'onlow',
- 'show_levels': 'onmagic',
- 'show_reserved': False,
- 'trend_perfdata': True,
- 'trend_range': 24},
- [(2,
- '189.7% used (2.65 of 1.39 MB), (warn/crit at 80.0%/90.0%), trend:
0.00 B / 24 hours',
- [(u'test_zips',
- 2.645620346069336,
- 1.115625,
- 1.255078125,
- 0,
- 1.39453125),
- ('fs_size', 1.39453125, None, None, None, None),
- ('growth', 0.0, None, None, None, None),
- ('trend', 0, None, None, 0, 0.05810546875)])])]}
+checks = {
+ '': [
+ (u'admin system.version', {}, [
+ (0, 'Uncompressed size in memory: 59.00 B', []),
+ (0, 'Allocated for document storage: 16.00 kB', []),
+ ]),
+ (u'config system.sessions', {}, [
+ (0, 'Uncompressed size in memory: 594.00 B', []),
+ (0, 'Allocated for document storage: 24.00 kB', []),
+ ]),
+ (u'local startup_log', {}, [
+ (0, 'Uncompressed size in memory: 5.71 kB', []),
+ (0, 'Allocated for document storage: 36.00 kB', []),
+ ]),
+ (u'test zips', {"levels_size": (1, 2),
"levels_storagesize": (1, 2)}, [
+ (2, 'Uncompressed size in memory: 2.65 MB (warn/crit at 1.00 MB/2.00
MB)', []),
+ (1, 'Allocated for document storage: 1.39 MB (warn/crit at 1.00 MB/2.00
MB)', []),
+ ]),
+ ],
+}