Get all alert definitions associated with a given deployment or if metric_name
    is specified, obtain the specific alert config

    Returns dictionary or list of dictionaries.

    CLI Example:

        salt myminion telemetry.get_alert_config rs-ds033197 currentConnections profile=telemetry
        salt myminion telemetry.get_alert_config rs-ds033197 profile=telemetry

def get_alert_config(deployment_id, metric_name=None, api_key=None, profile="telemetry"):
    '''
    Get all alert definitions associated with a given deployment or if metric_name
    is specified, obtain the specific alert config

    Returns dictionary or list of dictionaries.

    CLI Example:

        salt myminion telemetry.get_alert_config rs-ds033197 currentConnections profile=telemetry
        salt myminion telemetry.get_alert_config rs-ds033197 profile=telemetry
    '''

    auth = _auth(profile=profile)
    alert = False

    key = "telemetry.{0}.alerts".format(deployment_id)

    if key not in __context__:
        try:
            get_url = _get_telemetry_base(profile) + "/alerts?deployment={0}".format(deployment_id)
            response = requests.get(get_url, headers=auth)
        except requests.exceptions.RequestException as e:
            log.error(six.text_type(e))
            return False

        http_result = {}
        if response.status_code == 200:
            for alert in response.json():
                http_result[alert.get('condition', {}).get('metric')] = alert
                __context__[key] = http_result

    if not __context__.get(key):
        return []

    alerts = __context__[key].values()

    if metric_name:
        return __context__[key].get(metric_name)

    return [alert['_id'] for alert in alerts if '_id' in alert]