def _read_agent_output(hostname): # type: (str) -> Optional[Text] try: import cmk.base.cee.real_time_checks as real_time_checks except ImportError: real_time_checks = None # type: ignore if real_time_checks and real_time_checks.is_real_time_check_helper(): rtc_package = real_time_checks.get_rtc_package() if rtc_package is not None: return cmk.utils.encoding.convert_to_unicode(rtc_package) return None cache_path = Path(cmk.utils.paths.tcp_cache_dir, hostname) try: # Use similar decoding logic as cmk.base/data_sources/abstract.py does. In case this is not # working as intended, we may have to keep working with bytes here. with cache_path.open() as f: output = u"" for l in f: output += cmk.utils.encoding.convert_to_unicode(l) return output except IOError: pass return None
def _read_agent_output(hostname): # type: (str) -> Optional[RawAgentData] try: import cmk.base.cee.real_time_checks as real_time_checks # pylint: disable=import-outside-toplevel except ImportError: real_time_checks = None # type: ignore[assignment] if real_time_checks and real_time_checks.is_real_time_check_helper(): return real_time_checks.get_rtc_package() cache_path = Path(cmk.utils.paths.tcp_cache_dir, hostname) try: with cache_path.open(mode="rb") as f: return f.read() except IOError: pass return None