Ejemplo n.º 1
0
def create_user_event_notification():
    """
    Create user_event_notification associated with SystemEventDefinition.

    Usage: Whenever a SystemEvent occurs, for the system_event_definition_id, this notification
    indicates who and how to contact them with the SystemEvent information.
    """
    log = False
    try:
        data = json.loads(request.data)
        create_has_required_fields(data)

        system_event_definition_id = data['system_event_definition_id']
        definition = SystemEventDefinition.query.get(
            system_event_definition_id)
        if definition is None:
            message = "Invalid SystemEventDefinition ID, SystemEventDefinition record not found."
            #if log: print '\n message: ', message
            return bad_request(message)
            #return jsonify(error=message), 404

        # Validate user to be notified exists
        user_id = data['user_id']
        user = User.query.filter_by(id=user_id).first()
        if not user:
            message = "Invalid User ID, User record not found."
            #if log: print '\n message: ', message
            return bad_request(message)

        # Create UserEventNotification
        notification = UserEventNotification()
        notification.system_event_definition_id = data[
            'system_event_definition_id']
        notification.user_id = data['user_id']
        notification.use_email = data['use_email']
        notification.use_redmine = data['use_redmine']
        notification.use_phone = data['use_phone']
        notification.use_log = data['use_log']
        notification.use_sms = data['use_sms']
        try:
            db.session.add(notification)
            db.session.commit()
        except Exception as err:
            #if log: print '\n (log) create_user_event_notification - message: ', err.message
            db.session.rollback()
            return bad_request('IntegrityError creating notification')
        return jsonify(notification.to_json()), 201
    except Exception as err:
        #if log: print '\n (log) create_user_event_notification - exception: ', err.message
        return conflict('Insufficient data, or bad data format.')
def create_user_event_notification():
    """
    Create user_event_notification associated with SystemEventDefinition.

    Usage: Whenever a SystemEvent occurs, for the system_event_definition_id, this notification
    indicates who and how to contact them with the SystemEvent information.
    """
    log = False
    try:
        data = json.loads(request.data)
        create_has_required_fields(data)

        system_event_definition_id = data['system_event_definition_id']
        definition = SystemEventDefinition.query.get(system_event_definition_id)
        if definition is None:
            message = "Invalid SystemEventDefinition ID, SystemEventDefinition record not found."
            #if log: print '\n message: ', message
            return bad_request(message)
            #return jsonify(error=message), 404

        # Validate user to be notified exists
        user_id = data['user_id']
        user = User.query.filter_by(id=user_id).first()
        if not user:
            message = "Invalid User ID, User record not found."
            #if log: print '\n message: ', message
            return bad_request(message)

        # Create UserEventNotification
        notification = UserEventNotification()
        notification.system_event_definition_id = data['system_event_definition_id']
        notification.user_id = data['user_id']
        notification.use_email = data['use_email']
        notification.use_redmine = data['use_redmine']
        notification.use_phone = data['use_phone']
        notification.use_log = data['use_log']
        notification.use_sms = data['use_sms']
        try:
            db.session.add(notification)
            db.session.commit()
        except Exception as err:
            #if log: print '\n (log) create_user_event_notification - message: ', err.message
            db.session.rollback()
            return bad_request('IntegrityError creating notification')
        return jsonify(notification.to_json()), 201
    except Exception as err:
        #if log: print '\n (log) create_user_event_notification - exception: ', err.message
        return conflict('Insufficient data, or bad data format.')
Ejemplo n.º 3
0
    def create_user_event_notification(self, definition_id, user_id):

        notification = None
        user_id = user_id
        use_email = False
        use_redmine = True
        use_phone = False
        use_log = False
        use_sms = True
        try:
            # Create corresponding UserEventNotification when alert or alarm definition is created
            new_id = UserEventNotification.insert_user_event_notification(
                system_event_definition_id=definition_id,
                user_id=user_id,
                use_email=use_email,
                use_redmine=use_redmine,
                use_phone=use_phone,
                use_log=use_log,
                use_sms=use_sms)
            notification = UserEventNotification.query.get(new_id)
        except Exception as err:
            print '\n ******* Create CP02PMCO-WFP01-02-DOFSTK000 UserEventNotification message: \n', err.message

        return notification
    def create_user_event_notification(self, definition_id, user_id):

        notification = None
        user_id = user_id
        use_email = False
        use_redmine = True
        use_phone = False
        use_log = False
        use_sms = True
        try:
            # Create corresponding UserEventNotification when alert or alarm definition is created
            new_id = UserEventNotification.insert_user_event_notification(
                                                 system_event_definition_id=definition_id,
                                                 user_id=user_id,
                                                 use_email=use_email,
                                                 use_redmine=use_redmine,
                                                 use_phone=use_phone,
                                                 use_log=use_log,
                                                 use_sms=use_sms)
            notification = UserEventNotification.query.get(new_id)
        except Exception as err:
            print '\n ******* Create CP02PMCO-WFP01-02-DOFSTK000 UserEventNotification message: \n', err.message

        return notification
Ejemplo n.º 5
0
    def create_alert_alarm_definition(self, ref_def, event_type, uframe_id,
                                      severity):
        # Note, creates a definition in test database only, just used to exercise SystemEventDefinition class
        # but does NOT create alertfilter id in uframe. An alertfilter is created when the /alert_alarm_definition
        # route is called.
        #headers = self.get_api_headers('admin', 'test')
        #valid_event_type = ['alert','alarm']
        alert_alarm_definition = None
        array_name = ref_def[0:0 + 2]
        platform_name = ref_def[0:0 + 14]
        instrument_parameter = 'temperature'
        instrument_parameter_pdid = 'PD100'
        operator = 'GREATER'
        high_value = '10.0'
        low_value = '1.0'
        stream = 'ctdpf_j_cspp_instrument'
        escalate_on = 5
        escalate_boundary = 10
        user_id = 1
        use_email = False
        use_redmine = True
        use_phone = False
        use_log = False
        use_sms = True
        create_time = dt.datetime.now()
        if ref_def == 'CP02PMCO-WFP01-02-DOFSTK000':
            alert_alarm_definition = SystemEventDefinition(
                reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n ***  CP02PMCO-WFP01-02-DOFSTK000 **** message: ', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                    system_event_definition_id=alert_alarm_definition.id,
                    user_id=user_id,
                    use_email=use_email,
                    use_redmine=use_redmine,
                    use_phone=use_phone,
                    use_log=use_log,
                    use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-02-DOFSTK000 UserEventNotification message: \n', err.message

        elif alert_alarm_definition == 'CP02PMCO-WFP01-03-CTDPFK000':
            alert_alarm_definition = SystemEventDefinition(
                reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-03-CTDPFK000 alert_alarm_definition message: \n', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                    system_event_definition_id=alert_alarm_definition.id,
                    user_id=user_id,
                    use_email=use_email,
                    use_redmine=use_redmine,
                    use_phone=use_phone,
                    use_log=use_log,
                    use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-03-CTDPFK000 UserEventNotification message: \n', err.message

        elif alert_alarm_definition == 'CP02PMCO-WFP01-05-PARADK000':
            alert_alarm_definition = SystemEventDefinition(
                reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n *** CP02PMCO-WFP01-05-PARADK000 **** message: ', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                    system_event_definition_id=alert_alarm_definition.id,
                    user_id=user_id,
                    use_email=use_email,
                    use_redmine=use_redmine,
                    use_phone=use_phone,
                    use_log=use_log,
                    use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-05-PARADK000 UserEventNotification message: \n', err.message
        else:
            alert_alarm_definition = SystemEventDefinition(
                reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n *** %s **** message: %s' % (ref_def, err.message)
            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                    system_event_definition_id=alert_alarm_definition.id,
                    user_id=user_id,
                    use_email=use_email,
                    use_redmine=use_redmine,
                    use_phone=use_phone,
                    use_log=use_log,
                    use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create UserEventNotification message: \n', err.message
        return alert_alarm_definition
    def create_alert_alarm_definition(self, ref_def, event_type, uframe_id, severity):
        # Note, creates a definition in test database only, just used to exercise SystemEventDefinition class
        # but does NOT create alertfilter id in uframe. An alertfilter is created when the /alert_alarm_definition
        # route is called.
        #headers = self.get_api_headers('admin', 'test')
        #valid_event_type = ['alert','alarm']
        alert_alarm_definition = None
        array_name = ref_def[0:0+2]
        platform_name = ref_def[0:0+14]
        instrument_parameter = 'temperature'
        instrument_parameter_pdid = 'PD100'
        operator = 'GREATER'
        high_value = '10.0'
        low_value = '1.0'
        stream = 'ctdpf_j_cspp_instrument'
        escalate_on = 5
        escalate_boundary = 10
        user_id = 1
        use_email = False
        use_redmine = True
        use_phone = False
        use_log = False
        use_sms = True
        create_time = dt.datetime.now()
        '''
        if ref_def == 'CP02PMCO-WFP01-02-DOFSTK000':
            alert_alarm_definition = SystemEventDefinition(reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n ***  CP02PMCO-WFP01-02-DOFSTK000 **** message: ', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                                                     system_event_definition_id=alert_alarm_definition.id,
                                                     user_id=user_id,
                                                     use_email=use_email,
                                                     use_redmine=use_redmine,
                                                     use_phone=use_phone,
                                                     use_log=use_log,
                                                     use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-02-DOFSTK000 UserEventNotification message: \n', err.message

        elif alert_alarm_definition == 'CP02PMCO-WFP01-03-CTDPFK000':
            alert_alarm_definition = SystemEventDefinition(reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-03-CTDPFK000 alert_alarm_definition message: \n', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                                                     system_event_definition_id=alert_alarm_definition.id,
                                                     user_id=user_id,
                                                     use_email=use_email,
                                                     use_redmine=use_redmine,
                                                     use_phone=use_phone,
                                                     use_log=use_log,
                                                     use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-03-CTDPFK000 UserEventNotification message: \n', err.message


        elif alert_alarm_definition == 'CP02PMCO-WFP01-05-PARADK000':
            alert_alarm_definition = SystemEventDefinition(reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n *** CP02PMCO-WFP01-05-PARADK000 **** message: ', err.message

            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                                                     system_event_definition_id=alert_alarm_definition.id,
                                                     user_id=user_id,
                                                     use_email=use_email,
                                                     use_redmine=use_redmine,
                                                     use_phone=use_phone,
                                                     use_log=use_log,
                                                     use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create CP02PMCO-WFP01-05-PARADK000 UserEventNotification message: \n', err.message
        else:
        '''
        if ref_def:
            alert_alarm_definition = SystemEventDefinition(reference_designator=ref_def)
            alert_alarm_definition.active = True
            alert_alarm_definition.event_type = event_type
            alert_alarm_definition.array_name = array_name
            alert_alarm_definition.platform_name = platform_name
            alert_alarm_definition.instrument_name = ref_def
            alert_alarm_definition.instrument_parameter = instrument_parameter
            alert_alarm_definition.instrument_parameter_pdid = instrument_parameter_pdid
            alert_alarm_definition.operator = operator
            alert_alarm_definition.created_time = create_time
            alert_alarm_definition.uframe_filter_id = uframe_id
            alert_alarm_definition.high_value = high_value
            alert_alarm_definition.low_value = low_value
            alert_alarm_definition.severity = severity
            alert_alarm_definition.stream = stream
            alert_alarm_definition.escalate_on = escalate_on
            alert_alarm_definition.escalate_boundary = escalate_boundary
            if event_type == 'alarm':
                alert_alarm_definition.uframe_filter_id = uframe_id
            try:
                db.session.add(alert_alarm_definition)
                db.session.commit()
            except Exception as err:
                print '\n *** %s **** message: %s' % (ref_def,err.message)
            try:
                # Create corresponding UserEventNotification when alert or alarm definition is created
                new_id = UserEventNotification.insert_user_event_notification(
                                                     system_event_definition_id=alert_alarm_definition.id,
                                                     user_id=user_id,
                                                     use_email=use_email,
                                                     use_redmine=use_redmine,
                                                     use_phone=use_phone,
                                                     use_log=use_log,
                                                     use_sms=use_sms)
            except Exception as err:
                print '\n ******* Create UserEventNotification message: \n', err.message
        return alert_alarm_definition