2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2016 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.
26 """This module serves the path structure of the Check_MK environment
27 to all components of Check_MK."""
32 # First declare the possible paths for the linters. Then set it within _set_paths()
35 # TODO: Add piggyback_dir and use it in code
36 omd_root
= '' # type: str
37 default_config_dir
= '' # type: str
38 main_config_file
= None
39 final_config_file
= None
40 local_config_file
= None
41 check_mk_config_dir
= None
45 precompiled_checks_dir
= None
47 precompiled_hostchecks_dir
= None
51 data_source_cache_dir
= None
52 snmp_scan_cache_dir
= None
53 include_cache_dir
= None
56 nagios_objects_file
= None
57 nagios_command_pipe_path
= None
58 check_result_path
= None
59 nagios_status_file
= None
60 nagios_conf_dir
= None
61 nagios_config_file
= None
62 nagios_startscript
= None
64 apache_config_dir
= None
66 livestatus_unix_socket
= None
67 pnp_rraconf_dir
= None
68 livebackendsdir
= None
72 notifications_dir
= None
74 check_manpages_dir
= None
78 pnp_templates_dir
= None
80 locale_dir
= '' # type: str
85 # TODO: Add active_checks_dir and make it used in code
88 local_notifications_dir
= ''
89 local_inventory_dir
= ''
90 local_check_manpages_dir
= ''
94 local_pnp_templates_dir
= ''
100 inventory_output_dir
= ''
101 inventory_archive_dir
= ''
107 omd_root
= _omd_root()
110 "default_config_dir": os
.path
.join(omd_root
, "etc/check_mk"),
111 "main_config_file": os
.path
.join(omd_root
, "etc/check_mk/main.mk"),
112 "final_config_file": os
.path
.join(omd_root
, "etc/check_mk/final.mk"),
113 "local_config_file": os
.path
.join(omd_root
, "etc/check_mk/local.mk"),
114 "check_mk_config_dir": os
.path
.join(omd_root
, "etc/check_mk/conf.d"),
115 "modules_dir": os
.path
.join(omd_root
, "share/check_mk/modules"),
116 "var_dir": os
.path
.join(omd_root
, "var/check_mk"),
117 "log_dir": os
.path
.join(omd_root
, "var/log"),
118 "precompiled_checks_dir": os
.path
.join(omd_root
, "var/check_mk/precompiled_checks"),
119 "autochecks_dir": os
.path
.join(omd_root
, "var/check_mk/autochecks"),
120 "precompiled_hostchecks_dir": os
.path
.join(omd_root
, "var/check_mk/precompiled"),
121 "snmpwalks_dir": os
.path
.join(omd_root
, "var/check_mk/snmpwalks"),
122 "counters_dir": os
.path
.join(omd_root
, "tmp/check_mk/counters"),
123 "tcp_cache_dir": os
.path
.join(omd_root
, "tmp/check_mk/cache"),
124 "data_source_cache_dir": os
.path
.join(omd_root
, "tmp/check_mk/data_source_cache"),
125 "snmp_scan_cache_dir": os
.path
.join(omd_root
, "tmp/check_mk/snmp_scan_cache"),
126 "include_cache_dir": os
.path
.join(omd_root
, "tmp/check_mk/check_includes"),
127 "tmp_dir": os
.path
.join(omd_root
, "tmp/check_mk"),
128 "logwatch_dir": os
.path
.join(omd_root
, "var/check_mk/logwatch"),
129 "nagios_startscript": os
.path
.join(omd_root
, "etc/init.d/core"),
131 # Switched via symlinks on icinga/nagios change
132 "nagios_conf_dir": os
.path
.join(omd_root
, "etc/nagios/conf.d"),
133 "nagios_objects_file": os
.path
.join(omd_root
, "etc/nagios/conf.d/check_mk_objects.cfg"),
134 "check_result_path": os
.path
.join(omd_root
, "tmp/nagios/checkresults"),
135 "nagios_status_file": os
.path
.join(omd_root
, "tmp/nagios/status.dat"),
136 "apache_config_dir": os
.path
.join(omd_root
, "etc/apache"),
137 "htpasswd_file": os
.path
.join(omd_root
, "etc/htpasswd"),
138 "livestatus_unix_socket": os
.path
.join(omd_root
, "tmp/run/live"),
139 "pnp_rraconf_dir": os
.path
.join(omd_root
, "share/check_mk/pnp-rraconf"),
140 "livebackendsdir": os
.path
.join(omd_root
, "share/check_mk/livestatus"),
141 "inventory_output_dir": os
.path
.join(omd_root
, "var/check_mk/inventory"),
142 "inventory_archive_dir": os
.path
.join(omd_root
, "var/check_mk/inventory_archive"),
143 "status_data_dir": os
.path
.join(omd_root
, "tmp/check_mk/status_data"),
146 _set_core_specific_paths()
147 _set_overridable_paths()
148 _set_overridable_paths(local
=True)
152 return os
.environ
.get("OMD_ROOT", "")
155 def _set_core_specific_paths():
156 core
= _get_core_name()
160 "nagios_binary": os
.path
.join(omd_root
, "bin/icinga"),
161 "nagios_config_file": os
.path
.join(omd_root
, "tmp/icinga/icinga.cfg"),
162 "nagios_command_pipe_path": os
.path
.join(omd_root
, "tmp/run/icinga.cmd"),
166 "nagios_binary": os
.path
.join(omd_root
, "bin/nagios"),
167 "nagios_config_file": os
.path
.join(omd_root
, "tmp/nagios/nagios.cfg"),
168 "nagios_command_pipe_path": os
.path
.join(omd_root
, "tmp/run/nagios.cmd"),
172 # TODO: Find a better way to determine the currently configured core.
173 # For example generalize the etc/check_mk/conf.d/microcore.mk which is written by the CORE
174 # hook -> Change the name to core.mk and write it for all configured cores.
175 def _get_core_name():
177 for l
in open(os
.path
.join(omd_root
, "etc/omd/site.conf")):
178 if l
.startswith("CONFIG_CORE='"):
179 return l
.split("'")[1]
181 # At least in test environment the file is not available. We only added this try/except for
182 # this case. This should better be solved in a cleaner way.
189 def _set_overridable_paths(local
=False):
190 rel_base
= "local" if local
else ""
191 var_prefix
= "local_" if local
else ""
194 var_prefix
+ "share_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk"),
195 var_prefix
+ "checks_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/checks"),
196 var_prefix
+ "notifications_dir": os
.path
.join(omd_root
, rel_base
,
197 "share/check_mk/notifications"),
198 var_prefix
+ "inventory_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/inventory"),
199 var_prefix
+ "check_manpages_dir": os
.path
.join(omd_root
, rel_base
,
200 "share/check_mk/checkman"),
201 var_prefix
+ "agents_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/agents"),
202 var_prefix
+ "mibs_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/mibs"),
203 var_prefix
+ "web_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/web"),
204 var_prefix
+ "pnp_templates_dir": os
.path
.join(omd_root
, rel_base
,
205 "share/check_mk/pnp-templates"),
206 var_prefix
+ "doc_dir": os
.path
.join(omd_root
, rel_base
, "share/doc/check_mk"),
207 var_prefix
+ "locale_dir": os
.path
.join(omd_root
, rel_base
, "share/check_mk/locale"),
208 var_prefix
+ "bin_dir": os
.path
.join(omd_root
, rel_base
, "bin"),
209 var_prefix
+ "lib_dir": os
.path
.join(omd_root
, rel_base
, "lib"),
210 var_prefix
+ "mib_dir": os
.path
.join(omd_root
, rel_base
, "share/snmp/mibs"),