예제 #1
0
def search_logs(type_=None,
                sort_field='datetime_utc',
                sort_order='desc',
                size=1000):
    es_client = get_state_es_client()

    query = {'match_all': {}}

    if type_ is not None:
        if not isinstance(type_, (list, tuple)):
            type_ = [type_]

        query = {
            'terms': {
                'type': type_,
            },
        }

    results = es_client.search(
        index=ES_LOGS_INDEX_NAME,
        size=size,
        body={
            'query': query,
            'sort': {
                sort_field: sort_order,
            },
        },
    )

    return results
예제 #2
0
def delete_cluster(cluster_slug):
    es_client = get_state_es_client()
    es_client.delete(
        index=ES_CLUSTERS_INDEX_NAME,
        id=cluster_slug,
    )
    return jsonify(deleted=True, slug=cluster_slug), 200
예제 #3
0
def list_clusters():
    es_client = get_state_es_client()
    result = es_client.search(
        index=ES_CLUSTERS_INDEX_NAME,
        size=1000,
    )
    clusters = {hit['_id']: hit['_source'] for hit in result['hits']['hits']}
    return jsonify(clusters=clusters), 200
예제 #4
0
def create_log(type_, cluster_slug, data):
    es_client = get_state_es_client()
    es_client.create(
        index=ES_LOGS_INDEX_NAME,
        body={
            'type': type_,
            'cluster_slug': cluster_slug,
            'data': data,
            'datetime_utc': datetime.utcnow(),
        },
    )
예제 #5
0
def create_cluster():
    request_data = request.get_json()

    doc = {
        'name': request_data['name'],
        'base_url': request_data['base_url'],
    }
    slug = slugify(request_data['name'])

    es_client = get_state_es_client()
    es_client.create(
        index=ES_CLUSTERS_INDEX_NAME,
        id=slug,
        body=doc,
    )

    return jsonify(created=True, slug=slug, data=request_data), 201