Skip to content
Permalink
Browse files
Completed index route for Distill status which lists all applications…
… registered and their document count split by type
  • Loading branch information
mooshu1x2 committed Jun 14, 2016
1 parent f5350d1 commit 35a4230865e20abb1f02e9e82c4c168d15f87376
Showing 1 changed file with 56 additions and 11 deletions.
@@ -20,6 +20,8 @@

import datetime
import json
import csv
import StringIO
import yaml
import urllib2

@@ -28,17 +30,61 @@
"""
class UserAle (object):

"""
Get Status of Elasticsearch Instance, show all applications registered and the number
of logs in each application (based on doc_type).
Example:
{
"author" : "Michelle Beard",
"email" : "mbeard@draper.com",
"name": "Distill",
"status" : true,
"version" : "1.0",
"apps" : {
"xdata_v3" : {
testing: 205,
parsed: 500,
},
"test_app" : {
logs: 500,
parsed: 100,
}
}
}
"""
@staticmethod
def getStatus ():
"""
Get Status of Elasticsearch Instance
"""
try:
res = es.ping ()
except ConnectionError as e:
res = False
return res

@staticmethod
def getApps ():
doc = {}
try:
cluster_status = es.cat.indices (h=["index"], pri=False)
x = cluster_status.strip ().splitlines()

for idx in x:
idx = idx.rstrip ()

# Ignore private indexes (like .kibana or .stout)
if idx [:1] != '4':
s = Search (using=es, index=idx)
s.aggs.bucket ('count_by_type', 'terms', field='_type')
response = s.execute ()
d = {}
for tag in response.aggregations.count_by_type.buckets:
d [tag ['key']] = tag ['doc_count']
doc [idx] = d

except TransportError as e:
doc ['error'] = e.info

return doc

"""
Register a new application in User Ale
Example:
@@ -98,20 +144,19 @@ def update (app):
return jsonify (status="not implemented")

"""
Delete an application from User Ale
Technically close the index so its content is not searchable.
Example:
{
}
"""
@staticmethod
def delete (app):
# try:
# res = es.indices.delete (index=app)
# return jsonify (status="Deleted index %s" % app)
# except TransportError as e:
# return jsonify (e.info)
return jsonify (status="not allowed")
try:
res = es.indices.close (index=app)
return jsonify (status="Deleted index %s" % app)
except TransportError as e:
return jsonify (e.info)

"""
Main method of entry to perform segmentation and integration of STOUT's master
@@ -167,7 +212,7 @@ def denoise (app, doc_type='parsed', save=False):
pass

"""
Helper method to gather cluster information
Helper method to gather cluster information for a specific index
"""
def get_cluster_status (app):
# Return cluster status, index health, and document count as string

0 comments on commit 35a4230

Please sign in to comment.