2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # Future convention within all Check_MK modules for variable names:
29 # - host_name - Monitoring name of a host (string)
30 # - node_name - Name of cluster member (string)
31 # - cluster_name - Name of a cluster (string)
32 # - realhost_name - Name of a *real* host, not a cluster (string)
38 # Needs to be placed before cmk modules, because they are not available
39 # when executed as non site user. Alas, this screws up our import ordering
40 # a bit, so we have to tell pylint about that.
41 # pylint: disable=wrong-import-position
42 if not os
.environ
.get("OMD_SITE"):
43 sys
.stderr
.write("Check_MK can be used only as site user.\n")
46 from cmk
.utils
.exceptions
import MKGeneralException
, MKTerminate
, MKBailOut
47 import cmk
.utils
.debug
49 import cmk
.utils
.paths
52 import cmk_base
.console
as console
53 import cmk_base
.config
as config
54 import cmk_base
.profiling
as profiling
55 from cmk_base
.modes
import modes
56 import cmk_base
.check_api
as check_api
58 cmk
.utils
.log
.setup_console_logging()
59 logger
= cmk
.utils
.log
.get_logger("base")
61 cmk_base
.utils
.register_sigint_handler()
64 opts
, args
= getopt
.getopt(sys
.argv
[1:], modes
.short_getopt_specs(), modes
.long_getopt_specs())
65 except getopt
.GetoptError
, err
:
66 console
.error("ERROR: %s\n\n" % err
)
67 modes
.get("help").handler_function()
70 # First load the general modifying options
71 modes
.process_general_options(opts
)
74 # At least in case the config is needed, the checks are needed too, because
75 # the configuration may refer to check config variable names.
76 if len(set.intersection(set(modes
.non_checks_options()), [o
[0] for o
in opts
])) == 0:
77 config
.load_all_checks(check_api
.get_check_api_context
)
79 # Read the configuration files (main.mk, autochecks, etc.), but not for
80 # certain operation modes that does not need them and should not be harmed
81 # by a broken configuration
82 if len(set.intersection(set(modes
.non_config_options()), [o
[0] for o
in opts
])) == 0:
85 # Now find the requested mode and execute it
86 done
, exit_status
= False, 0
89 exit_status
= modes
.call(o
, a
, opts
, args
)
93 # When no mode was found, Check_MK is running the "check" mode
95 if (args
and len(args
) <= 2) or "--keepalive" in [o
[0] for o
in opts
]:
96 exit_status
= modes
.call("--check", None, opts
, args
)
98 modes
.get("help").handler_function()
101 profiling
.output_profile()
102 sys
.exit(exit_status
)
104 except MKTerminate
, e
:
105 console
.output("<Interrupted>\n", stream
=sys
.stderr
)
108 except (MKGeneralException
, MKBailOut
), e
:
109 sys
.stderr
.write("%s\n" % e
)
110 if cmk
.utils
.debug
.enabled():