Exemple #1
0
def _update_single_service_phase(
    target_phase: str,
    host: watolib.CREHost,
    check_type: str,
    service_item: str,
) -> None:
    discovery = Discovery(
        host=host,
        discovery_options=DiscoveryOptions(
            action=DiscoveryAction.SINGLE_UPDATE,
            show_checkboxes=False,
            show_parameters=False,
            show_discovered_labels=False,
            show_plugin_names=False,
            ignore_errors=True,
        ),
        api_request={
            "update_target": target_phase,
            "update_services": [checkbox_id(
                check_type,
                service_item,
            )]
        },
    )
    discovery.execute_discovery()
Exemple #2
0
def serialize_service_discovery(host, discovered_services, discovery_state):
    members = {}
    for (table_source, check_type, _checkgroup, item, _discovered_params,
         _check_params, descr, _service_state, _output, _perfdata,
         _service_labels) in discovered_services:

        if table_source == SERVICE_DISCOVERY_STATES[discovery_state]:
            service_hash = checkbox_id(check_type, item)
            members[service_hash] = {
                "service_name":
                descr,
                "check_plugin_name":
                check_type,
                "state":
                object_property(
                    name=descr,
                    title="The service is currently %s" % discovery_state,
                    value=table_source,
                    prop_format='string',
                    base='',
                    links=[
                        link_rel(
                            rel="cmk/service.move-monitored",
                            href=
                            "/objects/host/%s/service/%s/action/move/monitored"
                            % (host.ident(), service_hash),
                            method='put',
                            title='Move the service to monitored'),
                        link_rel(
                            rel="cmk/service.move-undecided",
                            href=
                            "/objects/host/%s/service/%s/action/move/undecided"
                            % (host.ident(), service_hash),
                            method='put',
                            title='Move the service to undecided'),
                        link_rel(
                            rel="cmk/service.move-ignored",
                            href=
                            "/objects/host/%s/service/%s/action/move/ignored" %
                            (host.ident(), service_hash),
                            method='put',
                            title='Move the service to ignored'),
                    ]),
            }

    return domain_object(
        domain_type='service_discovery',
        identifier='%s-services-%s' % (host.ident(), "wato"),
        title='Services discovery',
        members=members,
        extensions={},
    )