33# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
44# conditions defined in the file COPYING, which is part of this source code package.
55import importlib
6+ import importlib .resources
67import re
78import sys
89from collections .abc import Generator
1213from types import ModuleType
1314from typing import Final , get_args
1415
16+ import cmk .base .core .nagios # astrein: disable=cmk-module-layer-violation
1517from cmk .base .core .nagios import HostCheckConfig # astrein: disable=cmk-module-layer-violation
1618from cmk .ccc .hostaddress import HostAddress , HostName # astrein: disable=cmk-module-layer-violation
1719from cmk .discover_plugins import PluginLocation # astrein: disable=cmk-module-layer-violation
@@ -96,11 +98,6 @@ def list_agent_based_plugins(self) -> dict[str, list[str]]:
9698
9799 def dump_host_check_file (self ) -> None :
98100 """Creates a host check file which loads all agent based plugins"""
99-
100- template_file : Path = (
101- self .omd_root / "lib/python3/cmk/base/core/nagios/_host_check_template.py"
102- )
103-
104101 plugin_locations = [
105102 PluginLocation (module = module_name , name = plugin_name )
106103 for module_name , plugin_names in self .agent_based_plugins .items ()
@@ -120,7 +117,9 @@ def dump_host_check_file(self) -> None:
120117 ipv6addresses = {},
121118 hostname = self .host_name ,
122119 )
123- template_text = template_file .read_text (encoding = "utf-8" )
120+ template_text = importlib .resources .read_text (
121+ cmk .base .core .nagios , "_host_check_template.py" , encoding = "utf-8"
122+ )
124123 startpos = template_text .find ("CONFIG = HostCheckConfig(" )
125124 endpos = template_text .find (")\n " , startpos ) + 1
126125 replacement = f"CONFIG = { pformat (host_check_config )} "
0 commit comments