Esempio n. 1
0
def parse_and_validate(msg, valid_periods, require_all=False):
    try:
        request_body_schema(msg)
    except Exception as ex:
        LOG.exception(ex)
        raise exceptions.ValidationException(str(ex))

    if 'period' not in msg:
        if require_all:
            raise exceptions.ValidationException("Period is required")
        else:
            msg['period'] = 0
    else:
        msg['period'] = _parse_and_validate_period(msg['period'],
                                                   valid_periods)

    notification_type = str(msg['type']).upper()

    if notification_type == 'EMAIL':
        _validate_email(msg['address'])
    elif notification_type == 'WEBHOOK':
        _validate_url(msg['address'])

    if notification_type != 'WEBHOOK' and msg['period'] != 0:
        raise exceptions.ValidationException(
            "Period can only be set with webhooks")
def _parse_and_validate_period(period, valid_periods):
    try:
        period = int(period)
    except Exception:
        raise exceptions.ValidationException("Period {} must be a valid integer".format(period))
    if period != 0 and period not in valid_periods:
        raise exceptions.ValidationException("{} is not a valid period".format(period))
    return period
def _validate_url(address):
    try:
        parsed = urlparse.urlparse(address)
    except Exception:
        raise exceptions.ValidationException("Address {} is not of correct format".format(address))

    if not parsed.scheme:
        raise exceptions.ValidationException("Address {} does not have URL scheme".format(address))
    if not parsed.netloc:
        raise exceptions.ValidationException("Address {} does not have network location"
                                             .format(address))
    if parsed.scheme not in schemes:
        raise exceptions.ValidationException("Address {} scheme is not in {}"
                                             .format(address, schemes))
def validate(msg, require_all=False):
    try:
        request_body_schema = Schema(alarm_definition_schema,
                                     required=require_all,
                                     extra=True)
        request_body_schema(msg)
    except Exception as ex:
        LOG.debug(ex)
        raise exceptions.ValidationException(str(ex))
def validate(msg):
    try:
        request_body_schema(msg)
    except Exception as ex:
        LOG.debug(ex)
        raise exceptions.ValidationException(str(ex))

    notification_type = str(msg['type']).upper()
    if notification_type == 'EMAIL':
        _validate_email(msg['address'])
    elif notification_type == 'WEBHOOK':
        _validate_url(msg['address'])
Esempio n. 6
0
def validate(name):
    try:
        metric_name_schema(name)
    except Exception as ex:
        LOG.debug(ex)
        raise exceptions.ValidationException(str(ex))
Esempio n. 7
0
def _validate_email(address):
    if not validation.validate_email_address(address):
        raise exceptions.ValidationException(
            "Address {} is not of correct format".format(address))
Esempio n. 8
0
def validate(msg):
    try:
        request_body_schema(msg)
    except Exception as ex:
        LOG.debug(ex)
        raise exceptions.ValidationException(str(ex))
Esempio n. 9
0
def validate(dimensions):
    try:
        dimensions_schema(dimensions)
    except Exception as ex:
        LOG.debug(ex)
        raise exceptions.ValidationException(str(ex))