Skip to content

Commit

Permalink
Modify call in views to make ES fields optional. Further add caching …
Browse files Browse the repository at this point in the history
…for es health in handler code
  • Loading branch information
Mraoul committed May 15, 2019
1 parent b8176b6 commit dc32479
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 8 additions & 5 deletions pydat/pydat/handlers/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ def cluster_stats():


def cluster_health():
try:
es = es_connector()
except Exception as e:
raise
health = cache.get('cluster_health')
if health is None:
try:
es = es_connector()
except Exception as e:
raise

health = es.cluster.health()
health = es.cluster.health()
cache.set('cluster_health', health, CACHE_TIME)

return health['status']

Expand Down
14 changes: 8 additions & 6 deletions pydat/pydat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __renderErrorPage__(request, message, data=None):
return render(request, 'error.html', context=context)


def __createRequestContext__(data=None):
def __createRequestContext__(data=None, include_es=True):
# Default to adding search forms to every context
search_f = domain_form()
pdns_f_dyn = pdns_form_dynamic()
Expand All @@ -44,14 +44,15 @@ def __createRequestContext__(data=None):
'advdomain_form': advdomain_f,
'pdns_form_dynamic': pdns_f_dyn,
'rpdns_form_dynamic': rpdns_f_dyn,
'latest_version': handler.lastVersion(),
'pdns_sources': [
mod_data.config
for mod_data in passive.PDNS_HANDLER_MODS.values()]}

ctx_var['health'] = handler.cluster_health().capitalize()
ctx_var['record_count'] = handler.record_count()
ctx_var['last_import'] = handler.lastUpdate()
if include_es:
ctx_var['latest_version'] = handler.lastVersion()
ctx_var['health'] = handler.cluster_health().capitalize()
ctx_var['record_count'] = handler.record_count()
ctx_var['last_import'] = handler.lastUpdate()

if data is not None:
ctx_var.update(data)
Expand Down Expand Up @@ -115,7 +116,8 @@ def help(request):
except Exception as e:
helptxt = "Unable to render help text."

context = __createRequestContext__(data={'help': helptxt})
context = __createRequestContext__(
data={'help': helptxt}, include_es=False)
return render(request, 'help.html', context=context)


Expand Down

0 comments on commit dc32479

Please sign in to comment.