예제 #1
0
def get(request, id_ds):
    try:
        obj = DataTemplateData.objects.get(local_data_id=id_ds)
        
        path = obj.data_source_path.replace("<path_rra>", RRA_PATH)
        if path is None: 
            raise("Can't find data related to datasouce %s" % data)
        start = retrieve_param(request, "start", "-1h")        
        data = convert_to_json(extract_data(path, 300, start))
        response =  render_to_response(
            "cacti_rest/json/datasource.json",
            {
             "resource_type": "datasource",
             "data": data,
             "id": id_ds,
             "url": reverse("resource_datasource", args=[id_ds, ]),
             "host_resource": reverse("resource_host", args=[obj.local_data_id.host_id.id, ]),
            },
            content_type="application/json") 
        response['Cache-Control'] = 'no-cache'
        return response
    except Exception, ex:
        logging.error("Resource get error: %s" % ex)
        
        response =  HttpResponseServerError(
                content=simplejson.dumps({"errors": str(ex)}),                
                content_type="application/json") 
        
        response['Cache-Control'] = 'no-cache'
        return response
예제 #2
0
def get(request):
    try:
        offset = int(retrieve_param(request, "offset", 0))
        limit = int(retrieve_param(request, "limit", 50)) + offset 
        #print "offset: %s; Limit: %s" % (offset, limit)
        data = [{"resource_type": "host", "url": reverse("resource_host", args=[x.id, ])} for x in Host.objects.all()[offset:limit]]
        response =  render_to_response(
            "cacti_rest/json/list.json",
            {"data": data},
            content_type="application/json") 
        response['Cache-Control'] = 'no-cache'
        return response
        
    except Exception, ex:
        logging.error("Resource get error: %s" % ex)
        response =  HttpResponseServerError(
            content=simplejson.dumps({"errors": str(ex)}),
            content_type="application/json") 
        response['Cache-Control'] = 'no-cache'
        return response
def get(request, host):
    try:        
        offset = int(retrieve_param(request, "offset", 0))
        limit = int(retrieve_param(request, "limit", 50)) + offset 
        query = DataLocal.objects.filter(host_id=host)[offset:limit]
        #print query.query
        data = [{"resource_type": "datasource", "url": reverse("resource_datasource", args=[x.id, ])} for x in query]
        #print "data: %s" % data
        response =  render_to_response(
            "cacti_rest/json/list.json",
            {"data": data},
            content_type="application/json") 
        response['Cache-Control'] = 'no-cache'
        return response
        
    except AttributeError, ex:
        
        logging.error("Resource get error: %s" % ex)
        response =  HttpResponseServerError(
            content=simplejson.dumps({"errors": str(ex)}),
            content_type="application/json") 
        response['Cache-Control'] = 'no-cache'
        return response