create an telemetry alarms.

    data is a dict of alert configuration data.

    Returns (bool success, str message) tuple.

    CLI Example:

        salt myminion telemetry.create_alarm rs-ds033197 {} profile=telemetry

def create_alarm(deployment_id, metric_name, data, api_key=None, profile="telemetry"):
    '''
    create an telemetry alarms.

    data is a dict of alert configuration data.

    Returns (bool success, str message) tuple.

    CLI Example:

        salt myminion telemetry.create_alarm rs-ds033197 {} profile=telemetry

    '''

    auth = _auth(api_key, profile)
    request_uri = _get_telemetry_base(profile) + "/alerts"

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

    # set the notification channels if not already set
    post_body = {
        "deployment": deployment_id,
        "filter": data.get('filter'),
        "notificationChannel": get_notification_channel_id(data.get('escalate_to')).split(),
        "condition": {
            "metric": metric_name,
            "max": data.get('max'),
            "min": data.get('min')
        }
    }

    try:
        response = requests.post(request_uri, data=salt.utils.json.dumps(post_body), headers=auth)
    except requests.exceptions.RequestException as e:
        # TODO: May be we should retry?
        log.error(six.text_type(e))

    if response.status_code >= 200 and response.status_code < 300:
        # update cache
        log.info('Created alarm on metric: %s in deployment: %s', metric_name, deployment_id)
        log.debug('Updating cache for metric %s in deployment %s: %s',
                  metric_name, deployment_id, response.json())
        _update_cache(deployment_id, metric_name, response.json())
    else:
        log.error(
            'Failed to create alarm on metric: %s in '
            'deployment %s: payload: %s',
            metric_name, deployment_id, salt.utils.json.dumps(post_body)
        )

    return response.status_code >= 200 and response.status_code < 300, response.json()