ooiservices/app/main/notifications_redmine.py
def determine_action(id):
    """ For alert id, determine which valid action (or None) is next; return action. If exception, log exception.
    """
    action = None
    previous_alert = None
    previously_escalated = False
    try:
        # Get alert
        alert = SystemEvent.query.get(id)
        if alert is None:
            message = 'Failed to retrieve alert record for id provided (id:%d).' % id
            current_app.logger.info('[determine_action] %s ' % message)
            raise Exception(message)

        # Get alert_alarm_definition
        alert_alarm_definition = SystemEventDefinition.query.get(alert.system_event_definition_id)
        if alert_alarm_definition is None:
            message = 'Failed to identify system_event_definition with id: %d' % alert.system_event_definition_id
            current_app.logger.info('[determine_action] %s ' % message)
            return action

        # Get associated alerts back to when ts_start is not None (ts_start set to timestamp when
        # this alert first arrived).
        alerts = SystemEvent.query.filter_by(
            system_event_definition_id=alert.system_event_definition_id).order_by(desc(SystemEvent.id)).all()

        # Determine whether additional alerts have arrived since first alert
        found_alerts = False
        if alerts is not None:
            for item in alerts:
                if item.id == alert.id:
                    pass
                else:
                    found_alerts = True

        # If this is the FIRST alert for this definition, set ts_start to current datetime, return None
        if not found_alerts:
            alert.ts_start = alert.event_time
            try:
                db.session.add(alert)
                db.session.commit()
            except Exception as err:
                current_app.logger.info('[determine_action][1] %s ' % err.message)
            return action

        # Not the first alert received for this definition, evaluate this alert to determine whether to escalate.
        # Or if escalated == True, then have we exceeded the escalate boundary (if so, re-issue ticket)
        else:
            # Determine if previously escalated, review previous alert to see if escalated is True. Save previous_alert.
            previously_escalated = False
            inx = 1
            for item in alerts:
                if inx > 1:
                    if item.escalated == True:
                        previously_escalated = True
                        previous_alert = item
                        break
                inx += 1

            # Determine start_alert (ts_start is not None)
            start_alert = None
            for item in alerts:
                if item.ts_start is not None:
                    start_alert = item
                    break

            # Now have initial alert which kicked off (start_alert)
            # Evaluate time delta (event_time) of this alert versus start_alert
            delta = (alert.event_time - start_alert.ts_start).total_seconds()

            # if delta is greater than escalate_on value (from definition), has alert been previously escalated?
            if delta <= alert_alarm_definition.escalate_on:
                pass
            elif delta > alert_alarm_definition.escalate_on:

                # if alert hasn't been previously escalated, begin escalation
                if not previously_escalated: #alert.escalated:
                    action = 'begin_notification'
                    return action

                else:
                    # if alert previously escalated, determine if we have crossed escalate_boundary.
                    # If escalate boundary is crossed:
                    #     First:
                    #        reset start_alert.ts_start - None
                    #        alert.ts_start - event_time
                    #     Proceed to reissue ticket where:
                    #      escalated True, timestamp None
                    #      update ticket_id to be for new ticket_id created
                    # Carry forward some escalation data from previous alert...
                    try:
                        alert.escalated = previous_alert.escalated
                        alert.ts_escalated = previous_alert.ts_escalated
                        alert.ticket_id = previous_alert.ticket_id
                        db.session.add(alert)
                        db.session.commit()
                    except Exception as err:
                        message = '[determine_action][2] (Escalate boundary has been crossed) %s ' % err.message
                        current_app.logger.info(message)
                    # If boundary has not been crossed, update existing ticket
                    if delta <= alert_alarm_definition.escalate_boundary:
                        # Escalate boundary has not been crossed, update existing ticket
                        action = 'update_notification'
                        return action

                    elif delta > alert_alarm_definition.escalate_boundary:
                        # Escalate boundary has been crossed, issue new ticket 'reissue_notification_ticket'
                        action = 'reissue_notification'
                        start_alert.ts_start = None
                        try:
                            db.session.add(start_alert)
                            db.session.commit()
                        except Exception as err:
                            message = '[determine_action][3] (Escalate boundary has been crossed) (1) %s ' % err.message
                            current_app.logger.info(message)

                        alert.ts_start = alert.event_time
                        try:
                            db.session.add(alert)
                            db.session.commit()
                        except Exception as err:
                            message = '[determine_action][4] (Escalate boundary has been crossed) [2] %s ' % err.message
                            current_app.logger.info(message)
                        return action

        return action

    except Exception as err:
        current_app.logger.info('[determine_action] %s ' % err.message)
        return action
 For alert id, determine which valid action (or None) is next; return action. If exception, log exception.
    
For alert id, determine which valid action (or None) is next; return action. If exception, log exception.
For alert id determine which valid action ( or None ) is next ; return action . If exception log exception .
def determine_action(id):
    action = None
    previous_alert = None
    previously_escalated = False
    try:
        alert = SystemEvent.query.get(id)
        if alert is None:
            message = 'Failed to retrieve alert record for id provided (id:%d).' % id
            current_app.logger.info('[determine_action] %s ' % message)
            raise Exception(message)
        _alarm_definition
        alert_alarm_definition = SystemEventDefinition.query.get(alert.system_event_definition_id)
        if alert_alarm_definition is None:
            message = 'Failed to identify system_event_definition with id: %d' % alert.system_event_definition_id
            current_app.logger.info('[determine_action] %s ' % message)
            return action
        alerts = SystemEvent.query.filter_by(
            system_event_definition_id=alert.system_event_definition_id).order_by(desc(SystemEvent.id)).all()
        found_alerts = False
        if alerts is not None:
            for item in alerts:
                if item.id == alert.id:
                    pass
                else:
                    found_alerts = True
        if not found_alerts:
            alert.ts_start = alert.event_time
            try:
                db.session.add(alert)
                db.session.commit()
            except Exception as err:
                current_app.logger.info('[determine_action][1] %s ' % err.message)
            return action
        else:
            previously_escalated = False
            inx = 1
            for item in alerts:
                if inx > 1:
                    if item.escalated == True:
                        previously_escalated = True
                        previous_alert = item
                        break
                inx += 1
            start_alert = None
            for item in alerts:
                if item.ts_start is not None:
                    start_alert = item
                    break
            delta = (alert.event_time - start_alert.ts_start).total_seconds()
            if delta <= alert_alarm_definition.escalate_on:
                pass
            elif delta > alert_alarm_definition.escalate_on:
                if not previously_escalated: 
                    action = 'begin_notification'
                    return action
                else:
                    try:
                        alert.escalated = previous_alert.escalated
                        alert.ts_escalated = previous_alert.ts_escalated
                        alert.ticket_id = previous_alert.ticket_id
                        db.session.add(alert)
                        db.session.commit()
                    except Exception as err:
                        message = '[determine_action][2] (Escalate boundary has been crossed) %s ' % err.message
                        current_app.logger.info(message)
                    if delta <= alert_alarm_definition.escalate_boundary:
                        action = 'update_notification'
                        return action
                    elif delta > alert_alarm_definition.escalate_boundary:
                        action = 'reissue_notification'
                        start_alert.ts_start = None
                        try:
                            db.session.add(start_alert)
                            db.session.commit()
                        except Exception as err:
                            message = '[determine_action][3] (Escalate boundary has been crossed) (1) %s ' % err.message
                            current_app.logger.info(message)
                        alert.ts_start = alert.event_time
                        try:
                            db.session.add(alert)
                            db.session.commit()
                        except Exception as err:
                            message = '[determine_action][4] (Escalate boundary has been crossed) [2] %s ' % err.message
                            current_app.logger.info(message)
                        return action
        return action
    except Exception as err:
        current_app.logger.info('[determine_action] %s ' % err.message)
        return action
def determine_action ( id ) : action = None previous_alert = None previously_escalated = False try : alert = SystemEvent . query . get ( id ) if alert is None : message = 'Failed to retrieve alert record for id provided (id:%d).' % id current_app . logger . info ( '[determine_action] %s ' % message ) raise Exception ( message ) alert_alarm_definition = SystemEventDefinition . query . get ( alert . system_event_definition_id ) if alert_alarm_definition is None : message = 'Failed to identify system_event_definition with id: %d' % alert . system_event_definition_id current_app . logger . info ( '[determine_action] %s ' % message ) return action alerts = SystemEvent . query . filter_by ( system_event_definition_id = alert . system_event_definition_id ) . order_by ( desc ( SystemEvent . id ) ) . all ( ) found_alerts = False if alerts is not None : for item in alerts : if item . id == alert . id : pass else : found_alerts = True if not found_alerts : alert . ts_start = alert . event_time try : db . session . add ( alert ) db . session . commit ( ) except Exception as err : current_app . logger . info ( '[determine_action][1] %s ' % err . message ) return action else : previously_escalated = False inx = 1 for item in alerts : if inx > 1 : if item . escalated == True : previously_escalated = True previous_alert = item break inx += 1 start_alert = None for item in alerts : if item . ts_start is not None : start_alert = item break delta = ( alert . event_time - start_alert . ts_start ) . total_seconds ( ) if delta <= alert_alarm_definition . escalate_on : pass elif delta > alert_alarm_definition . escalate_on : if not previously_escalated : action = 'begin_notification' return action else : try : alert . escalated = previous_alert . escalated alert . ts_escalated = previous_alert . ts_escalated alert . ticket_id = previous_alert . ticket_id db . session . add ( alert ) db . session . commit ( ) except Exception as err : message = '[determine_action][2] (Escalate boundary has been crossed) %s ' % err . message current_app . logger . info ( message ) if delta <= alert_alarm_definition . escalate_boundary : action = 'update_notification' return action elif delta > alert_alarm_definition . escalate_boundary : action = 'reissue_notification' start_alert . ts_start = None try : db . session . add ( start_alert ) db . session . commit ( ) except Exception as err : message = '[determine_action][3] (Escalate boundary has been crossed) (1) %s ' % err . message current_app . logger . info ( message ) alert . ts_start = alert . event_time try : db . session . add ( alert ) db . session . commit ( ) except Exception as err : message = '[determine_action][4] (Escalate boundary has been crossed) [2] %s ' % err . message current_app . logger . info ( message ) return action return action except Exception as err : current_app . logger . info ( '[determine_action] %s ' % err . message ) return action
For alert id, determine which valid action (or None) is next; return action.
For alert id determine which valid action ( or None ) is next ; return action .
""" For alert id, determine which valid action (or None) is next; return action. If exception, log exception.
    """ # Get alert # Get alert_alarm_definition # Get associated alerts back to when ts_start is not None (ts_start set to timestamp when # this alert first arrived). # Determine whether additional alerts have arrived since first alert # If this is the FIRST alert for this definition, set ts_start to current datetime, return None # Not the first alert received for this definition, evaluate this alert to determine whether to escalate. # Or if escalated == True, then have we exceeded the escalate boundary (if so, re-issue ticket) # Determine if previously escalated, review previous alert to see if escalated is True. Save previous_alert. # Determine start_alert (ts_start is not None) # Now have initial alert which kicked off (start_alert) # Evaluate time delta (event_time) of this alert versus start_alert # if delta is greater than escalate_on value (from definition), has alert been previously escalated? # if alert hasn't been previously escalated, begin escalation #alert.escalated: # if alert previously escalated, determine if we have crossed escalate_boundary. # If escalate boundary is crossed: #     First: #        reset start_alert.ts_start - None #        alert.ts_start - event_time #     Proceed to reissue ticket where: #      escalated True, timestamp None #      update ticket_id to be for new ticket_id created # Carry forward some escalation data from previous alert... # If boundary has not been crossed, update existing ticket # Escalate boundary has not been crossed, update existing ticket # Escalate boundary has been crossed, issue new ticket 'reissue_notification_ticket'
id