Ejemplo n.º 1
0
def post_event(request):
    if request.method == 'POST':
        event = json.loads(request.body)
        assert isinstance(event, dict)

        tags = event.get('tags')
        if tags is not None:
            if isinstance(tags, list):
                tags = ' '.join(tags)
            elif not isinstance(tags, six.string_types):
                return HttpResponse(json.dumps({
                    'error':
                    '"tags" must be an array or space-separated string'
                }),
                                    status=400)
        else:
            tags = None
        if 'when' in event:
            when = epoch_to_dt(event['when'])
        else:
            when = now()

        Event.objects.create(
            what=event.get('what'),
            tags=tags,
            when=when,
            data=event.get('data', ''),
        )

        return HttpResponse(status=200)
    else:
        return HttpResponse(status=405)
Ejemplo n.º 2
0
def get_data(request):
    query_params = request.GET.copy()
    query_params.update(request.POST)

    if 'jsonp' in query_params:
        response = HttpResponse("%s(%s)" %
                                (query_params.get('jsonp'),
                                 json.dumps(fetch(request), cls=EventEncoder)),
                                content_type='text/javascript')
    else:
        response = HttpResponse(json.dumps(fetch(request), cls=EventEncoder),
                                content_type='application/json')
    return response
Ejemplo n.º 3
0
def functionList(request, queryParams):
    if request.method != 'GET':
        return HttpResponse(status=405)

    if queryParams.get('type') == 'pie':
        funcs = PieFunctions()
    else:
        funcs = SeriesFunctions()

    grouped = queryParams.get('grouped', '').lower() in ['1', 'true']
    group = queryParams.get('group')
    result = {}

    for (name, func) in funcs.items():
        info = functionInfo(name, func)
        if group is not None and group != info['group']:
            continue

        if grouped:
            if info['group'] not in result:
                result[info['group']] = {}
            result[info['group']][name] = info
        else:
            result[name] = info

    return result
Ejemplo n.º 4
0
def tagList(request, queryParams):
    if request.method != 'GET':
        return HttpResponse(status=405)

    return STORE.tagdb.list_tags(
        tagFilter=request.GET.get('filter'),
        limit=request.GET.get('limit'),
        requestContext=_requestContext(request, queryParams),
    )
Ejemplo n.º 5
0
def tagDetails(request, queryParams, tag):
    if request.method != 'GET':
        return HttpResponse(status=405)

    return STORE.tagdb.get_tag(
        tag,
        valueFilter=queryParams.get('filter'),
        limit=queryParams.get('limit'),
        requestContext=_requestContext(request, queryParams),
    )
Ejemplo n.º 6
0
def tagSeries(request, queryParams):
    if request.method != 'POST':
        return HttpResponse(status=405)

    path = queryParams.get('path')
    if not path:
        raise HttpError('no path specified', status=400)

    return STORE.tagdb.tag_series(path,
                                  requestContext=_requestContext(request))
Ejemplo n.º 7
0
def functionDetails(request, queryParams, name):
    if request.method != 'GET':
        return HttpResponse(status=405)

    try:
        if queryParams.get('type') == 'pie':
            func = PieFunction(name)
        else:
            func = SeriesFunction(name)
    except KeyError:
        raise HttpError('Function not found: %s' % name, status=404)

    return functionInfo(name, func)
Ejemplo n.º 8
0
def delSeries(request, queryParams):
    if request.method != 'POST':
        return HttpResponse(status=405)

    paths = []
    # Normal format: ?path=name;tag1=value1;tag2=value2&path=name;tag1=value2;tag2=value2
    if len(queryParams.getlist('path')) > 0:
        paths = queryParams.getlist('path')
    # Rails/PHP/jQuery common practice format: ?path[]=...&path[]=...
    elif len(queryParams.getlist('path[]')) > 0:
        paths = queryParams.getlist('path[]')
    else:
        raise HttpError('no path specified', status=400)

    return STORE.tagdb.del_multi_series(
        paths, requestContext=_requestContext(request))
Ejemplo n.º 9
0
def autoCompleteTags(request, queryParams):
    if request.method not in ['GET', 'POST']:
        return HttpResponse(status=405)

    exprs = []
    # Normal format: ?expr=tag1=value1&expr=tag2=value2
    if len(queryParams.getlist('expr')) > 0:
        exprs = queryParams.getlist('expr')
    # Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
    elif len(queryParams.getlist('expr[]')) > 0:
        exprs = queryParams.getlist('expr[]')

    return STORE.tagdb_auto_complete_tags(
        exprs,
        tagPrefix=queryParams.get('tagPrefix'),
        limit=queryParams.get('limit'),
        requestContext=_requestContext(request, queryParams))
Ejemplo n.º 10
0
def findSeries(request, queryParams):
    if request.method not in ['GET', 'POST']:
        return HttpResponse(status=405)

    exprs = []
    # Normal format: ?expr=tag1=value1&expr=tag2=value2
    if len(queryParams.getlist('expr')) > 0:
        exprs = queryParams.getlist('expr')
    # Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
    elif len(queryParams.getlist('expr[]')) > 0:
        exprs = queryParams.getlist('expr[]')

    if not exprs:
        raise HttpError('no tag expressions specified', status=400)

    return STORE.tagdb.find_series(exprs,
                                   requestContext=_requestContext(request))
Ejemplo n.º 11
0
def autoCompleteValues(request, queryParams):
    if request.method not in ['GET', 'POST']:
        return HttpResponse(status=405)

    exprs = []
    # Normal format: ?expr=tag1=value1&expr=tag2=value2
    if len(queryParams.getlist('expr')) > 0:
        exprs = queryParams.getlist('expr')
    # Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
    elif len(queryParams.getlist('expr[]')) > 0:
        exprs = queryParams.getlist('expr[]')

    tag = queryParams.get('tag')
    if not tag:
        raise HttpError('no tag specified', status=400)

    return STORE.tagdb_auto_complete_values(
        exprs,
        tag,
        valuePrefix=queryParams.get('valuePrefix'),
        limit=queryParams.get('limit'),
        requestContext=_requestContext(request))