Module: check_mk
Branch: master
Commit: e68782cba289e64ab7986aa4599ef2ba01e9d350
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e68782cba289e6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 25 08:05:20 2016 +0200
pylint: Merged pylintrc files to a single one
---
pylint/pylint-checks | 2 +-
pylint/pylint-modules | 2 +-
pylint/pylint-web | 2 +-
pylint/pylint_cmk.py | 4 +--
pylint/{pylintrc.modules => pylintrc} | 14 +++++++---
pylint/pylintrc.checks | 48 ---------------------------------
pylint/pylintrc.web | 40 ---------------------------
7 files changed, 15 insertions(+), 97 deletions(-)
diff --git a/pylint/pylint-checks b/pylint/pylint-checks
index a331f88..16044ed 100755
--- a/pylint/pylint-checks
+++ b/pylint/pylint-checks
@@ -20,4 +20,4 @@ for path in pylint_cmk.check_files():
f.close()
-sys.exit(pylint_cmk.run_pylint("pylintrc.checks", base_path))
+sys.exit(pylint_cmk.run_pylint(base_path))
diff --git a/pylint/pylint-modules b/pylint/pylint-modules
index b70e331..da40389 100755
--- a/pylint/pylint-modules
+++ b/pylint/pylint-modules
@@ -14,4 +14,4 @@ for path in pylint_cmk.ordered_module_files():
pylint_cmk.add_file(f, path)
f.close()
-sys.exit(pylint_cmk.run_pylint("pylintrc.modules", base_path))
+sys.exit(pylint_cmk.run_pylint(base_path))
diff --git a/pylint/pylint-web b/pylint/pylint-web
index 92e53cd..e910547 100755
--- a/pylint/pylint-web
+++ b/pylint/pylint-web
@@ -66,4 +66,4 @@ for plugin_dir in get_web_plugin_dirs():
pylint_cmk.add_file(module, plugin_path)
module.close()
-sys.exit(pylint_cmk.run_pylint("pylintrc.web", base_path))
+sys.exit(pylint_cmk.run_pylint(base_path))
diff --git a/pylint/pylint_cmk.py b/pylint/pylint_cmk.py
index 06cbde2..fb5efc9 100644
--- a/pylint/pylint_cmk.py
+++ b/pylint/pylint_cmk.py
@@ -93,13 +93,13 @@ def get_test_dir():
return base_path
-def run_pylint(cfg_file, base_path):
+def run_pylint(base_path):
pylint_args = os.environ.get("PYLINT_ARGS", "")
if pylint_args:
pylint_args += " "
pylint_output = os.environ.get("PYLINT_OUTPUT")
- pylint_cfg = os.getcwd() + "/" + cfg_file
+ pylint_cfg = os.getcwd() + "/pylintrc"
os.putenv("PYLINT_PATH", os.getcwd())
cmd = "pylint --rcfile=\"%s\" %s*.py" % (pylint_cfg, pylint_args)
diff --git a/pylint/pylintrc.modules b/pylint/pylintrc
similarity index 69%
rename from pylint/pylintrc.modules
rename to pylint/pylintrc
index 1c307ae..ba825cf 100644
--- a/pylint/pylintrc.modules
+++ b/pylint/pylintrc
@@ -21,10 +21,14 @@ disable=C0111,C0326
disable=unsubscriptable-object,unsupported-membership-test,unpacking-non-sequence,assignment-from-none
[TYPECHECK]
-# Can not check methods / attributes of the rrdtool C module. Skipping related errors
-# like the following:
-# [E1101(no-member), create_rrd] Module 'rrdtool' has no 'create' member
-ignored-modules = rrdtool
+# rrdtool
+# Can not check methods / attributes of the rrdtool C module. Skipping related errors
+# like the following:
+# [E1101(no-member), create_rrd] Module 'rrdtool' has no 'create' member
+# ldap
+# The Python ldap module gets a lot of constants from the C API which can not be found by pylint.
+# This results in a lot of these errors: "Module 'ldap' has no 'OPT_REFERRALS' member".
+ignored-modules = rrdtool,ldap
[REPORTS]
output-format=cmk_colorized
@@ -38,6 +42,8 @@ indent-string=' '
[VARIABLES]
# Ignore these unused variables (e.g. _no_item,_no_params)
dummy-variables-rgx=^_.*
+# Needed by web code because of super globals. TODO Clean this up some day
+additional-builtins=html,_,_u,current_language,HTML
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
diff --git a/pylint/pylintrc.checks b/pylint/pylintrc.checks
deleted file mode 100644
index a667903..0000000
--- a/pylint/pylintrc.checks
+++ /dev/null
@@ -1,48 +0,0 @@
-[MASTER]
-# Use the OMD default version lib dir to add the mod_python modules
-init-hook='import sys; sys.path.insert(0, os.environ.get("PYLINT_PATH"))'
-load-plugins=pylint_cmk
-persistent=yes
-# We only want to see errors for the moment. Disable this one day. But prepare to cleanup a lot of stuff.
-errors-only=yes
-
-[MESSAGES CONTROL]
-# C0111 missing module docstring
-# C0326 bad-whitespace
-disable=C0111,C0326
-# unsubscriptable-object
-# unsupported-membership-test
-# unpacking-non-sequence
-# Disable this because we often use multiple types for a single variable. Maybe we
-# can change this in future to make such linter checks work, but for the moment these
-# checks are useless with Check_MK.
-# unpacking-non-sequence
-# Not a problem for us
-disable=unsubscriptable-object,unsupported-membership-test,unpacking-non-sequence,assignment-from-none
-
-[TYPECHECK]
-# Can not check methods / attributes of the rrdtool C module. Skipping related errors
-# like the following:
-# [E1101(no-member), create_rrd] Module 'rrdtool' has no 'create' member
-ignored-modules = rrdtool
-
-[REPORTS]
-output-format=cmk_colorized
-msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
-
-[FORMAT]
-max-line-length=100
-single-line-if-stmt=no
-indent-string=' '
-
-[VARIABLES]
-# Ignore these unused variables (e.g. _no_item,_no_params)
-dummy-variables-rgx=^_.*
-
-# FIXME lm: How to make this different for checks / web / ...?
-# patch /usr/lib/python2.7/dist-packages/pylint/checkers/variables.py to make regexes possible here.
-#additional-builtins=factory_settings,saveint,savefloat,snmp_info,snmp_scan_functions,check_info,special_agent_info,time,sys,check_temperature,check_humidity,get_age_human_readable,get_timestamp_human_readable,get_rate,get_relative_date_human_readable,get_bytes_human_readable,get_average,g_hostname,OID_END,OID_STRING,CACHED_OID,re,get_percent_human_readable,MKGeneralException,MKCounterWrapped,GRAB_USER,g_item_state,get_item_state,set_item_state,clear_item_state,quote_shell_string,regex,SKIP,RAISE,ZERO,get_nic_speed_human_readable,fnmatch,host_extra_conf,host_extra_conf_merged,hosttags_match_taglist,tags_of_host,in_extraconf_hostlist,core_state_names,active_check_info,is_ipv6_primary,~(check|parse|inventory|snmp_scan|scan)_.*,~.*_scan_function
-
-[MISCELLANEOUS]
-# List of note tags to take in consideration, separated by a comma.
-notes=FIXME,TODO
diff --git a/pylint/pylintrc.web b/pylint/pylintrc.web
deleted file mode 100644
index 1ff6551..0000000
--- a/pylint/pylintrc.web
+++ /dev/null
@@ -1,40 +0,0 @@
-[MASTER]
-# Use the OMD default version lib dir to add the mod_python modules
-init-hook='import sys; sys.path.insert(0, os.environ.get("PYLINT_PATH"))'
-load-plugins=pylint_cmk
-persistent=yes
-# We only want to see errors for the moment. Disable this one day. But prepare to cleanup a lot of stuff.
-errors-only=yes
-
-[MESSAGES CONTROL]
-# C0111 missing module docstring
-# C0326 bad-whitespace
-disable=C0111,C0326
-# Disable this because we often use multiple types for a single variable. Maybe we
-# can change this in future to make such linter checks work, but for the moment these
-# checks are useless with Check_MK.
-disable=unsubscriptable-object,unsupported-membership-test,unpacking-non-sequence
-
-[TYPECHECK]
-# The Python ldap module gets a lot of constants from the C API which can not be found by pylint.
-# This results in a lot of these errors: "Module 'ldap' has no 'OPT_REFERRALS' member".
-ignored-modules = ldap
-
-[REPORTS]
-output-format=cmk_colorized
-msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
-
-[FORMAT]
-max-line-length=100
-single-line-if-stmt=no
-indent-string=' '
-
-[VARIABLES]
-# Ignore these unused variables (e.g. _no_item,_no_params)
-dummy-variables-rgx=^_.*
-
-additional-builtins=html,_,_u,current_language,HTML
-
-[MISCELLANEOUS]
-# List of note tags to take in consideration, separated by a comma.
-notes=FIXME,TODO
Module: check_mk
Branch: master
Commit: ca725d8e54ac9fe469edae6123e862f0b62372c7
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ca725d8e54ac9f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Apr 22 15:50:10 2016 +0200
update for wk3387: better implementation
---
checks/ps | 3 +++
checks/ps.include | 6 +-----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/checks/ps b/checks/ps
index ac8c386..cf02118 100644
--- a/checks/ps
+++ b/checks/ps
@@ -217,6 +217,9 @@ def ps_parse_process_entries(parsed):
# Make number of columns in line consistent for discovery/check
line.insert(1, (None,))
+ # Filter out any lines where no process command line is available, e.g.
+ # [None, u'(<defunct>,,,)']
+ parsed = [ x for x in parsed if len(x) > 2 ]
return parsed
diff --git a/checks/ps.include b/checks/ps.include
index 45748f8..98093aa 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -185,11 +185,7 @@ def process_matches_for_discovery(process_line, process_pattern, userspec):
if matchobject:
return [ g and g or "" for g in matchobject.groups() ], grabbed_user
else:
- # command_line can be empty. Found in AIX agent output (server-aix-ps-1):
- # ...
- # (<defunct>,,,)
- # ...
- if command_line and command_line[0] == process_pattern:
+ if command_line[0] == process_pattern:
return (), grabbed_user
return False, grabbed_user
Module: check_mk
Branch: master
Commit: ac62a6c91151acaac48bda3ec76ed1c0a1563671
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac62a6c91151ac…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Apr 22 15:18:55 2016 +0200
wato_remove_nonsite_folders.py: New helper script for distributed slave sites.
It removes all wato folders which are not related to the site.
This reduces the number of the configuration files, and in the end the size
of the Check_MK Helper processes (when using the CMC).
---
doc/treasures/wato_remove_nonsite_folders.py | 157 ++++++++++++++++++++++++++
1 file changed, 157 insertions(+)
diff --git a/doc/treasures/wato_remove_nonsite_folders.py b/doc/treasures/wato_remove_nonsite_folders.py
new file mode 100644
index 0000000..6fa605d
--- /dev/null
+++ b/doc/treasures/wato_remove_nonsite_folders.py
@@ -0,0 +1,157 @@
+#!/usr/bin/python
+# encoding: utf-8
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | 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.
+
+########################################
+# >>>>>>>>>>>> IMPORTANT <<<<<<<<<<<<<<
+# This script deletes subfolders in the ~/etc/check_mk/conf.d/wato directory
+# It should only be used in slave sites. You have been warned...
+########################################
+
+# The purpose of this script is to remove WATO folders in slave sites which
+# do not have any reference to the site. The positive site effect of this
+# operation is a reduced size of the ~/var/check_mk/core/config.mk, which represents
+# the configuration for the "Check_MK Check Helpers".
+# A smaller configuration results in smaller helper processes
+
+# The deletion of the nonsite folders is always triggered in a hook right before the
+# "Activate changes" action, internally named pre-activate-changes. Keep in mind that
+# this script delete folders, rules and hosts. Other scripts in the pre-activate-changes
+# block might receive outdated information, where all hosts are still present.
+
+# Installation:
+# Copy this file to a distributed monitoring slave site in the site folder
+# ~/local/share/check_mk/web/plugins/wato
+# and restart the apache afterwards. A restart of the monitoring core is also advised,
+# since the check helpers are not fully restarted during a core reload.
+
+# The umodified version of this script only creates a logfile in
+# ~/var/log/remove_nonsite_folders.log, showing the required actions.
+# If you want the script to actually remove the folders you need to change
+# the parameter do_remove_folders (just below) to True.
+
+import pprint
+
+def remove_nonrelated_site_folders(effective_hosts):
+ # Note: most of the paths here are hardcorded
+ # I do not want to use any helper functions from the WATO world, because
+ # they might change over time.
+
+ # Set this true if you actually want to delete folders
+ # If you just want to start a dry run, leave this at False and have a
+ # look in the logfile
+ do_remove_folders = False
+
+ logfile = file(os.path.expanduser("~/var/log/remove_site_folders.log"), "w")
+ def log_info(info):
+ logfile.write(info + "\n")
+
+ # Is this a master or a viewer site? -> return
+ if os.path.exists(defaults.default_config_dir + "/multisite.d/sites.mk"):
+ return
+
+ # The own site id is written into the distributed_wato.mk file. If it's missing -> return
+ if not os.path.exists(defaults.check_mk_configdir + "/distributed_wato.mk"):
+ return
+
+ # Parse the file with the site name
+ file_vars_g = {}
+ file_vars = {}
+ try:
+ execfile(defaults.check_mk_configdir + "/distributed_wato.mk", file_vars_g, file_vars)
+ except Exception, e:
+ # Return on any error
+ return
+ our_site = file_vars.get("distributed_wato_site")
+
+ if not our_site:
+ # Looks like the file is empty -> return
+ return
+
+
+ # Get all folders in WATO dir
+ config_dir = defaults.check_mk_configdir + "/wato/"
+ all_folders = sorted([x[0][len(config_dir):] for x in os.walk(config_dir)])[1:] # Skip first folder (WATO root!)
+
+ keep_folders = set([])
+ total_hosts = 0
+ for host, attributes in effective_hosts.items():
+ host_folder = attributes[".folder"][".path"]
+
+ host_site = None
+ host_tags = attributes.get(".tags", [])
+ for tag in host_tags:
+ if tag.startswith("site:"):
+ host_site = tag.split(":", 1)[1]
+ break
+ if not host_site:
+ # Site host tag not available. Keep this folder
+ keep_folders.add(host_folder)
+ continue
+
+ if host_site == our_site:
+ total_hosts += 1
+ keep_folders.add(host_folder)
+
+
+ def folder_required(foldername):
+ for folder in keep_folders:
+ if folder.startswith(foldername):
+ return True
+ else:
+ return False
+
+ remove_folders = []
+ for folder in all_folders:
+ if not folder_required(folder):
+ remove_folders.append(folder)
+
+
+ if do_remove_folders:
+ import shutil
+ for folder in remove_folders:
+ if folder: # This is just another safety mechanism to prevent the deletion of the
+ # WATO root folder. The WATO root folder should never appear in this list of folders,
+ # because it is filtered out earlier on. Just in case..
+ the_folder = "%s%s" % (config_dir, folder)
+ if os.path.exists(the_folder):
+ shutil.rmtree(the_folder)
+
+ log_info("Did actually remove folders (no dry run): %s" % do_remove_folders)
+
+ # Log the outcome
+ log_info("\nAll folders\n##############")
+ log_info("\n".join(all_folders))
+ log_info("\nKeep folders\n##############")
+ log_info("\n".join(keep_folders))
+ log_info("\nRemove folders\n##############")
+ log_info("\n".join(remove_folders))
+ log_info("\nTotal hosts of current site %s" % total_hosts)
+
+
+register_hook("pre-activate-changes", remove_nonrelated_site_folders)
+
+
+
Module: check_mk
Branch: master
Commit: a4a99b22dcf1e9d30b0d3ae9788495b6facb67ae
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a4a99b22dcf1e9…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Apr 22 15:15:24 2016 +0200
3473: fileinfo.groups: the include patterns now also support the pattern YESTERDAY, in addition to DATE
---
.werks/3473 | 11 +++++++++++
ChangeLog | 1 +
checks/fileinfo | 18 +++++++++++-------
web/plugins/wato/check_parameters.py | 10 +++++++++-
4 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/.werks/3473 b/.werks/3473
new file mode 100644
index 0000000..af09ac1
--- /dev/null
+++ b/.werks/3473
@@ -0,0 +1,11 @@
+Title: fileinfo.groups: the include patterns now also support the pattern YESTERDAY, in addition to DATE
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.9i1
+Date: 1461330445
+Class: feature
+
+You can now specifiy include patterns with the following syntax<br>
+<i>/var/tmp/backups/$YESTERDAY:%Y%m%d$.txt</i>.<br>This includes files of yesterdays date
+with the given date format spec. The YESTERDAY format should also consider daylight saving time.
diff --git a/ChangeLog b/ChangeLog
index eb8226c..04c6189 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -67,6 +67,7 @@
NOTE: Please refer to the migration notes!
* 3414 New declarator BINARY(...) for OIDs - returning a list of byte values...
* 3423 papouch_th2e_sensors, papouch_th2e_sensors.dewpoint, papouch_th2e_sensors.humidity: new checks which monitor the temperature, dew point and humidity sensors of Papouch TH2E devices
+ * 3473 fileinfo.groups: the include patterns now also support the pattern YESTERDAY, in addition to DATE...
* 3073 FIX: windows agent: relative paths to mrpe scripts are now treated as relative to the agent installation directory...
* 3061 FIX: mk_jolokia: Fixed debugging of the agent plugin
* 3074 FIX: windows agent: fixed incorrect values for 32-bit performance counters
diff --git a/checks/fileinfo b/checks/fileinfo
index 51c46a4..b5580c9 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -60,13 +60,17 @@ def inventory_fileinfo(info, case):
inventory.append((group, {}))
return inventory
-def fileinfo_process_date(pattern,reftime):
- disect = re.match('(/.*)\$DATE:((?:%\w.?){1,})\$(.*)',pattern)
- if disect:
- prefix = disect.group(1)
- datepattern = time.strftime(disect.group(2),time.localtime(reftime))
- postfix = disect.group(3)
- pattern = prefix+datepattern+postfix
+def fileinfo_process_date(pattern, reftime):
+ for what, the_time in [ ("DATE", reftime), ("YESTERDAY", reftime - 86400) ]:
+ the_regex = '(/.*)\$%s:((?:%%\w.?){1,})\$(.*)' % what
+ disect = re.match(the_regex, pattern)
+ if disect:
+ prefix = disect.group(1)
+ datepattern = time.strftime(disect.group(2),time.localtime(the_time))
+ postfix = disect.group(3)
+ pattern = prefix+datepattern+postfix
+ return pattern
+
return pattern
def fileinfo_groups_of_file(check_filename,reftime):
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index f2db844..b79f26e 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -2654,7 +2654,15 @@ register_rule(group + '/' + subgroup_storage,
'<tt>/var/log/apache/*.log</tt>. For files contained in a group '
'the inventory will automatically create a group service instead '
'of single services for each file. This rule also applies when '
- 'you use manually configured checks instead of inventorized ones.'),
+ 'you use manually configured checks instead of inventorized ones. '
+ 'Furthermore, the current time/date in a configurable format '
+ 'may be included in the include pattern. The syntax is as follows: '
+ '$DATE:format-spec$ or $YESTERDAY:format-spec$, where format-spec '
+ 'is a list of time format directives of the unix date command. '
+ 'Example: $DATE:%Y%m%d$ is todays date, e.g. 20140127. A pattern '
+ 'of /var/tmp/backups/$DATE:%Y%m%d$.txt would search for .txt files '
+ 'with todays date as name in the directory /var/tmp/backups. '
+ 'The YESTERDAY syntax simply subtracts one day from the reference time.'),
valuespec = ListOf(
Tuple(
help = _("This defines one file grouping pattern"),