ooiservices/app/main/notifications_redmine.py
def handle_redmine_notifications(id):
    """
    Escalation notification processing is handled here for red mine.

    When an alert or an alarm is created, the state of the alert escalation process is determined.
    For each of the three escalation states ('begin_notification', 'update_notification', 'reissue_notification'),
    there is a corresponding function (of the same name) which process the notification for that state.
    Each of these functions handles the case when use_redmine is either enabled or disabled (both are required).
    """
    try:
        # Get alert_alarm using id provided
        alert_alarm = SystemEvent.query.get(id)
        if alert_alarm is None:
            message = 'Failed to retrieve SystemEvent to handle_notifications for id: %d' % id
            current_app.logger.info('[handle_redmine_notifications] %s ' % message)
            raise Exception(message)

        # Get alert_alarm, alert_alarm_definition and user_event_notification to process redmine notification
        alert_alarm, alert_alarm_definition, user_event_notification = get_info_from_alert(id)
        if alert_alarm is None or alert_alarm_definition is None or user_event_notification is None:
            message = 'Failed to retrieve alert, definition or notification for handle_redmine_notifications. (id: %d)' % id
            current_app.logger.info('[handle_redmine_notifications] %s ' % message)
            raise Exception(message)

        # If 'alert' received, start the alert escalation process, otherwise begin the process for an alarm.
        valid_actions = ['begin_notification', 'update_notification', 'reissue_notification']

        # Process alert for redmine notifications
        if alert_alarm.event_type == 'alert':
            action = alert_escalation_state(alert_alarm.id)
            if action is not None:
                is_dirty = False
                if action in valid_actions:

                    # Begin notification
                    if action == 'begin_notification':
                        ticket_id = begin_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message = 'Failed to create notification for alert notification (id:%d).' % alert_alarm.id
                            current_app.logger.info(message)
                            raise Exception(message)
                        else:
                            alert_alarm.ticket_id = ticket_id
                            is_dirty = True

                    # Update notification
                    elif action == 'update_notification':
                        ticket_id = update_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message ='Failed to update notification for alert notification (id:%d)' % alert_alarm.id
                            current_app.logger.info(message)

                    # Reissue notification
                    elif action == 'reissue_notification':
                        ticket_id = reissue_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message ='Failed to reissue notification for alert notification (id:%d)' % alert_alarm.id
                            current_app.logger.info(message)
                        else:
                            alert_alarm.ticket_id = ticket_id
                            is_dirty = True

                    # Update alert_alarm if dirty
                    if is_dirty:
                        try:
                            db.session.add(alert_alarm)
                            db.session.commit()
                        except Exception as err:
                            message = 'Error updating alert_alarm with redmine ticket_id; %s' % str(err.message)
                            current_app.logger.info(message)
                            raise Exception(message)

        # Process alarm for redmine notifications
        elif alert_alarm.event_type == 'alarm':
            ticket_id = begin_notification(alert_alarm, alert_alarm_definition, user_event_notification)
            if ticket_id is None:
                message = 'Failed to create notification for alarm (id:%d)' % alert_alarm.id
                current_app.logger.info(message)
                raise Exception(message)

    except Exception as err:
        message = 'Exception handle_redmine_notifications. %s' % err.message
        current_app.logger.info(message)
        raise Exception(message)

    Escalation notification processing is handled here for red mine.

    When an alert or an alarm is created, the state of the alert escalation process is determined.
    For each of the three escalation states ('begin_notification', 'update_notification', 'reissue_notification'),
    there is a corresponding function (of the same name) which process the notification for that state.
    Each of these functions handles the case when use_redmine is either enabled or disabled (both are required).
    
Escalation notification processing is handled here for red mine.
When an alert or an alarm is created, the state of the alert escalation process is determined.
Escalation notification processing is handled here for red mine . When an alert or an alarm is created the state of the alert escalation process is determined .
def handle_redmine_notifications(id):
    try:
        alert_alarm = SystemEvent.query.get(id)
        if alert_alarm is None:
            message = 'Failed to retrieve SystemEvent to handle_notifications for id: %d' % id
            current_app.logger.info('[handle_redmine_notifications] %s ' % message)
            raise Exception(message)
        alert_alarm, alert_alarm_definition, user_event_notification = get_info_from_alert(id)
        if alert_alarm is None or alert_alarm_definition is None or user_event_notification is None:
            message = 'Failed to retrieve alert, definition or notification for handle_redmine_notifications. (id: %d)' % id
            current_app.logger.info('[handle_redmine_notifications] %s ' % message)
            raise Exception(message)
        valid_actions = ['begin_notification', 'update_notification', 'reissue_notification']
        if alert_alarm.event_type == 'alert':
            action = alert_escalation_state(alert_alarm.id)
            if action is not None:
                is_dirty = False
                if action in valid_actions:
                    if action == 'begin_notification':
                        ticket_id = begin_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message = 'Failed to create notification for alert notification (id:%d).' % alert_alarm.id
                            current_app.logger.info(message)
                            raise Exception(message)
                        else:
                            alert_alarm.ticket_id = ticket_id
                            is_dirty = True
                    elif action == 'update_notification':
                        ticket_id = update_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message ='Failed to update notification for alert notification (id:%d)' % alert_alarm.id
                            current_app.logger.info(message)
                    elif action == 'reissue_notification':
                        ticket_id = reissue_notification(alert_alarm, alert_alarm_definition, user_event_notification)
                        if ticket_id is None:
                            message ='Failed to reissue notification for alert notification (id:%d)' % alert_alarm.id
                            current_app.logger.info(message)
                        else:
                            alert_alarm.ticket_id = ticket_id
                            is_dirty = True
                    if is_dirty:
                        try:
                            db.session.add(alert_alarm)
                            db.session.commit()
                        except Exception as err:
                            message = 'Error updating alert_alarm with redmine ticket_id; %s' % str(err.message)
                            current_app.logger.info(message)
                            raise Exception(message)
        elif alert_alarm.event_type == 'alarm':
            ticket_id = begin_notification(alert_alarm, alert_alarm_definition, user_event_notification)
            if ticket_id is None:
                message = 'Failed to create notification for alarm (id:%d)' % alert_alarm.id
                current_app.logger.info(message)
                raise Exception(message)
    except Exception as err:
        message = 'Exception handle_redmine_notifications. %s' % err.message
        current_app.logger.info(message)
        raise Exception(message)
def handle_redmine_notifications ( id ) : try : alert_alarm = SystemEvent . query . get ( id ) if alert_alarm is None : message = 'Failed to retrieve SystemEvent to handle_notifications for id: %d' % id current_app . logger . info ( '[handle_redmine_notifications] %s ' % message ) raise Exception ( message ) alert_alarm , alert_alarm_definition , user_event_notification = get_info_from_alert ( id ) if alert_alarm is None or alert_alarm_definition is None or user_event_notification is None : message = 'Failed to retrieve alert, definition or notification for handle_redmine_notifications. (id: %d)' % id current_app . logger . info ( '[handle_redmine_notifications] %s ' % message ) raise Exception ( message ) valid_actions = [ 'begin_notification' , 'update_notification' , 'reissue_notification' ] if alert_alarm . event_type == 'alert' : action = alert_escalation_state ( alert_alarm . id ) if action is not None : is_dirty = False if action in valid_actions : if action == 'begin_notification' : ticket_id = begin_notification ( alert_alarm , alert_alarm_definition , user_event_notification ) if ticket_id is None : message = 'Failed to create notification for alert notification (id:%d).' % alert_alarm . id current_app . logger . info ( message ) raise Exception ( message ) else : alert_alarm . ticket_id = ticket_id is_dirty = True elif action == 'update_notification' : ticket_id = update_notification ( alert_alarm , alert_alarm_definition , user_event_notification ) if ticket_id is None : message = 'Failed to update notification for alert notification (id:%d)' % alert_alarm . id current_app . logger . info ( message ) elif action == 'reissue_notification' : ticket_id = reissue_notification ( alert_alarm , alert_alarm_definition , user_event_notification ) if ticket_id is None : message = 'Failed to reissue notification for alert notification (id:%d)' % alert_alarm . id current_app . logger . info ( message ) else : alert_alarm . ticket_id = ticket_id is_dirty = True if is_dirty : try : db . session . add ( alert_alarm ) db . session . commit ( ) except Exception as err : message = 'Error updating alert_alarm with redmine ticket_id; %s' % str ( err . message ) current_app . logger . info ( message ) raise Exception ( message ) elif alert_alarm . event_type == 'alarm' : ticket_id = begin_notification ( alert_alarm , alert_alarm_definition , user_event_notification ) if ticket_id is None : message = 'Failed to create notification for alarm (id:%d)' % alert_alarm . id current_app . logger . info ( message ) raise Exception ( message ) except Exception as err : message = 'Exception handle_redmine_notifications. %s' % err . message current_app . logger . info ( message ) raise Exception ( message )
Escalation notification processing is handled here for red mine.
Escalation notification processing is handled here for red mine .
"""
    Escalation notification processing is handled here for red mine.

    When an alert or an alarm is created, the state of the alert escalation process is determined.
    For each of the three escalation states ('begin_notification', 'update_notification', 'reissue_notification'),
    there is a corresponding function (of the same name) which process the notification for that state.
    Each of these functions handles the case when use_redmine is either enabled or disabled (both are required).
    """ # Get alert_alarm using id provided # Get alert_alarm, alert_alarm_definition and user_event_notification to process redmine notification # If 'alert' received, start the alert escalation process, otherwise begin the process for an alarm. # Process alert for redmine notifications # Begin notification # Update notification # Reissue notification # Update alert_alarm if dirty # Process alarm for redmine notifications
id