示例#1
0
def receive_alert_data(request):
    if request.POST:
        payload = json.loads(request.POST.get("payload", ""))

        database = OmniDatabase.Generic.InstantiateDatabase(
            'sqlite', '', '', settings.OMNIDB_DATABASE, '', '', '', '0', '')
        print('x')

        try:
            v_alert_id = database.v_connection.ExecuteScalar('''
                select a.alert_id
                from monitor_alert a
                inner join monitor_node n on a.node_id = n.node_id
                where n.node_name = '{0}'
                  and a.alert_name = '{1}'
                  and n.node_key = '{2}'
                limit 1
            '''.format(payload['node'], payload['alert'], payload['key']))
            print(v_alert_id)
            if v_alert_id:
                monitoring_core.receive_status(v_alert_id, payload['status'],
                                               payload['message'],
                                               payload['value'])

        except Exception as exc:
            return HttpResponse("not found")

    from django.middleware.csrf import get_token
    get_token(request)

    return HttpResponse(request)
示例#2
0
def receive_alert_data(request):
    if request.POST:
        payload = json.loads(request.POST.get("payload", ""))

        database = OmniDatabase.Generic.InstantiateDatabase(
            'sqlite',
            '',
            '',
            settings.OMNIDB_DATABASE,
            '',
            '',
            '',
            '0',
            ''
        )

        try:
            v_alert_id = database.v_connection.ExecuteScalar('''
                select a.alert_id
                from monitor_alert a
                inner join monitor_node n on a.node_id = n.node_id
                where n.node_name = '{0}'
                  and a.alert_name = '{1}'
                  and n.node_key = '{2}'
                limit 1
            '''.format(payload['node'],payload['alert'],payload['key']))
            if v_alert_id:
                monitoring_core.receive_status(v_alert_id,payload['status'],payload['message'],payload['value'])

        except Exception as exc:
            return HttpResponse("not found")

    from django.middleware.csrf import get_token
    get_token(request)

    return HttpResponse(request)