Module: check_mk
Branch: master
Commit: 29d0be51a52873b790da0c7566e48f4f8351193b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=29d0be51a52873…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon May 9 16:57:45 2016 +0200
Added missing file ; Added cmk module dir to pylint checks
---
lib/exceptions.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
pylint/pylint-misc | 1 +
2 files changed, 48 insertions(+)
diff --git a/lib/exceptions.py b/lib/exceptions.py
new file mode 100644
index 0000000..3f6ab91
--- /dev/null
+++ b/lib/exceptions.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2016 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-
+# tails. 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.
+
+# never used directly in the code. Just some wrapper to make all of our
+# exceptions handleable with one call
+class MKException(Exception):
+ # Do not use the Exception() __str__, because it uses str()
+ # to convert the message. We want to keep unicode strings untouched
+ # And don't use self.message, because older python versions don't
+ # have this variable set. self.args[0] seems to be the most portable
+ # way at the moment.
+ def __str__(self):
+ return self.args[0]
+
+
+class MKGeneralException(MKException):
+ plain_title = _("General error")
+ title = _("Error")
+
+ def __init__(self, reason):
+ self.reason = reason
+
+ def __str__(self):
+ return self.reason
diff --git a/pylint/pylint-misc b/pylint/pylint-misc
index 09d2de4..7d2ba4f 100755
--- a/pylint/pylint-misc
+++ b/pylint/pylint-misc
@@ -8,6 +8,7 @@ import pylint_cmk
pylint_cmk.ensure_equal_branches()
search_paths = [
+ "../lib",
"../bin",
"../notifications",
"../agents/plugins",
Module: check_mk
Branch: master
Commit: fbde9e5e65384224664c61ae75ae814e1e0f1250
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fbde9e5e653842…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Mon May 9 15:11:59 2016 +0200
3130 periodic service discovery can now be configured to not activate specific service changes
The rule "Periodic service discovery" now allows setting a whitelist and a blacklist on service
description.
A service for which a change was automatically discovered that doesn't match any whitelist or one
that does match any blacklist will still show up in the discovery service but it will not be
activated automatically.
---
.werks/3130 | 13 +++++++
ChangeLog | 1 +
modules/discovery.py | 56 ++++++++++++++++++++++++----
web/plugins/wato/check_mk_configuration.py | 12 +++++-
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/.werks/3130 b/.werks/3130
new file mode 100644
index 0000000..48ef6ae
--- /dev/null
+++ b/.werks/3130
@@ -0,0 +1,13 @@
+Title: periodic service discovery can now be configured to not activate specific service changes
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.2.9i1
+Date: 1462799265
+Class: feature
+
+The rule "Periodic service discovery" now allows setting a whitelist and a blacklist on service
+description.
+A service for which a change was automatically discovered that doesn't match any whitelist or one
+that does match any blacklist will still show up in the discovery service but it will not be
+activated automatically.
diff --git a/ChangeLog b/ChangeLog
index 87b8516..fe959ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -290,6 +290,7 @@
* 3239 The delay and the period of notifications can be fractions of a minute now.
* 3116 Timerange buttons for downtimes can now be configured...
* 3469 Show type of rule match of a rule (first, per-parameter, all) in WATO...
+ * 3130 periodic service discovery can now be configured to not activate specific service changes...
* 3060 FIX: Folder properties: Fixed exception when a user has no alias set...
* 3062 FIX: Git integration: Fixed not adding files in WATO folders to git control
* 3203 FIX: Distributed WATO: Fixed exception in remote host service discovery...
diff --git a/modules/discovery.py b/modules/discovery.py
index b006d3f..c223f14 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -142,8 +142,11 @@ def do_discovery_for(hostname, check_types, only_new, use_caches, on_error):
# determine changed services on host.
# param mode: can be one of "new", "remove", "fixall", "refresh"
# param do_snmp_scan: if True, a snmp host will be scanned, otherwise uses only the check types
-# previously discovered
-def discover_on_host(mode, hostname, do_snmp_scan, use_caches, on_error="ignore"):
+# previously discovereda
+# param servic_filter: if a filter is set, it controls whether items are touched by the discovery.
+# if it returns False for a new item it will not be added, if it returns
+# False for a vanished item, that item is kept
+def discover_on_host(mode, hostname, do_snmp_scan, use_caches, on_error="ignore", service_filter=None):
counts = {
"added" : 0,
"removed" : 0,
@@ -153,6 +156,9 @@ def discover_on_host(mode, hostname, do_snmp_scan, use_caches, on_error="ignore"
if hostname not in all_active_realhosts():
return [0, 0, 0, 0], ""
+ if service_filter is None:
+ service_filter = lambda hostname, check_type, item: True
+
err = None
try:
@@ -175,7 +181,7 @@ def discover_on_host(mode, hostname, do_snmp_scan, use_caches, on_error="ignore"
# that way.
if check_source in ("new"):
- if mode in ("new", "fixall", "refresh"):
+ if mode in ("new", "fixall", "refresh") and service_filter(hostname, check_type, item):
counts["added"] += 1
new_items[(check_type, item)] = paramstring
@@ -187,7 +193,7 @@ def discover_on_host(mode, hostname, do_snmp_scan, use_caches, on_error="ignore"
elif check_source in ("obsolete", "vanished"):
# keep item, if we are currently only looking for new services
# otherwise fix it: remove ignored and non-longer existing services
- if mode not in ("fixall", "remove"):
+ if mode not in ("fixall", "remove") or not service_filter(hostname, check_type, item):
new_items[(check_type, item)] = paramstring
counts["kept"] += 1
else:
@@ -246,6 +252,10 @@ def default_discovery_check_parameters():
}
+def discovery_filter_by_lists(hostname, check_type, item, whitelist, blacklist):
+ description = service_description(hostname, check_type, item)
+ return whitelist.match(description) is not None and\
+ blacklist.match(description) is None
def check_discovery(hostname, ipaddress=None):
params = discovery_check_parameters(hostname) or \
@@ -270,6 +280,20 @@ def check_discovery(hostname, ipaddress=None):
long_infotexts = []
need_rediscovery = False
+ params_rediscovery = params.get("inventory_rediscovery", {})
+
+ if params_rediscovery.get("service_whitelist", []) or\
+ params_rediscovery.get("service_blacklist", []):
+ # whitelist. if none is specified, this matches everything
+ whitelist = regex("|".join(["(%s)" % pat for pat in params_rediscovery.get("service_whitelist", [".*"])]))
+ # blacklist. if none is specified, this matches nothing
+ blacklist = regex("|".join(["(%s)" % pat for pat in params_rediscovery.get("service_blacklist", ["(?!x)x"])]))
+
+ item_filters = lambda hostname, check_type, item:\
+ discovery_filter_by_lists(hostname, check_type, item, whitelist, blacklist)
+ else:
+ item_filters = None
+
for check_state, title, params_key, default_state in [
( "new", "unmonitored", "severity_unmonitored", inventory_check_severity ),
( "vanished", "vanished", "severity_vanished", 0 ),
@@ -277,12 +301,17 @@ def check_discovery(hostname, ipaddress=None):
affected_check_types = {}
count = 0
+ unfiltered = False
for (check_type, item), (check_source, paramstring) in services.items():
if check_source == check_state:
count += 1
affected_check_types.setdefault(check_type, 0)
affected_check_types[check_type] += 1
+
+ if not unfiltered and item_filters(hostname, check_type, item):
+ unfiltered = True
+
long_infotexts.append("%s: %s: %s" % (title, check_type, service_description(hostname, check_type, item)))
if affected_check_types:
@@ -293,8 +322,9 @@ def check_discovery(hostname, ipaddress=None):
if params.get("inventory_rediscovery", False):
mode = params["inventory_rediscovery"]["mode"]
- if (check_state == "new" and mode in ( 0, 2, 3 )) or \
- check_state == "vanished" and mode in ( 1, 2, 3 ):
+ if unfiltered and\
+ ((check_state == "new" and mode in ( 0, 2, 3 )) or
+ (check_state == "vanished" and mode in ( 1, 2, 3 ))):
need_rediscovery = True
else:
infotexts.append("no %s services found" % title)
@@ -448,12 +478,24 @@ def discover_marked_hosts():
# have to do hosts one-by-one because each could have a different configuration
params = discovery_check_parameters(hostname) or default_discovery_check_parameters()
+ params_rediscovery = params["inventory_rediscovery"]
+ if "service_blacklist" in params_rediscovery or "service_whitelist" in params_rediscovery:
+ # whitelist. if none is specified, this matches everything
+ whitelist = regex("|".join(["(%s)" % pat for pat in params_rediscovery.get("service_whitelist", [".*"])]))
+ # blacklist. if none is specified, this matches nothing
+ blacklist = regex("|".join(["(%s)" % pat for pat in params_rediscovery.get("service_blacklist", ["(?!x)x"])]))
+ item_filters = lambda hostname, check_type, item:\
+ discovery_filter_by_lists(hostname, check_type, item, whitelist, blacklist)
+ else:
+ item_filters = None
+
why_not = may_rediscover(params)
if not why_not:
redisc_params = params["inventory_rediscovery"]
verbose(" Doing discovery with mode '%s'...\n" % mode_table[redisc_params["mode"]])
result, error = discover_on_host(mode_table[redisc_params["mode"]], hostname,
- params["inventory_check_do_scan"], True)
+ params["inventory_check_do_scan"], True,
+ service_filter=item_filters)
if error is not None:
if error:
verbose("failed: %s\n" % error)
diff --git a/web/plugins/wato/check_mk_configuration.py b/web/plugins/wato/check_mk_configuration.py
index c318642..8b570fd 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1863,8 +1863,18 @@ register_rule(group,
help = _("Here you can have the changes activated whenever services "
"have been added or removed."),
)),
+ ( "service_whitelist",
+ ListOfStrings(
+ title = _("Whitelist Services"),
+ allow_empty = False,
+ )),
+ ( "service_blacklist",
+ ListOfStrings(
+ title = _("Blacklist Services"),
+ allow_empty = False,
+ )),
],
- optional_keys = None,
+ optional_keys = ["service_whitelist", "service_blacklist"],
)),
],
optional_keys = ["inventory_rediscovery"],
Module: check_mk
Branch: master
Commit: 7f96c97d174cae1355edf597bec90df7e82753fa
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7f96c97d174cae…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 6 16:35:20 2016 +0200
Some minor naming changes
---
web/plugins/wato/check_mk_configuration.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/web/plugins/wato/check_mk_configuration.py b/web/plugins/wato/check_mk_configuration.py
index 15b541c..c318642 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -880,7 +880,7 @@ register_configvar(group,
register_configvar(group,
"password_policy",
Dictionary(
- title = _('htpasswd: Password Policy'),
+ title = _('Password policy for local accounts'),
help = _('You can define some rules to which each user password ahers. By default '
'all passwords are accepted, even ones which are made of only a single character, '
'which is obviously a bad idea. Using this option you can enforce your users '
@@ -926,7 +926,7 @@ def list_contactgroups():
register_configvar(group,
"default_user_profile",
Dictionary(
- title = _("Default User Profile"),
+ title = _("Default user profile"),
help = _("With this option you can specify the attributes a user which is created during "
"its initial login gets added. For example, the default is to add the role \"user\" "
"to all automatically created users."),