Пример #1
0
    def discovery_migration_wrapper(section):
        disco_func = check_info_dict.get("inventory_function")
        if not callable(disco_func):  # never discover:
            return

        original_discovery_result = disco_func(section)
        if not original_discovery_result:
            return

        for element in original_discovery_result:
            if isinstance(element, tuple) and len(element) in (2, 3):
                parameters = _resolve_string_parameters(
                    element[-1], check_name, get_check_context)
                service = Service(
                    item=element[0] or None,
                    parameters=wrap_parameters(parameters or {}),
                )
                # nasty hack for nasty plugins:
                # Bypass validation. Item should be None or non-empty string!
                service = service._replace(item=element[0])
                yield service
            else:
                try:
                    yield Service(
                        item=element.item,
                        parameters=wrap_parameters(element.parameters or {}),
                        labels=[
                            ServiceLabel(l.name, l.value)
                            for l in element.service_labels
                        ],
                    )
                except AttributeError:
                    # just let it through. Base must deal with bogus return types anyway.
                    yield element
Пример #2
0
    def discovery_migration_wrapper(section):
        disco_func = check_info_dict.get("inventory_function")
        if not callable(disco_func):  # never discover:
            return

        original_discovery_result = disco_func(section)
        if not original_discovery_result:
            return

        for element in original_discovery_result:
            if isinstance(element, tuple) and len(element) in (2, 3):
                item, raw_params = element[0], element[-1]
                if item is not None and not isinstance(item, str):
                    raise ValueError("item must be None or of type `str`")

                parameters = _resolve_string_parameters(
                    raw_params, check_name, get_check_context)
                service = Service(
                    item=None,  # will be replaced
                    parameters=wrap_parameters(parameters or {}),
                )
                # nasty hack for nasty plugins: item = ''
                # Bypass validation. Item should be None or non-empty string!
                service = service._replace(item=item)
                yield service
                continue

            with suppress(AttributeError):
                yield Service(
                    item=element.item,
                    parameters=wrap_parameters(element.parameters or {}),
                    labels=[
                        ServiceLabel(l.name, l.value)
                        for l in element.service_labels
                    ],
                )
                continue

            # just let it through. Base must deal with bogus return types anyway.
            yield element