def serialize_host(host: watolib.CREHost, effective_attributes: bool): extensions = { "folder": host.folder().path(), "attributes": host.attributes(), "effective_attributes": host.effective_attributes() if effective_attributes else None, "is_cluster": host.is_cluster(), "is_offline": host.is_offline(), "cluster_nodes": host.cluster_nodes(), } return constructors.domain_object( domain_type="host_config", identifier=host.id(), title=host.alias() or host.name(), links=[ constructors.link_rel( rel="cmk/folder_config", href=constructors.object_href("folder_config", folder_slug(host.folder())), method="get", title="The folder config of the host.", ), ], extensions=extensions, )
def serialize_host(host: watolib.CREHost, effective_attributes: bool): extensions = { 'folder': host.folder().path(), 'attributes': host.attributes(), 'effective_attributes': host.effective_attributes() if effective_attributes else None, 'is_cluster': host.is_cluster(), 'is_offline': host.is_offline(), 'cluster_nodes': host.cluster_nodes(), } return constructors.domain_object( domain_type='host_config', identifier=host.id(), title=host.alias() or host.name(), links=[ constructors.link_rel( rel='cmk/folder_config', href=constructors.object_href('folder_config', folder_slug(host.folder())), method='get', title='The folder config of the host.', ), ], extensions=extensions, )
def etag_of_host(host: watolib.CREHost) -> ETags: # FIXME: Through some not yet fully explored effect, we do not get the actual persisted # timestamp in the meta_data section but rather some other timestamp. This makes the # reported ETag a different one than the one which is accepted by the endpoint. return constructors.etag_of_dict({ "name": host.name(), "attributes": _except_keys(host.attributes(), ["meta_data"]), "cluster_nodes": host.cluster_nodes(), })
def serialize_host(host: watolib.CREHost, effective_attributes: bool): if effective_attributes: attributes = host.effective_attributes() else: attributes = host.attributes() if 'meta_data' in attributes: attributes = attributes.copy() del attributes['meta_data'] return constructors.domain_object( domain_type='host_config', identifier=host.id(), title=host.alias(), links=[ constructors.link_rel( rel='cmk/folder_config', href=constructors.object_href('folder_config', folder_slug(host.folder())), method='get', title='The folder config of the host.', ), ], extensions={ 'attributes': attributes, 'is_cluster': host.is_cluster(), 'is_offline': host.is_offline(), 'cluster_nodes': host.cluster_nodes(), }, )
def serialize_host(host: watolib.CREHost, effective_attributes: bool): extensions = { "folder": host.folder().path(), "attributes": host.attributes(), "effective_attributes": host.effective_attributes() if effective_attributes else None, "is_cluster": host.is_cluster(), "is_offline": host.is_offline(), "cluster_nodes": host.cluster_nodes(), } agent_links = [] if not cmk_version.is_raw_edition(): import cmk.gui.cee.agent_bakery as agent_bakery # pylint: disable=no-name-in-module for agent_type in sorted(agent_bakery.agent_package_types().keys()): agent_links.append( constructors.link_rel( rel="cmk/download", href="{}?{}".format( constructors.domain_type_action_href( "agent", "download"), urlencode({ "os_type": agent_type, "host_name": host.id() }), ), method="get", title=f"Download the {agent_type} agent of the host.", )) return constructors.domain_object( domain_type="host_config", identifier=host.id(), title=host.alias() or host.name(), links=[ constructors.link_rel( rel="cmk/folder_config", href=constructors.object_href("folder_config", folder_slug(host.folder())), method="get", title="The folder config of the host.", ), ] + agent_links, extensions=extensions, )
def serialize_service_discovery( host: watolib.CREHost, discovered_services: CheckTable, discovery_phases: List[str], ): members = {} host_name = host.name() for entry in discovered_services: (table_source, check_type, _checkgroup, item, _discovered_params, _check_params, descr, _service_phase, _output, _perfdata, _service_labels, _found_on_nodes) = entry if _in_phase(table_source, discovery_phases): service_phase = _lookup_phase_name(table_source) members[f"{check_type}-{item}"] = object_property( name=descr, title=f"The service is currently {service_phase!r}", value=service_phase, prop_format='string', linkable=False, extensions={ "host_name": host_name, "check_plugin_name": check_type, "service_name": descr, "service_item": item, "service_phase": service_phase, }, base='', links=[ link_rel( rel="cmk/service.move-monitored", href=update_service_phase.path.format( host_name=host_name), body_params={ 'target_phase': 'monitored', 'check_type': check_type, 'service_item': item, }, method='put', title='Move the service to monitored', ), link_rel( rel="cmk/service.move-undecided", href=update_service_phase.path.format( host_name=host_name), body_params={ 'target_phase': 'undecided', 'check_type': check_type, 'service_item': item, }, method='put', title='Move the service to undecided', ), link_rel( rel="cmk/service.move-ignored", href=update_service_phase.path.format( host_name=host_name), body_params={ 'target_phase': 'ignored', 'check_type': check_type, 'service_item': item, }, method='put', title='Move the service to ignored', ), ], ) return domain_object( domain_type='service_discovery', identifier=f'{host_name}-services-wato', title='Services discovery', members=members, editable=False, deletable=False, extensions={}, )
def serialize_service_discovery( host: watolib.CREHost, discovered_services: Sequence[CheckPreviewEntry], discovery_phases: List[str], ): members = {} host_name = host.name() for entry in discovered_services: if _in_phase(entry.check_source, discovery_phases): service_phase = _lookup_phase_name(entry.check_source) members[ f"{entry.check_plugin_name}-{entry.item}"] = object_property( name=entry.description, title=f"The service is currently {service_phase!r}", value=service_phase, prop_format="string", linkable=False, extensions={ "host_name": host_name, "check_plugin_name": entry.check_plugin_name, "service_name": entry.description, "service_item": entry.item, "service_phase": service_phase, }, base="", links=[ link_rel( rel="cmk/service.move-monitored", href=update_service_phase.path.format( host_name=host_name), body_params={ "target_phase": "monitored", "check_type": entry.check_plugin_name, "service_item": entry.item, }, method="put", title="Move the service to monitored", ), link_rel( rel="cmk/service.move-undecided", href=update_service_phase.path.format( host_name=host_name), body_params={ "target_phase": "undecided", "check_type": entry.check_plugin_name, "service_item": entry.item, }, method="put", title="Move the service to undecided", ), link_rel( rel="cmk/service.move-ignored", href=update_service_phase.path.format( host_name=host_name), body_params={ "target_phase": "ignored", "check_type": entry.check_plugin_name, "service_item": entry.item, }, method="put", title="Move the service to ignored", ), ], ) return domain_object( domain_type="service_discovery", identifier=f"{host_name}-services-wato", title="Services discovery", members=members, editable=False, deletable=False, extensions={}, )