ooiservices/app/main/notifications_redmine.py
def update_notification_redmine(alert, definition, notification):
    """ Update redmine ticket as a part of alert notification process.
    """
    result = None
    try:
        # Get alert ticket id
        ticket_id = alert.ticket_id

        # Populate required fields to update a redmine ticket
        project = current_app.config['REDMINE_PROJECT_ID']

        # Use user_event_notification for determining assigned user's redmine id
        redmine_id = 1
        assigned_user = User.query.get(notification.user_id)
        if assigned_user is not None:
            name = assigned_user.first_name + ' ' + assigned_user.last_name
            tmp_id = get_user_redmine_id(project, name)
            if tmp_id is not None:
                redmine_id = tmp_id
        else:
            message = 'Invalid User ID, User record not found.'
            current_app.logger.info(message)
            raise Exception(message)
        assigned_id = redmine_id

        ts_updated = dt.datetime.strftime(dt.datetime.now(), "%Y-%m-%dT%H:%M:%S")
        update_info = '\nUpdated: %s ' % ts_updated

        # If no previous ticket_id associated (case where 'use_redmine' was enabled AFter alert has escalated)
        if ticket_id == 0:

            # Create redmine ticket
            prefix = (alert.event_type).upper() + ': '
            subject = prefix + alert.event_response
            description = alert.event_response
            priority = definition.severity
            ticket_id = create_redmine_ticket_for_notification(project, subject, description, priority, redmine_id)
            if ticket_id is None:
                message = 'Failed to create base redmine ticket (on update) for alert notification (id:%d).' % alert.id
                current_app.logger.info(message)
                raise Exception(message)

            # Update escalate fields.
            if ticket_id is not None:
                escalated = True
                ts_escalated = dt.datetime.strftime(dt.datetime.now(), "%Y-%m-%dT%H:%M:%S")
                SystemEvent.update_alert_alarm_escalation(id=alert.id, ticket_id=ticket_id,
                                                          escalated=escalated, ts_escalated=ts_escalated)
        # Get existing redmine ticket
        redmine_ticket = get_redmine_ticket_for_notification(ticket_id)

        # Set fields for update
        project = redmine_ticket['project']
        subject = redmine_ticket['subject']
        description = redmine_ticket['description']
        priority = redmine_ticket['priority']
        if 'assigned_to' in redmine_ticket:
            assigned_id = redmine_ticket['assigned_to']

        # Update subject for recent receipt of alert (not past escalate boundary yet)
        description += update_info
        result = update_redmine_ticket_for_notification(ticket_id, project, subject, description, priority, assigned_id)
        if result is None:
            message = 'Failed to update redmine ticket (ticket_id: %d)' % ticket_id
            current_app.logger.info(message)
            raise Exception(message)

        return ticket_id

    except Exception as err:
        message = '[update_redmine_notification_ticket] %s ' % str(err.message)
        current_app.logger.info(message)
        return result
 Update redmine ticket as a part of alert notification process.
    
Update redmine ticket as a part of alert notification process.
Update redmine ticket as a part of alert notification process .
def update_notification_redmine(alert, definition, notification):
    result = None
    try:
        ticket_id = alert.ticket_id
        project = current_app.config['REDMINE_PROJECT_ID']
        redmine_id = 1
        assigned_user = User.query.get(notification.user_id)
        if assigned_user is not None:
            name = assigned_user.first_name + ' ' + assigned_user.last_name
            tmp_id = get_user_redmine_id(project, name)
            if tmp_id is not None:
                redmine_id = tmp_id
        else:
            message = 'Invalid User ID, User record not found.'
            current_app.logger.info(message)
            raise Exception(message)
        assigned_id = redmine_id
        ts_updated = dt.datetime.strftime(dt.datetime.now(), "%Y-%m-%dT%H:%M:%S")
        update_info = '\nUpdated: %s ' % ts_updated
        if ticket_id == 0:
            prefix = (alert.event_type).upper() + ': '
            subject = prefix + alert.event_response
            description = alert.event_response
            priority = definition.severity
            ticket_id = create_redmine_ticket_for_notification(project, subject, description, priority, redmine_id)
            if ticket_id is None:
                message = 'Failed to create base redmine ticket (on update) for alert notification (id:%d).' % alert.id
                current_app.logger.info(message)
                raise Exception(message)
            if ticket_id is not None:
                escalated = True
                ts_escalated = dt.datetime.strftime(dt.datetime.now(), "%Y-%m-%dT%H:%M:%S")
                SystemEvent.update_alert_alarm_escalation(id=alert.id, ticket_id=ticket_id,
                                                          escalated=escalated, ts_escalated=ts_escalated)
        redmine_ticket = get_redmine_ticket_for_notification(ticket_id)
        project = redmine_ticket['project']
        subject = redmine_ticket['subject']
        description = redmine_ticket['description']
        priority = redmine_ticket['priority']
        if 'assigned_to' in redmine_ticket:
            assigned_id = redmine_ticket['assigned_to']
        description += update_info
        result = update_redmine_ticket_for_notification(ticket_id, project, subject, description, priority, assigned_id)
        if result is None:
            message = 'Failed to update redmine ticket (ticket_id: %d)' % ticket_id
            current_app.logger.info(message)
            raise Exception(message)
        return ticket_id
    except Exception as err:
        message = '[update_redmine_notification_ticket] %s ' % str(err.message)
        current_app.logger.info(message)
        return result
def update_notification_redmine ( alert , definition , notification ) : result = None try : ticket_id = alert . ticket_id project = current_app . config [ 'REDMINE_PROJECT_ID' ] redmine_id = 1 assigned_user = User . query . get ( notification . user_id ) if assigned_user is not None : name = assigned_user . first_name + ' ' + assigned_user . last_name tmp_id = get_user_redmine_id ( project , name ) if tmp_id is not None : redmine_id = tmp_id else : message = 'Invalid User ID, User record not found.' current_app . logger . info ( message ) raise Exception ( message ) assigned_id = redmine_id ts_updated = dt . datetime . strftime ( dt . datetime . now ( ) , "%Y-%m-%dT%H:%M:%S" ) update_info = '\nUpdated: %s ' % ts_updated if ticket_id == 0 : prefix = ( alert . event_type ) . upper ( ) + ': ' subject = prefix + alert . event_response description = alert . event_response priority = definition . severity ticket_id = create_redmine_ticket_for_notification ( project , subject , description , priority , redmine_id ) if ticket_id is None : message = 'Failed to create base redmine ticket (on update) for alert notification (id:%d).' % alert . id current_app . logger . info ( message ) raise Exception ( message ) if ticket_id is not None : escalated = True ts_escalated = dt . datetime . strftime ( dt . datetime . now ( ) , "%Y-%m-%dT%H:%M:%S" ) SystemEvent . update_alert_alarm_escalation ( id = alert . id , ticket_id = ticket_id , escalated = escalated , ts_escalated = ts_escalated ) redmine_ticket = get_redmine_ticket_for_notification ( ticket_id ) project = redmine_ticket [ 'project' ] subject = redmine_ticket [ 'subject' ] description = redmine_ticket [ 'description' ] priority = redmine_ticket [ 'priority' ] if 'assigned_to' in redmine_ticket : assigned_id = redmine_ticket [ 'assigned_to' ] description += update_info result = update_redmine_ticket_for_notification ( ticket_id , project , subject , description , priority , assigned_id ) if result is None : message = 'Failed to update redmine ticket (ticket_id: %d)' % ticket_id current_app . logger . info ( message ) raise Exception ( message ) return ticket_id except Exception as err : message = '[update_redmine_notification_ticket] %s ' % str ( err . message ) current_app . logger . info ( message ) return result
Update redmine ticket as a part of alert notification process.
Update redmine ticket as a part of alert notification process .
""" Update redmine ticket as a part of alert notification process.
    """ # Get alert ticket id # Populate required fields to update a redmine ticket # Use user_event_notification for determining assigned user's redmine id # If no previous ticket_id associated (case where 'use_redmine' was enabled AFter alert has escalated) # Create redmine ticket # Update escalate fields. # Get existing redmine ticket # Set fields for update # Update subject for recent receipt of alert (not past escalate boundary yet)
alert
definition
notification