ocs_ci/utility/prometheus.py
def check_alert_list(
    label,
    msg,
    alerts,
    states,
    severity="warning"
):
    """
    Check list of alerts that there are alerts with requested label and
    message for each provided state. If some alert is missing then this check
    fails.

    Args:
        label (str): Alert label
        msg (str): Alert message
        alerts (list): List of alerts to check
        states (list): List of states to check, order is important
    """

    target_alerts = [
        alert
        for alert
        in alerts
        if alert.get('labels').get('alertname') == label
    ]

    logger.info(f"Checking properties of found {label} alerts")
    assert_msg = (
        f"Incorrect number of {label} alerts ({len(target_alerts)} "
        f"instead of {len(states)})"
    )
    assert len(target_alerts) == len(states), assert_msg

    for key, state in enumerate(states):

        assert_msg = 'Alert message for alert {label} is not correct'
        assert target_alerts[key]['annotations']['message'] == msg, assert_msg

        assert_msg = f"Alert {label} doesn't have {severity} severity"
        assert target_alerts[key]['annotations']['severity_level'] == severity, assert_msg

        assert_msg = f"Alert {label} is not in {state} state"
        assert target_alerts[key]['state'] == state, assert_msg

    logger.info(f"Alerts were triggered correctly during utilization")

    Check list of alerts that there are alerts with requested label and
    message for each provided state. If some alert is missing then this check
    fails.

    Args:
        label (str): Alert label
        msg (str): Alert message
        alerts (list): List of alerts to check
        states (list): List of states to check, order is important
    
Check list of alerts that there are alerts with requested label and
message for each provided state. If some alert is missing then this check
fails.
Check list of alerts that there are alerts with requested label and message for each provided state . If some alert is missing then this check fails .
def check_alert_list(
    label,
    msg,
    alerts,
    states,
    severity="warning"
):
    target_alerts = [
        alert
        for alert
        in alerts
        if alert.get('labels').get('alertname') == label
    ]
    logger.info(f"Checking properties of found {label} alerts")
    assert_msg = (
        f"Incorrect number of {label} alerts ({len(target_alerts)} "
        f"instead of {len(states)})"
    )
    assert len(target_alerts) == len(states), assert_msg
    for key, state in enumerate(states):
        assert_msg = 'Alert message for alert {label} is not correct'
        assert target_alerts[key]['annotations']['message'] == msg, assert_msg
        assert_msg = f"Alert {label} doesn't have {severity} severity"
        assert target_alerts[key]['annotations']['severity_level'] == severity, assert_msg
        assert_msg = f"Alert {label} is not in {state} state"
        assert target_alerts[key]['state'] == state, assert_msg
    logger.info(f"Alerts were triggered correctly during utilization")
def check_alert_list ( label , msg , alerts , states , severity = "warning" ) : target_alerts = [ alert for alert in alerts if alert . get ( 'labels' ) . get ( 'alertname' ) == label ] logger . info ( f"Checking properties of found {label} alerts" ) assert_msg = ( f"Incorrect number of {label} alerts ({len(target_alerts)} " f"instead of {len(states)})" ) assert len ( target_alerts ) == len ( states ) , assert_msg for key , state in enumerate ( states ) : assert_msg = 'Alert message for alert {label} is not correct' assert target_alerts [ key ] [ 'annotations' ] [ 'message' ] == msg , assert_msg assert_msg = f"Alert {label} doesn't have {severity} severity" assert target_alerts [ key ] [ 'annotations' ] [ 'severity_level' ] == severity , assert_msg assert_msg = f"Alert {label} is not in {state} state" assert target_alerts [ key ] [ 'state' ] == state , assert_msg logger . info ( f"Alerts were triggered correctly during utilization" )
Check list of alerts that there are alerts with requested label and
message for each provided state.
Check list of alerts that there are alerts with requested label and message for each provided state .
"""
    Check list of alerts that there are alerts with requested label and
    message for each provided state. If some alert is missing then this check
    fails.

    Args:
        label (str): Alert label
        msg (str): Alert message
        alerts (list): List of alerts to check
        states (list): List of states to check, order is important
    """
label
None
msg
None
alerts
List of alerts to check
List of alerts to check
states
List of states to check, order is important
List of states to check order is important
severity