Пример #1
0
def _validate_detect_spec(detect_spec: SNMPDetectBaseType) -> None:
    if not (isinstance(detect_spec, list)
            and all(isinstance(element, list) for element in detect_spec)):
        raise TypeError(
            "value of 'detect' keyword must be a list of lists of 3-tuples")

    for atom in itertools.chain(*detect_spec):
        if not isinstance(atom, tuple) or not len(atom) == 3:
            raise TypeError(
                "value of 'detect' keyword must be a list of lists of 3-tuples"
            )
        oid_string, expression, expected_match = atom

        if not isinstance(oid_string, str):
            raise TypeError(
                "value of 'detect' keywords first element must be a string: %r"
                % (oid_string, ))
        if not str(oid_string).startswith('.'):
            raise ValueError(
                "OID in value of 'detect' keyword must start with '.': %r" %
                (oid_string, ))
        SNMPTree.validate_oid_string(oid_string.rstrip('.*'))

        if expression is not None:
            try:
                _ = regex(expression)
            except MKGeneralException as exc:
                raise ValueError(
                    "invalid regex in value of 'detect' keyword: %s" % exc)

        if not isinstance(expected_match, bool):
            TypeError(
                "value of 'detect' keywords third element must be a boolean: %r"
                % (expected_match, ))
Пример #2
0
def test_oidspec_invalid_value(value):
    with pytest.raises(ValueError):
        SNMPTree.validate_oid_string(value)