def METHOD_NAME():
    """
    Checks what should have been on maintenance from MaintenanceTask against
    what actually is on maintenance from AlertHistory, then creates events
    based on this.
    """
    # Find out what should have been on maintenance
    should_be_on_maintenance = set()
    task_subject_mapper = {}
    for task in MaintenanceTask.objects.filter(state=MaintenanceTask.STATE_ACTIVE):
        for subject in task.get_event_subjects():
            task_subject_mapper[subject] = task.id
            should_be_on_maintenance.add(subject)
    # Find out what is on maintenance
    is_on_maintenance = set()
    for alert in AlertHistory.objects.unresolved('maintenanceState'):
        subject = alert.get_subject()
        is_on_maintenance.add(subject)
    # Set on maintenance that which is not and should be
    to_be_put_on_maintenance = should_be_on_maintenance - is_on_maintenance
    _logger.debug(
        "Subjects that should be on maintenance but weren't: %r",
        to_be_put_on_maintenance,
    )
    for subject in to_be_put_on_maintenance:
        create_event(
            subject,
            state=Event.STATE_START,
            value=100,
            taskid=task_subject_mapper[subject],
        )
    # Set off maintenance that which is and should not be
    to_be_taken_off_maintenance = is_on_maintenance - should_be_on_maintenance
    _logger.debug(
        "Subjects that should not be on maintenance but were: %r",
        to_be_taken_off_maintenance,
    )
    for subject in to_be_taken_off_maintenance:
        create_event(subject, state=Event.STATE_END, value=0)