Module: check_mk
Branch: master
Commit: 71cd6884ce12baf243dab201fe273148ead3b026
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=71cd6884ce12ba…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 14 14:22:02 2016 +0200
bailing out is now handled by raising an exception
---
cmk_base/compress_history.py | 6 ++++--
lib/exceptions.py | 14 +++++++++++++-
modules/check_mk.py | 8 +++++---
modules/check_mk_base.py | 13 -------------
4 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/cmk_base/compress_history.py b/cmk_base/compress_history.py
index 6f4e713..c9e1e29 100644
--- a/cmk_base/compress_history.py
+++ b/cmk_base/compress_history.py
@@ -29,12 +29,14 @@
# logfiles and then compress them. Do *not* compress compressed
# files again.
+from cmk.exceptions import MKBailOut
+
import cmk.log
logger = cmk.log.get_logger(__name__)
def do_compress_history(args):
if not args:
- bail_out("Please specify files to compress.")
+ raise MKBailOut("Please specify files to compress.")
for filename in args:
try:
@@ -43,7 +45,7 @@ def do_compress_history(args):
except Exception, e:
if cmk.debug.enabled():
raise
- bail_out(str(e))
+ raise MKBailOut("%s" % e)
def compress_history_file(input_path, output_path):
diff --git a/lib/exceptions.py b/lib/exceptions.py
index d42244c..3642b83 100644
--- a/lib/exceptions.py
+++ b/lib/exceptions.py
@@ -65,6 +65,18 @@ class MKGeneralException(MKException):
# propagate the termination up the callstack.
# This should be raised in all cases where the program termination is a
# "normal" case and no exception handling like printing a stack trace
-# should be done.
+# nor an error message should be done. The program is stopped with
+# exit code 0.
class MKTerminate(Exception):
pass
+
+
+# This is raised to print an error message and then end the program.
+# The program should catch this at top level and end exit the program
+# with exit code 3, in order to be compatible with monitoring plugin API.
+class MKBailOut(Exception):
+ def __init__(self, reason):
+ self.reason = reason
+
+ def __str__(self):
+ return self.reason
diff --git a/modules/check_mk.py b/modules/check_mk.py
index aa7334d..d6a2f71 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -46,7 +46,7 @@ import py_compile
import inspect
from cmk.regex import regex, is_regex
-from cmk.exceptions import MKGeneralException, MKTerminate
+from cmk.exceptions import MKGeneralException, MKTerminate, MKBailOut
import cmk.debug
import cmk.log
import cmk.tty as tty
@@ -4882,7 +4882,8 @@ try:
elif o in [ '-A', '--bake-agents' ]:
if 'do_bake_agents' not in globals():
- bail_out("Agent baking is not implemented in your version of Check_MK. Sorry.")
+ raise MKBailOut("Agent baking is not implemented in your version of Check_MK. Sorry.")
+
if args:
hostnames = parse_hostname_list(args, with_clusters = False, with_foreign_hosts = True)
else:
@@ -4892,7 +4893,8 @@ try:
elif o == '--cap':
if 'do_cap' not in globals():
- bail_out("Agent packages are not supported by your version of Check_MK.")
+ raise MKBailOut("Agent packages are not supported by your version of Check_MK.")
+
do_cap(args)
done = True
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 815d984..37ab13e 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -72,7 +72,6 @@ import cmk_base.agent_simulator
# from --debug
# - remove all remaining print commands and use sys.stdout.write instead
# or define a new output function
-# - Also create a function bail_out() for printing and error and exiting
#.
# .--Globals-------------------------------------------------------------.
@@ -114,12 +113,6 @@ def vverbose(text):
if opt_verbose >= 2:
verbose(text)
-# Output text to sys.stderr with a linefeed added. Exists
-# afterwards with and exit code of 3, in order to be
-# compatible with monitoring plugin API.
-def bail_out(reason):
- raise MKBailOut(reason)
-
def warning(reason):
stripped = reason.lstrip()
indent = reason[:len(reason) - len(stripped)]
@@ -187,12 +180,6 @@ RAISE = False
ZERO = 0.0
-class MKBailOut(Exception):
- def __init__(self, reason):
- self.reason = reason
- def __str__(self):
- return self.reason
-
class MKCounterWrapped(Exception):
def __init__(self, reason):
self.reason = reason
Module: check_mk
Branch: master
Commit: a908c127d73dc7f689ec0cb743f6bbc1e6fffa71
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a908c127d73dc7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 14 14:58:58 2016 +0200
Moved helper functions to own module
---
cmk_base/packaging.py | 13 ++++---
cmk_base/utils.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
modules/automation.py | 3 +-
modules/check_mk_base.py | 67 +++---------------------------------
4 files changed, 103 insertions(+), 69 deletions(-)
diff --git a/cmk_base/packaging.py b/cmk_base/packaging.py
index 98d476e..5d5943e 100644
--- a/cmk_base/packaging.py
+++ b/cmk_base/packaging.py
@@ -38,6 +38,8 @@ import cmk.paths
import cmk.log
logger = cmk.log.get_logger(__name__)
+import cmk_base.utils
+
pac_ext = ".mkp"
# TODO: Subclass MKGeneralException()?
@@ -528,16 +530,16 @@ def verify_check_mk_version(package):
min_version = package["version.min_required"]
cmk_version = cmk.__version__
- if is_daily_build_version(min_version):
- min_branch = branch_of_daily_build(min_version)
+ if cmk_base.utils.is_daily_build_version(min_version):
+ min_branch = cmk_base.utils.branch_of_daily_build(min_version)
if min_branch == "master":
return # can not check exact version
else:
# use the branch name (e.g. 1.2.8 as min version)
min_version = min_branch
- if is_daily_build_version(cmk_version):
- branch = branch_of_daily_build(cmk_version)
+ if cmk_base.utils.is_daily_build_version(cmk_version):
+ branch = cmk_base.utils.branch_of_daily_build(cmk_version)
if branch == "master":
return # can not check exact version
else:
@@ -546,7 +548,8 @@ def verify_check_mk_version(package):
compatible = True
try:
- compatible = parse_check_mk_version(min_version) <= parse_check_mk_version(cmk_version)
+ compatible = cmk_base.utils.parse_check_mk_version(min_version) \
+ <= cmk_base.utils.parse_check_mk_version(cmk_version)
except:
# Be compatible: When a version can not be parsed, then skip this check
if cmk.debug.enabled():
diff --git a/cmk_base/utils.py b/cmk_base/utils.py
new file mode 100644
index 0000000..36ecde2
--- /dev/null
+++ b/cmk_base/utils.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 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.
+
+"""This is an unsorted collection of functions which are needed in
+Check_MK modules and/or cmk_base modules code."""
+
+# TODO: Try to find a better place for them.
+
+
+# Works with Check_MK version (without tailing .cee and/or .demo)
+def is_daily_build_version(v):
+ return len(v) == 10 or '-' in v
+
+
+# Works with Check_MK version (without tailing .cee and/or .demo)
+def branch_of_daily_build(v):
+ if len(v) == 10:
+ return "master"
+ else:
+ return v.split('-')[0]
+
+
+# Parses versions of Check_MK and converts them into comparable integers.
+# This does not handle daily build numbers, only official release numbers.
+# 1.2.4p1 -> 01020450001
+# 1.2.4 -> 01020450000
+# 1.2.4b1 -> 01020420100
+# 1.2.3i1p1 -> 01020310101
+# 1.2.3i1 -> 01020310100
+# TODO: Copied to werks.py - find location for common code.
+def parse_check_mk_version(v):
+ def extract_number(s):
+ number = ''
+ for i, c in enumerate(s):
+ try:
+ int(c)
+ number += c
+ except ValueError:
+ s = s[i:]
+ return number and int(number) or 0, s
+ return number and int(number) or 0, ''
+
+ parts = v.split('.')
+ while len(parts) < 3:
+ parts.append("0")
+
+ major, minor, rest = parts
+ sub, rest = extract_number(rest)
+
+ if not rest:
+ val = 50000
+ elif rest[0] == 'p':
+ num, rest = extract_number(rest[1:])
+ val = 50000 + num
+ elif rest[0] == 'i':
+ num, rest = extract_number(rest[1:])
+ val = 10000 + num*100
+
+ if rest and rest[0] == 'p':
+ num, rest = extract_number(rest[1:])
+ val += num
+ elif rest[0] == 'b':
+ num, rest = extract_number(rest[1:])
+ val = 20000 + num*100
+
+ return int('%02d%02d%02d%05d' % (int(major), int(minor), sub, val))
diff --git a/modules/automation.py b/modules/automation.py
index 5705e95..0768f98 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -1155,8 +1155,7 @@ def automation_create_or_edit_package(args, mode):
def automation_install_package(args):
import cmk_base.packaging
- file_content = sys.stdin.read()
- input_file = fake_file(file_content)
+ input_file = StringIO(sys.stdin.read())
try:
return cmk_base.packaging.install_package(file_object=input_file)
except Exception, e:
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 37ab13e..046d1fa 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -61,6 +61,7 @@ import cmk.crash_reporting as crash_reporting
import cmk.paths
import cmk_base.agent_simulator
+import cmk_base.utils
# PLANNED CLEANUP:
# - central functions for outputting verbose information and bailing
@@ -1308,10 +1309,10 @@ def is_expected_agent_version(agent_version, expected_version):
elif type(expected_version) == tuple and expected_version[0] == 'at_least':
spec = expected_version[1]
- if is_daily_build_version(agent_version) and 'daily_build' in spec:
+ if cmk_base.utils.is_daily_build_version(agent_version) and 'daily_build' in spec:
expected = int(spec['daily_build'].replace('.', ''))
- branch = branch_of_daily_build(agent_version)
+ branch = cmk_base.utils.branch_of_daily_build(agent_version)
if branch == "master":
agent = int(agent_version.replace('.', ''))
@@ -1322,7 +1323,8 @@ def is_expected_agent_version(agent_version, expected_version):
return False
elif 'release' in spec:
- if parse_check_mk_version(agent_version) < parse_check_mk_version(spec['release']):
+ if cmk_base.utils.parse_check_mk_version(agent_version) \
+ < cmk_base.utils.parse_check_mk_version(spec['release']):
return False
return True
@@ -1333,65 +1335,6 @@ def is_expected_agent_version(agent_version, expected_version):
(agent_version, expected_version, e))
-# Works with Check_MK version (without tailing .cee and/or .demo)
-def is_daily_build_version(v):
- return len(v) == 10 or '-' in v
-
-
-# Works with Check_MK version (without tailing .cee and/or .demo)
-def branch_of_daily_build(v):
- if len(v) == 10:
- return "master"
- else:
- return v.split('-')[0]
-
-
-# Parses versions of Check_MK and converts them into comparable integers.
-# This does not handle daily build numbers, only official release numbers.
-# 1.2.4p1 -> 01020450001
-# 1.2.4 -> 01020450000
-# 1.2.4b1 -> 01020420100
-# 1.2.3i1p1 -> 01020310101
-# 1.2.3i1 -> 01020310100
-# TODO: Copied to werks.py - find location for common code.
-def parse_check_mk_version(v):
- def extract_number(s):
- number = ''
- for i, c in enumerate(s):
- try:
- int(c)
- number += c
- except ValueError:
- s = s[i:]
- return number and int(number) or 0, s
- return number and int(number) or 0, ''
-
- parts = v.split('.')
- while len(parts) < 3:
- parts.append("0")
-
- major, minor, rest = parts
- sub, rest = extract_number(rest)
-
- if not rest:
- val = 50000
- elif rest[0] == 'p':
- num, rest = extract_number(rest[1:])
- val = 50000 + num
- elif rest[0] == 'i':
- num, rest = extract_number(rest[1:])
- val = 10000 + num*100
-
- if rest and rest[0] == 'p':
- num, rest = extract_number(rest[1:])
- val += num
- elif rest[0] == 'b':
- num, rest = extract_number(rest[1:])
- val = 20000 + num*100
-
- return int('%02d%02d%02d%05d' % (int(major), int(minor), sub, val))
-
-
# Loops over all checks for a host, gets the data, calls the check
# function that examines that data and sends the result to the Core.
def do_all_checks_on_host(hostname, ipaddress, only_check_types = None, fetch_agent_version = True):
Module: check_mk
Branch: master
Commit: ea0549ddd1a6891fa6172a5f6d7e263eba5d417f
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ea0549ddd1a689…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Oct 18 14:57:50 2016 +0200
Reenabled opt_verbose for compatibility until it has been removed completely
---
modules/check_mk.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 3679f3d..05c2f74 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -4661,6 +4661,7 @@ for o,a in opts:
# -v/--verbose is handled above manually. Simply ignore it here.
if o in [ '-v', '--verbose' ]:
_verbosity += 1
+ opt_verbose += 1 # TODO: Remove this once opt_verbose usage has been removed
elif o in [ '-f', '--force' ]:
opt_force = True
elif o == '-c':
Module: check_mk
Branch: master
Commit: 19e5d92f45f0cbf3612dbff575a89b1e104a71e4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=19e5d92f45f0cb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 18 14:44:00 2016 +0200
Reorder option in ESXi datasource program rule set
Group related options better.
---
web/plugins/wato/datasource_programs.py | 90 ++++++++++++++++-----------------
1 file changed, 45 insertions(+), 45 deletions(-)
diff --git a/web/plugins/wato/datasource_programs.py b/web/plugins/wato/datasource_programs.py
index 3aa4932..02c94d1 100644
--- a/web/plugins/wato/datasource_programs.py
+++ b/web/plugins/wato/datasource_programs.py
@@ -60,6 +60,18 @@ register_rule(group,
allow_empty = False,
)
),
+ ( "direct",
+ DropdownChoice(
+ title = _("Type of query"),
+ choices = [
+ ( True, _("Queried host is a host system" ) ),
+ ( "hostsystem_agent", _("Queried host is a host system with Check_MK Agent installed") ),
+ ( False, _("Queried host is the vCenter") ),
+ ( "agent", _("Queried host is the vCenter with Check_MK Agent installed") ),
+ ],
+ default = True,
+ )
+ ),
( "tcp_port",
Integer(
title = _("TCP Port number"),
@@ -93,6 +105,17 @@ register_rule(group,
unit = _("seconds"),
)
),
+ ( "use_pysphere",
+ Checkbox(
+ title = _("Compatibility mode"),
+ label = _("Support ESX 4.1 (using slower PySphere implementation)"),
+ true_label = _("Support 4.1"),
+ false_label = _("fast"),
+ help = _("The current very performant implementation of the ESX special agent "
+ "does not support older ESX versions than 5.0. Please use the slow "
+ "compatibility mode for those old hosts."),
+ )
+ ),
( "infos",
Transform(
ListChoice(
@@ -110,6 +133,18 @@ register_rule(group,
title = _("Retrieve information about..."),
)
),
+ ( "skip_placeholder_vms",
+ Checkbox(
+ title = _("Placeholder VMs"),
+ label = _("Do no monitor placeholder VMs"),
+ default_value = True,
+ true_label = _("ignore"),
+ false_label = _("monitor"),
+ help = _("Placeholder VMs are created by the Site Recovery Manager(SRM) and act as backup "
+ "virtual machines in case the default vm is unable to start. This option tells the "
+ "vsphere agent to exclude placeholder vms in its output."
+ ))
+ ),
( "host_pwr_display",
DropdownChoice(
title = _("Display ESX Host power state on"),
@@ -121,16 +156,6 @@ register_rule(group,
default = None,
)
),
- ( "vm_piggyname",
- DropdownChoice(
- title = _("Piggyback name of virtual machines"),
- choices = [
- ( "alias", _("Use the name specified in the ESX system") ),
- ( "hostname", _("Use the VMs hostname if set, otherwise fall back to ESX name") ),
- ],
- default = "alias",
- )
- ),
( "vm_pwr_display",
DropdownChoice(
title = _("Display VM power state on"),
@@ -142,6 +167,16 @@ register_rule(group,
default = None,
)
),
+ ( "vm_piggyname",
+ DropdownChoice(
+ title = _("Piggyback name of virtual machines"),
+ choices = [
+ ( "alias", _("Use the name specified in the ESX system") ),
+ ( "hostname", _("Use the VMs hostname if set, otherwise fall back to ESX name") ),
+ ],
+ default = "alias",
+ )
+ ),
( "spaces",
DropdownChoice(
title = _("Spaces in hostnames"),
@@ -152,41 +187,6 @@ register_rule(group,
default = "underscore",
)
),
- ( "direct",
- DropdownChoice(
- title = _("Type of query"),
- choices = [
- ( True, _("Queried host is a host system" ) ),
- ( "hostsystem_agent", _("Queried host is a host system with Check_MK Agent installed") ),
- ( False, _("Queried host is the vCenter") ),
- ( "agent", _("Queried host is the vCenter with Check_MK Agent installed") ),
- ],
- default = True,
- )
- ),
- ( "skip_placeholder_vms",
- Checkbox(
- title = _("Placeholder VMs"),
- label = _("Do no monitor placeholder VMs"),
- default_value = True,
- true_label = _("ignore"),
- false_label = _("monitor"),
- help = _("Placeholder VMs are created by the Site Recovery Manager(SRM) and act as backup "
- "virtual machines in case the default vm is unable to start. This option tells the "
- "vsphere agent to exclude placeholder vms in its output."
- ))
- ),
- ( "use_pysphere",
- Checkbox(
- title = _("Compatibility mode"),
- label = _("Support ESX 4.1 (using slower PySphere implementation)"),
- true_label = _("Support 4.1"),
- false_label = _("fast"),
- help = _("The current very performant implementation of the ESX special agent "
- "does not support older ESX versions than 5.0. Please use the slow "
- "compatibility mode for those old hosts."),
- )
- ),
],
optional_keys = [ "tcp_port", "timeout", "vm_pwr_display", "host_pwr_display", "vm_piggyname" ],
),