Module: check_mk
Branch: master
Commit: 2e60ca5fca090138c35688101190e49f9abfd42c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2e60ca5fca0901…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jun 30 11:54:40 2014 +0200
FIX Do not fail on errors in *.mk files anymore - except in interactive mode
If a syntax error in <tt>main.mk</tt> or other <tt>*.mk</tt> files
occurs,
Check_MK used to abort any operation. This is nasty when for example a new
variable that has been introduced in a new version is not known in an older
version of Check_MK and thus after a version downgrade the configuration
cannot be activated any more.
The behaviour has now changed so that in case of such an error Check_MK will only
abort in <i>interactive</i> mode, i.e. if the standard output is a terminal.
That means that WATO will always try to activate Changes. You can force the
old behaviour by adding the new option <tt>--interactive</tt>.
Conflicts:
ChangeLog
modules/check_mk.py
---
.werks/1035 | 18 ++++++++++++++++++
ChangeLog | 1 +
modules/check_mk.py | 22 +++++++++++++++++-----
3 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/.werks/1035 b/.werks/1035
new file mode 100644
index 0000000..4975cee
--- /dev/null
+++ b/.werks/1035
@@ -0,0 +1,18 @@
+Title: Do not fail on errors in *.mk files anymore - except in interactive mode
+Level: 2
+Component: core
+Class: fix
+State: unknown
+Version: 1.2.5i5
+Date: 1404121324
+
+If a syntax error in <tt>main.mk</tt> or other <tt>*.mk</tt>
files occurs,
+Check_MK used to abort any operation. This is nasty when for example a new
+variable that has been introduced in a new version is not known in an older
+version of Check_MK and thus after a version downgrade the configuration
+cannot be activated any more.
+
+The behaviour has now changed so that in case of such an error Check_MK will only
+abort in <i>interactive</i> mode, i.e. if the standard output is a terminal.
+That means that WATO will always try to activate Changes. You can force the
+old behaviour by adding the new option <tt>--interactive</tt>.
diff --git a/ChangeLog b/ChangeLog
index 39fba89..3d199fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
Core & Setup:
* 1012 Fix quoting of backslashes in custom checks with nagios core...
NOTE: Please refer to the migration notes!
+ * 1035 FIX: Do not fail on errors in *.mk files anymore - except in interactive
mode...
Checks & Agents:
* 0168 f5_bigip_pool: Added Wato configuration...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 78c4403..9e943f5 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -37,6 +37,7 @@ g_profile_path = 'profile.out'
if __name__ == "__main__":
opt_debug = '--debug' in sys.argv[1:]
+ opt_interactive = '--interactive' in sys.argv[1:]
opt_verbose = '-v' in sys.argv[1:] or '--verbose' in
sys.argv[1:]
if '--profile' in sys.argv[1:]:
import cProfile
@@ -48,6 +49,7 @@ if __name__ == "__main__":
else:
opt_verbose = False
opt_debug = False
+ opt_interactive = False
#.
# .--Pathnames-----------------------------------------------------------.
@@ -122,6 +124,12 @@ def verbose(t):
sys.stderr.write(t)
sys.stderr.flush()
+# Abort after an error, but only in interactive mode.
+def interactive_abort(error):
+ if sys.stdout.isatty() or opt_interactive:
+ sys.stderr.write(error + "\n")
+ sys.exit(1)
+
# During setup a file called defaults is created in the modules
# directory. In this file all directories are configured. We need to
@@ -4741,6 +4749,9 @@ OPTIONS:
prevents DNS lookups.
--usewalk use snmpwalk stored with --snmpwalk
--debug never catch Python exceptions
+ --interactive Some errors are only reported in interactive mode, i.e. if stdout
+ is a TTY. This option forces interactive mode even if the output
+ is directed into a pipe or file.
--procs N start up to N processes in parallel during --scan-parents
--checks A,.. restrict checks/inventory to specified checks (tcp/snmp/check type)
--keepalive used by Check_MK Mirco Core: run check and --notify in continous
@@ -5615,11 +5626,10 @@ def read_config_files(with_autochecks=True, with_conf_d=True):
marks_hosts_with_path(_old_all_hosts, all_hosts, _f)
marks_hosts_with_path(_old_clusters, clusters.keys(), _f)
except Exception, e:
- sys.stderr.write("Cannot read in configuration file %s:\n%s\n" %
(_f, e))
- if __name__ == "__main__":
- sys.exit(3)
- else:
+ if opt_debug:
raise
+ else:
+ interactive_abort("Cannot read in configuration file %s: %s" %
(_f, e))
# Strip off host tags from the list of all_hosts. Host tags can be
# appended to the hostnames in all_hosts, separated by pipe symbols,
@@ -5878,7 +5888,7 @@ def output_profile():
# if check_mk is not called as module
if __name__ == "__main__":
short_options = 'ASHVLCURODMmd:Ic:nhvpXPNBil'
- long_options = [ "help", "version", "verbose",
"compile", "debug",
+ long_options = [ "help", "version", "verbose",
"compile", "debug", "interactive",
"list-checks", "list-hosts",
"list-tag", "no-tcp", "cache",
"flush", "package", "localize",
"donate", "snmpwalk", "oid=", "extraoid=",
"snmptranslate", "bake-agents",
@@ -5944,6 +5954,8 @@ if __name__ == "__main__":
opt_nowiki = True
elif o == '--debug':
opt_debug = True
+ elif o == '--interactive':
+ opt_interactive = True
elif o == '-I':
seen_I += 1
elif o == "--checks":