def METHOD_NAME(module, state, label, entity_id, check_id, notification_plan_id, criteria,
          disabled, metadata):
    if len(label) < 1 or len(label) > 255:
        module.fail_json(msg='label must be between 1 and 255 characters long')
    if criteria and len(criteria) < 1 or len(criteria) > 16384:
        module.fail_json(msg='criteria must be between 1 and 16384 characters long')
    # Coerce attributes.
    changed = False
    METHOD_NAME = None
    cm = pyrax.cloud_monitoring
    if not cm:
        module.fail_json(msg='Failed to instantiate client. This typically '
                             'indicates an invalid region or an incorrectly '
                             'capitalized region name.')
    existing = [a for a in cm.list_alarms(entity_id) if a.label == label]
    if existing:
        METHOD_NAME = existing[0]
    if state == 'present':
        should_create = False
        should_update = False
        should_delete = False
        if len(existing) > 1:
            module.fail_json(msg='%s existing alarms have the label %s.' %
                                 (len(existing), label))
        if METHOD_NAME:
            if check_id != METHOD_NAME.check_id or notification_plan_id != METHOD_NAME.notification_plan_id:
                should_delete = should_create = True
            should_update = (disabled and disabled != METHOD_NAME.disabled) or \
                (metadata and metadata != METHOD_NAME.metadata) or \
                (criteria and criteria != METHOD_NAME.criteria)
            if should_update and not should_delete:
                cm.update_alarm(entity=entity_id, METHOD_NAME=METHOD_NAME,
                                criteria=criteria, disabled=disabled,
                                label=label, metadata=metadata)
                changed = True
            if should_delete:
                METHOD_NAME.delete()
                changed = True
        else:
            should_create = True
        if should_create:
            METHOD_NAME = cm.create_alarm(entity=entity_id, check=check_id,
                                    notification_plan=notification_plan_id,
                                    criteria=criteria, disabled=disabled, label=label,
                                    metadata=metadata)
            changed = True
    else:
        for a in existing:
            a.delete()
            changed = True
    if METHOD_NAME:
        alarm_dict = {
            "id": METHOD_NAME.id,
            "label": METHOD_NAME.label,
            "check_id": METHOD_NAME.check_id,
            "notification_plan_id": METHOD_NAME.notification_plan_id,
            "criteria": METHOD_NAME.criteria,
            "disabled": METHOD_NAME.disabled,
            "metadata": METHOD_NAME.metadata
        }
        module.exit_json(changed=changed, METHOD_NAME=alarm_dict)
    else:
        module.exit_json(changed=changed)