示例#1
0
def _agent_cache_file_age(
        hostname: HostName,
        check_plugin_name: CheckPluginNameStr) -> Optional[float]:
    host_config = _config.get_config_cache().get_host_config(hostname)
    if host_config.is_cluster:
        raise MKGeneralException("get_agent_data_time() not valid for cluster")

    # NOTE: This is a workaround for the 'old' API and will not be correct
    # for the new one. This is a check plugin name, and the property of being
    # 'TCP' or 'SNMP' is a property of the section.
    # This function is deprecated for new plugins.
    # For old-style plugins, plugin and section name are same, so check the
    # corresponding section:
    section_name_str = _cmk_utils.check_utils.section_name_of(
        check_plugin_name)
    section = _agent_based_register.get_section_plugin(
        _SectionName(section_name_str))
    if hasattr(section, "trees"):
        cachefile = "%s/%s.%s" % (_paths.tcp_cache_dir, hostname,
                                  section_name_str)
    else:
        cachefile = "%s/%s" % (_paths.tcp_cache_dir, hostname)

    if os.path.exists(cachefile):
        return _cmk_utils.cachefile_age(cachefile)

    return None
示例#2
0
 def deserialize(cls, serialized: Mapping[str, Any]) -> "SNMPHostConfig":
     serialized_ = copy.deepcopy(dict(serialized))
     serialized_["snmp_backend"] = SNMPBackendEnum.deserialize(serialized_["snmp_backend"])
     serialized_["oid_range_limits"] = {
         _SectionName(sn): rl for sn, rl in serialized_["oid_range_limits"].items()
     }
     return cls(**serialized_)