Create an alert in OpsGenie. Example usage with Salt's requisites and other
    global state arguments could be found above.

    Required Parameters:

    api_key
        It's the API Key you've copied while adding integration in OpsGenie.

    reason
        It will be used as alert's default message in OpsGenie.

    Optional Parameters:

    name
        It will be used as alert's alias. If you want to use the close
        functionality you must provide name field for both states like
        in above case.

    action_type
        OpsGenie supports the default values Create/Close for action_type.
        You can customize this field with OpsGenie's custom actions for
        other purposes like adding notes or acknowledging alerts.

def create_alert(name=None, api_key=None, reason=None, action_type="Create"):
    '''
    Create an alert in OpsGenie. Example usage with Salt's requisites and other
    global state arguments could be found above.

    Required Parameters:

    api_key
        It's the API Key you've copied while adding integration in OpsGenie.

    reason
        It will be used as alert's default message in OpsGenie.

    Optional Parameters:

    name
        It will be used as alert's alias. If you want to use the close
        functionality you must provide name field for both states like
        in above case.

    action_type
        OpsGenie supports the default values Create/Close for action_type.
        You can customize this field with OpsGenie's custom actions for
        other purposes like adding notes or acknowledging alerts.
    '''

    _, _, _, values = inspect.getargvalues(inspect.currentframe())
    log.info("Arguments values: %s", values)

    ret = {
        'result': '',
        'name': '',
        'changes': '',
        'comment': ''
    }

    if api_key is None or reason is None:
        raise salt.exceptions.SaltInvocationError(
            'API Key or Reason cannot be None.')

    if __opts__['test'] is True:
        ret[
            'comment'] = 'Test: {0} alert request will be processed ' \
                         'using the API Key="{1}".'.format(action_type, api_key)

        # Return ``None`` when running with ``test=true``.
        ret['result'] = None

        return ret

    response_status_code, response_text = __salt__['opsgenie.post_data'](
        api_key=api_key,
        name=name,
        reason=reason,
        action_type=action_type
    )

    if 200 <= response_status_code < 300:
        log.info(
            "POST Request has succeeded with message: %s status code: %s",
            response_text, response_status_code)
        ret[
            'comment'] = 'Test: {0} alert request will be processed' \
                         ' using the API Key="{1}".'.format(
            action_type,
            api_key)
        ret['result'] = True
    else:
        log.error(
            "POST Request has failed with error: %s status code: %s",
            response_text, response_status_code)
        ret['result'] = False

    return ret