Module: check_mk
Branch: master
Commit: 7647cd04fdb096c825559e3ac22d4ca2294243b5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7647cd04fdb096…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 18 11:35:03 2015 +0100
#2881 Automatically restart core instead of reload after changes in local check plugins
If you create, remove or modify you own check plugins in
<tt>~/local/share/check_mk/checks</tt> then usually had to do a real core
restart with <tt>cmk -R</tt> in order to activate these changes. This is now
done automatically. Whenever you do <i>Activate Changes</i> then Check_MK
does a real restart on demand if it sees any modification in the check plugins.
This also helps the handling of installing and removing Check_MK packages (MKPs).
---
.werks/2881 | 14 ++++++++++++++
ChangeLog | 1 +
modules/automation.py | 30 ++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
diff --git a/.werks/2881 b/.werks/2881
new file mode 100644
index 0000000..575e104
--- /dev/null
+++ b/.werks/2881
@@ -0,0 +1,14 @@
+Title: Automatically restart core instead of reload after changes in local check plugins
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.7i4
+Date: 1450434659
+Class: feature
+
+If you create, remove or modify you own check plugins in
+<tt>~/local/share/check_mk/checks</tt> then usually had to do a real core
+restart with <tt>cmk -R</tt> in order to activate these changes. This is now
+done automatically. Whenever you do <i>Activate Changes</i> then Check_MK
+does a real restart on demand if it sees any modification in the check plugins.
+This also helps the handling of installing and removing Check_MK packages (MKPs).
diff --git a/ChangeLog b/ChangeLog
index 31514d7..5aacd49 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
1.2.7i4:
Core & Setup:
* 2771 Errors in Check_MK configuration do not prevent the core from being restarted
anymore...
+ * 2881 Automatically restart core instead of reload after changes in local check
plugins...
* 2682 FIX: Fixed exception Error creating configuration: global name
'extra_host_attributes' is not defined
* 2443 FIX: Fixed quoting of ! in classical nagios checks configured via WATO...
* 2718 FIX: Fixed agent timeouts not resulting in a crash report anympore...
diff --git a/modules/automation.py b/modules/automation.py
index 8622454..e76ec10 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -412,6 +412,8 @@ def automation_delete_host(args):
def automation_restart(job = "restart", use_rushd = True):
+ if job == "reload" and check_plugins_have_changed():
+ job = "restart"
# make sure, Nagios does not inherit any open
# filedescriptors. This really happens, e.g. if
@@ -492,6 +494,34 @@ def automation_restart(job = "restart", use_rushd = True):
sys.stdout = old_stdout
return configuration_warnings
+
+def check_plugins_have_changed():
+ if not omd_root:
+ return False # not supported for manual setup
+
+ this_time = last_modification_in_dir(local_checks_dir)
+ last_time = time_of_last_config_creation()
+ return this_time > last_time
+
+
+def last_modification_in_dir(dir_path):
+ max_time = os.stat(dir_path).st_mtime
+ for file_name in os.listdir(dir_path):
+ max_time = max(max_time, os.stat(dir_path + "/" + file_name).st_mtime)
+ return max_time
+
+
+def time_of_last_config_creation():
+ if monitoring_core == "cmc":
+ config_path = omd_root + "/var/check_mk/core/config"
+ else:
+ config_path = omd_root + "/etc/nagios/conf.d/check_mk_objects.cfg"
+ if os.path.exists(config_path):
+ return os.stat(config_path).st_mtime
+ else:
+ return 0
+
+
def automation_get_configuration():
# We read the list of variable names from stdin since
# that could be too much for the command line