Exemplo n.º 1
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        polleddata = session.query(
            models.Polleddata).filter_by(id=data.get('id')).first()
        if polleddata is None:
            return custom_response_flask_restful(request, 404,
                                                 "polleddata chua ton tai",
                                                 None, None)

        if data.get('name'): polleddata.name = data.get('name')
        if data.get('agent'): polleddata.agent = data.get('agent')
        if data.get('period'): polleddata.period = data.get('period')
        if data.get('active'): polleddata.active = data.get('active')
        if data.get('threshold_activate'):
            polleddata.threshold_activate = data.get('threshold_activate')
        if data.get('devicedetails_did'):
            polleddata.devicedetails_did = data.get('devicedetails_did')
        if data.get('groupdevices_group_id'):
            polleddata.groupdevices_group_id = data.get(
                'groupdevices_group_id')
        if data.get('threshold_lists_id'):
            polleddata.threshold_lists_id = data.get('threshold_lists_id')
        if data.get('metricdetails_metricid'):
            polleddata.metricdetails_metricid = data.get(
                'metricdetails_metricid')

        session.add(polleddata)
        session.commit()

        res = models.to_json(polleddata, 'Polleddata', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 2
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        device = session.query(
            models.Devicedetail).filter_by(did=data.get('did')).first()
        if device is None:
            return custom_response_flask_restful(request, 404,
                                                 "device chua ton tai", None,
                                                 None)

        if data.get('mode'): device.mode = data.get('mode')
        if data.get('status'): device.status = data.get('status')
        if data.get('errorstring'):
            device.errorstring = data.get('errorstring')
        if data.get('timeinterval'):
            device.timeinterval = data.get('timeinterval')
        device.last_updated_on = datetime.now()
        if data.get('isprofilebased'):
            device.isprofilebased = data.get('isprofilebased')
        if data.get('fetch_rules'):
            device.fetch_rules = data.get('fetch_rules')
        if data.get('ip'): device.ip = data.get('ip')

        session.add(device)
        session.commit()

        res = models.to_json(device, 'Devicedetail', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 3
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        threshold_lists = session.query(models.Threshold_list).filter_by(id=data.get('threshold_lists_id')).first()
        if threshold_lists is None:
            return custom_response_flask_restful(request, 404, "threshold_lists chua ton tai", None, None)

        thresholdobject = models.Thresholdobject(name=data.get('name', ""), kind=data.get('kind', ""),
                                                 priority=data.get('priority', ""), category=data.get('category', ""),
                                                 thresholdvalue=data.get('thresholdvalue', ""),
                                                 rearmvalue=data.get('rearmvalue', ""),
                                                 mmessage=data.get('mmessage', ""), allowed=data.get('allowed', ""),
                                                 is_customize=data.get('is_customize', ""),
                                                 consecutive_time=data.get('consecutive_time', ""),
                                                 operator=data.get('operator', ""), severity=data.get('severity', "")
                                                 , threshold_lists_id=data.get('threshold_lists_id', "")
                                                 )

        session.add(thresholdobject)
        session.commit()

        res = models.to_json(thresholdobject, 'Thresholdobject', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 4
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        if data.get("rearmvalue") is None:
            return custom_response_flask_restful(request, 404,
                                                 "rearmvalue phai duoc set",
                                                 None, None)

        threshold_list = session.query(models.Threshold_list).filter_by(
            id=data.get('threshold_list_id')).first()
        if threshold_list is None:
            return custom_response_flask_restful(
                request, 404, "threshold_list chua ton tai", None, None)
        thresholdobjects = threshold_list.thresholdobjects
        for i in range(0, len(thresholdobjects)):
            thresholdobjects[i].thresholdvalue = data.get('threshold_value_' +
                                                          str(i + 1))
            thresholdobjects[i].rearmvalue = data.get('rearmvalue')

        session.add(threshold_list)
        session.commit()

        res = models.to_json(threshold_list, 'Threshold_list', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 5
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        metricdetail = session.query(models.Metricdetail).filter_by(metricid=data.get('metricdetails_metricid')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404, "metricdetail chua ton tai", None, None)
        threshold_lists = session.query(models.Threshold_list).filter_by(id=data.get('threshold_lists_id')).first()
        if threshold_lists is None:
            return custom_response_flask_restful(request, 404, "threshold_lists chua ton tai", None, None)

        groupdevices = session.query(models.Groupdevice).filter_by(group_id=data.get('groupdevices_group_id')).first()
        if groupdevices is None:
            return custom_response_flask_restful(request, 404, "groupdevices chua ton tai", None, None)

        devicedetails = session.query(models.Devicedetail).filter_by(did=data.get('devicedetails_did')).first()
        if devicedetails is None:
            return custom_response_flask_restful(request, 404, "devicedetails chua ton tai", None, None)

        polleddata = models.Polleddata(name=data.get('name', ""), agent=data.get('agent', ""),
                                       period=data.get('period', ""), active=data.get('active', ""),
                                       threshold_activate=data.get('threshold_activate', ""),
                                       devicedetails_did=data.get('devicedetails_did', ""),
                                       groupdevices_group_id=data.get('groupdevices_group_id', ""),
                                       threshold_lists_id=data.get('threshold_lists_id', ""),
                                       metricdetails_metricid=data.get('metricdetails_metricid', ""))

        session.add(polleddata)
        session.commit()

        res = models.to_json(polleddata, 'Polleddata', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 6
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        if data.get('metricdetail_id') is None or data.get('threshold_list_id') is None:
            return custom_response_flask_restful(request, 404, "metricdetail_id and threshold_list_id is required", None, None)
        metricdetail = session.query(models.Metricdetail).filter_by(metricid=data.get('metricdetail_id')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404, "metricdetail chua ton tai", None, None)
        threshold_lists = session.query(models.Threshold_list).filter_by(id=data.get('threshold_list_id')).first()
        if threshold_lists is None:
            return custom_response_flask_restful(request, 404, "threshold_lists chua ton tai", None, None)


        check_polldata=  session.query(models.Polldatatemplate).filter_by(metricdetail_id=data.get('metricdetail_id'), threshold_list_id=data.get('threshold_list_id', "")).first()
        if check_polldata is not None:
            return custom_response_flask_restful(request, 404, "polldatatemplate voi metric id: " + str(data.get('metricdetail_id'))  + " threshold_list_id " + str(data.get('threshold_list_id')) + " da ton tai. Please change to update polldatatemplate with id:  "+ str(check_polldata.id)  , None, None)
        polldatatemplate = models.Polldatatemplate(name=data.get('name', ""), agent=data.get('agent', ""),
                                                   period=data.get('period', ""), active=data.get('active', ""),
                                                   oid=data.get('oid', ""),
                                                   threshold_activate=data.get('threshold_activate', ""),
                                                   protocol=data.get('protocol', ""),
                                                   metricdetail_id=data.get('metricdetail_id', ""),
                                                   threshold_list_id=data.get('threshold_list_id', ""))

        session.add(polldatatemplate)
        session.commit()

        res = models.to_json(polldatatemplate, 'Polldatatemplate', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 7
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        groupdevicesdevicedetail = session.query(
            models.Groupdevicesdevicedetail).filter_by(
                id=data.get('id')).first()
        if groupdevicesdevicedetail is None:
            return custom_response_flask_restful(
                request, 404, "groupdevicesdevicedetail chua ton tai", None,
                None)

        if data.get('devicedetail_did'):
            groupdevicesdevicedetail.devicedetail_did = data.get(
                'devicedetail_did')
        if data.get('groupdevice_id'):
            groupdevicesdevicedetail.groupdevice_id = data.get(
                'groupdevice_id')
        session.add(groupdevicesdevicedetail)
        session.commit()

        res = models.to_json(groupdevicesdevicedetail,
                             'Groupdevicesdevicedetail', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 8
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        polldatatemplate = session.query(
            models.Polldatatemplate).filter_by(id=data.get('id')).first()
        if polldatatemplate is None:
            return custom_response_flask_restful(
                request, 404, "polldatatemplate chua ton tai", None, None)
        if data.get('name'): polldatatemplate.name = data.get('name')
        if data.get('agent'): polldatatemplate.agent = data.get('agent')
        if data.get('period'): polldatatemplate.period = data.get('period')
        if data.get('active'): polldatatemplate.active = data.get('active')
        if data.get('oid'): polldatatemplate.oid = data.get('oid')
        if data.get('threshold_activate'):
            polldatatemplate.threshold_activate = data.get(
                'threshold_activate')
        if data.get('protocol'):
            polldatatemplate.protocol = data.get('protocol')
        if data.get('metricdetail_id'):
            polldatatemplate.metricdetail_id = data.get('metricdetail_id')
        if data.get('threshold_list_id'):
            polldatatemplate.threshold_list_id = data.get('threshold_list_id')

        session.add(polldatatemplate)
        session.commit()

        res = models.to_json(polldatatemplate, 'Polldatatemplate', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 9
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        metricdetails = session.query(models.Metricdetail).filter_by(
            metricid=data.get('metricid')).first()
        if metricdetails is None:
            return custom_response_flask_restful(request, 404,
                                                 "metricdetails chua ton tai",
                                                 None, None)
        protocoldetails = session.query(models.Protocoldetail).filter_by(
            protocolid=data.get('protocolid')).first()
        if protocoldetails is None:
            return custom_response_flask_restful(
                request, 404, "protocoldetails chua ton tai", None, None)

        if data.get('metricname'):
            metricdetails.metricname = data.get('metricname')
        if data.get('description'):
            metricdetails.description = data.get('description')
        if data.get('displayname'):
            metricdetails.displayname = data.get('displayname')
        if data.get('metrictype'):
            metricdetails.metrictype = data.get('metrictype')
        if data.get('datatype'): metricdetails.datatype = data.get('datatype')
        if data.get('protocolid'):
            metricdetails.protocolid = data.get('protocolid')

        session.add(metricdetails)
        session.commit()

        res = models.to_json(metricdetails, 'Metricdetail', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 10
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        devicedetail = session.query(models.Devicedetail).filter_by(did=data.get('deviceid')).first()
        if devicedetail is None:
            return custom_response_flask_restful(request, 404, "devicedetail chua ton tai", None, None)
        metricdetail = session.query(models.Metricdetail).filter_by(metricid=data.get('metricid')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404, "metricdetail chua ton tai", None, None)

        alert = models.Alert(alarmRaisedTime=data.get('alarmRaisedTime', ""),
                             alarmChangedTime=data.get('alarmChangedTime', ""),
                             alarmClearedTime=data.get('alarmClearedTime', ""), state=data.get('state', ""),
                             perceivedSeverity=data.get('perceivedSeverity', ""), eventTime=data.get('eventTime', ""),
                             eventType=data.get('eventType', ""), faultType=data.get('faultType', ""),
                             probableCause=data.get('probableCause', ""), isRootCause=data.get('isRootCause', ""),
                             correlatedAlarmId=data.get('correlatedAlarmId', ""),
                             faultDetails=data.get('faultDetails', ""), deviceid=data.get('deviceid', ""),
                             metricid=data.get('metricid', ""))

        session.add(alert)
        session.commit()

        res = models.to_json(alert, 'Alert', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 11
0
    def get(self):
        if not (request.args.get('device_id') or request.args.get('metricid')):
            abort(400)

        data = {
            'device_id': int(request.args.get('device_id')),
            'metricid': int(request.args.get('metricid'))
        }
        metricdetail = session.query(models.Metricdetail).filter_by(
            metricid=data.get('metricid')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404,
                                                 "metricdetail chua ton tai",
                                                 None, None)

        device = session.query(models.Devicedetail).filter_by(
            did=data.get('device_id', "")).first()
        if device is None:
            return custom_response_flask_restful(request, 404,
                                                 "device chua ton tai", None,
                                                 None)
        polleddata = session.query(models.Polleddata).filter_by(
            devicedetails_did=device.did,
            metricdetails_metricid=metricdetail.metricid).first()
        if polleddata is None:
            return custom_response_flask_restful(request, 404,
                                                 "polleddata chua ton tai",
                                                 None, None)

        threshold_list_id = polleddata.threshold_lists_id
        threshold_list = session.query(
            models.Threshold_list).filter_by(id=threshold_list_id).first()
        if threshold_list is None:
            return custom_response_flask_restful(
                request, 404, "threshold_list chua ton tai", None, None)
        else:
            thresholdobjects = threshold_list.thresholdobjects
            res_json = {
                'metricdetail':
                models.to_json(metricdetail, 'Metricdetail', False),
                'device':
                models.to_json(device, 'Devicedetail', False),
                'polleddata':
                models.to_json(polleddata, 'Polleddata', False),
                'threshold_list':
                models.to_json(threshold_list, 'Threshold_list', False),
                'thresholdobjects':
                models.to_json(thresholdobjects, 'Thresholdobject', True)
            }
            session.commit()

        session.close()
        return custom_response_flask_restful(request, 201, None, 'Ok roi nhe',
                                             res_json)
Exemplo n.º 12
0
    def get(self, alertid):
        alert = session.query(models.Alert).filter_by(alertid=alertid).first()
        session.commit()
        if alert is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None, models.to_json(alert, 'Alert', False))
Exemplo n.º 13
0
    def get(self, id):
        polleddata = session.query(models.Polleddata).filter_by(id=id).first()
        session.commit()
        if polleddata is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(polleddata, 'Polleddata', False))
Exemplo n.º 14
0
    def get(self, did):
        devicedetails = session.query(
            models.Devicedetail).filter_by(did=did).first()
        session.commit()
        if devicedetails is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(devicedetails, 'Devicedetail', False))
Exemplo n.º 15
0
    def get(self, id):
        thresholdobjects = session.query(
            models.Thresholdobject).filter_by(id=id).first()
        session.commit()
        if thresholdobjects is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(thresholdobjects, 'Thresholdobject', False))
Exemplo n.º 16
0
    def get(self, protocolid):
        protocoldetails = session.query(
            models.Protocoldetail).filter_by(protocolid=protocolid).first()
        session.commit()
        if protocoldetails is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(protocoldetails, 'Protocoldetail', False))
Exemplo n.º 17
0
    def get(self, metricid):
        metricdetails = session.query(
            models.Metricdetail).filter_by(metricid=metricid).first()
        session.commit()
        if metricdetails is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(metricdetails, 'Metricdetail', False))
Exemplo n.º 18
0
    def get(self, group_id):
        groupalerts = session.query(
            models.Groupalert).filter_by(group_id=group_id).first()
        session.commit()
        if groupalerts is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(groupalerts, 'Groupalert', False))
Exemplo n.º 19
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        protocoldetail = session.query(models.Protocoldetail).filter_by(
            protocolid=data.get('protocolid')).first()
        if protocoldetail is None:
            return custom_response_flask_restful(
                request, 404, "protocoldetail chua ton tai", None, None)
        if data.get('protocolname'):
            protocoldetail.protocolname = data.get('protocolname')

        session.add(protocoldetail)
        session.commit()

        res = models.to_json(protocoldetail, 'Protocoldetail', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 20
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        threshold_list = session.query(
            models.Threshold_list).filter_by(id=data.get('id')).first()
        if threshold_list is None:
            return custom_response_flask_restful(
                request, 404, "threshold_list chua ton tai", None, None)

        if data.get('description'):
            threshold_list.description = data.get('description')

        session.add(threshold_list)
        session.commit()

        res = models.to_json(threshold_list, 'Threshold_list', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 21
0
    def get(self, id):
        groupdevicesdevicedetails = session.query(
            models.Groupdevicesdevicedetail).filter_by(id=id).first()
        session.commit()
        if groupdevicesdevicedetails is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(groupdevicesdevicedetails,
                           'Groupdevicesdevicedetail', False))
Exemplo n.º 22
0
    def get(self, id):
        groupdevicepolledatatemplate = session.query(
            models.Groupevicepolledatatemplate).filter_by(id=id).first()
        session.commit()
        if groupdevicepolledatatemplate is None:
            abort(400)

        return custom_response_flask_restful(
            request, 200, None, None,
            models.to_json(groupdevicepolledatatemplate,
                           'Groupevicepolledatatemplate', False))
Exemplo n.º 23
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        groupdevices = session.query(models.Groupdevice).filter_by(group_id=data.get('groupdevices_group_id')).first()
        if groupdevices is None:
            return custom_response_flask_restful(request, 404, "groupdevices chua ton tai", None, None)
        polldatatemplate = session.query(models.Polldatatemplate).filter_by(id=data.get('polldatatemplate_id')).first()
        if polldatatemplate is None:
            return custom_response_flask_restful(request, 404, "polldatatemplate chua ton tai", None, None)
        groupdevicepolledatatemplate = models.Groupevicepolledatatemplate(
            groupdevices_group_id=data.get('groupdevices_group_id', ""),
            polldatatemplate_id=data.get('polldatatemplate_id', ""))

        session.add(groupdevicepolledatatemplate)
        session.commit()

        res = models.to_json(groupdevicepolledatatemplate, 'Groupevicepolledatatemplate', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 24
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        alert = session.query(
            models.Alert).filter_by(alertid=data.get('alertid')).first()
        if alert is None:
            return custom_response_flask_restful(request, 404,
                                                 "alert chua ton tai", None,
                                                 None)

        if data.get('alarmRaisedTime'):
            alert.alarmRaisedTime = data.get('alarmRaisedTime')
        if data.get('alarmChangedTime'):
            alert.alarmChangedTime = data.get('alarmChangedTime')
        if data.get('alarmClearedTime'):
            alert.alarmClearedTime = data.get('alarmClearedTime')
        if data.get('state'): alert.state = data.get('state')
        if data.get('perceivedSeverity'):
            alert.perceivedSeverity = data.get('perceivedSeverity')
        if data.get('eventTime'): alert.eventTime = data.get('eventTime')
        if data.get('eventType'): alert.eventType = data.get('eventType')
        if data.get('faultType'): alert.faultType = data.get('faultType')
        if data.get('probableCause'):
            alert.probableCause = data.get('probableCause')
        if data.get('isRootCause'): alert.isRootCause = data.get('isRootCause')
        if data.get('correlatedAlarmId'):
            alert.correlatedAlarmId = data.get('correlatedAlarmId')
        if data.get('faultDetails'):
            alert.faultDetails = data.get('faultDetails')
        if data.get('deviceid'): alert.deviceid = data.get('deviceid')
        if data.get('metricid'): alert.metricid = data.get('metricid')

        session.add(alert)
        session.commit()

        res = models.to_json(alert, 'Alert', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 25
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        groupalert = models.Groupalert(group_name=data.get('group_name', ""), group_desc=data.get('group_desc', ""))

        session.add(groupalert)
        session.commit()

        res = models.to_json(groupalert, 'Groupalert', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 26
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        groupdevice = session.query(models.Groupdevice).filter_by(
            group_id=data.get('group_id')).first()
        if groupdevice is None:
            return custom_response_flask_restful(request, 404,
                                                 "groupdevice chua ton tai",
                                                 None, None)
        if data.get('group_name'):
            groupdevice.group_name = data.get('group_name')
        if data.get('group_desc'):
            groupdevice.group_desc = data.get('group_desc')
        if data.get('is_manual'): groupdevice.is_manual = data.get('is_manual')

        session.add(groupdevice)
        session.commit()

        res = models.to_json(groupdevice, 'Groupdevice', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 27
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json
        if data.get("rearmvalue") is None:
            return custom_response_flask_restful(request, 404,
                                                 "rearmvalue phai duoc set",
                                                 None, None)
        metricdetail = session.query(models.Metricdetail).filter_by(
            metricid=data.get('metricid')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404,
                                                 "metricdetail chua ton tai",
                                                 None, None)

        device = session.query(models.Devicedetail).filter_by(
            did=data.get('device_id', "")).first()
        if device is None:
            return custom_response_flask_restful(request, 404,
                                                 "device chua ton tai", None,
                                                 None)
        polleddata = session.query(models.Polleddata).filter_by(
            devicedetails_did=device.did,
            metricdetails_metricid=metricdetail.metricid).first()
        if polleddata is None:
            return custom_response_flask_restful(request, 404,
                                                 "polleddata chua ton tai",
                                                 None, None)

        threshold_list_id = polleddata.threshold_lists_id
        threshold_list = session.query(
            models.Threshold_list).filter_by(id=threshold_list_id).first()
        if threshold_list is None:
            return custom_response_flask_restful(
                request, 404, "threshold_list chua ton tai", None, None)
        else:
            for id in range(1, 5):
                if data.get('threshold_value_' + str(id)):
                    thresholdobject = models.Thresholdobject(
                        name='threshold_template_' +
                        data.get('group_name', ""),
                        kind="long",
                        priority=id,
                        thresholdvalue=data.get('threshold_value_' + str(id)),
                        rearmvalue=data.get('rearmvalue', ""),
                        operator='operator',
                        is_customize=False,
                        threshold_lists_id=threshold_list.id)
                    session.add(thresholdobject)
            session.commit()
        res = models.to_json(threshold_list, 'Threshold_list', False)
        session.close()
        return custom_response_flask_restful(
            request, 201, None,
            'Ok roi nhe, check in http://127.0.0.1:1234/api/v1/threshold_lists/'
            + str(threshold_list.id), res)
Exemplo n.º 28
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json


        protocoldetail = models.Protocoldetail(protocolname=data.get('protocolname', ""))

        session.add(protocoldetail)
        session.commit()
        new_protocoldetail = models.Protocoldetail(protocolname=data.get('protocolname', ""))
        res = models.to_json(protocoldetail, 'Protocoldetail', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 29
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json


        threshold_list = models.Threshold_list(description=data.get('description', ""))

        session.add(threshold_list)
        session.commit()

        res = models.to_json(threshold_list, 'Threshold_list', False)
        session.close()
        return custom_response_flask_restful(request, 201, None, None, res)
Exemplo n.º 30
0
    def post(self):
        if not request.json:
            abort(400)
        else:
            data = request.json

        metricdetail = session.query(models.Metricdetail).filter_by(
            metricid=data.get('metricid')).first()
        if metricdetail is None:
            return custom_response_flask_restful(request, 404,
                                                 "metricdetail chua ton tai",
                                                 None, None)

        device = session.query(models.Devicedetail).filter_by(
            did=data.get('device_id', "")).first()
        if device is None:
            return custom_response_flask_restful(request, 404,
                                                 "device chua ton tai", None,
                                                 None)
        polleddata = session.query(models.Polleddata).filter_by(
            devicedetails_did=device.did,
            metricdetails_metricid=metricdetail.metricid).first()
        if polleddata is None:
            return custom_response_flask_restful(request, 404,
                                                 "polleddata chua ton tai",
                                                 None, None)

        threshold_list_id = polleddata.threshold_lists_id
        threshold_list = session.query(
            models.Threshold_list).filter_by(id=threshold_list_id).first()
        if threshold_list is None:
            return custom_response_flask_restful(
                request, 404, "threshold_list chua ton tai", None, None)
        else:
            thresholdobject = session.query(models.Thresholdobject).filter_by(
                id=data.get('threshold_id'),
                threshold_lists_id=threshold_list.id).first()
            if thresholdobject is None:
                return custom_response_flask_restful(
                    request, 404, "thresholdobject chua ton tai", None, None)
            else:
                session.delete(thresholdobject)
                session.commit()
        res = models.to_json(threshold_list, 'Threshold_list', False)
        session.close()
        return custom_response_flask_restful(
            request, 201, None,
            'Ok roi nhe, check in http://127.0.0.1:1234/api/v1/threshold_lists/'
            + str(threshold_list.id), res)