forked from marineam/nagcat
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request marineam#2 from mythmon/intern1
Major Changes: - Changed configurator to be auto complete text boxes. - Allow configurator to add multiple hosts/services/groups at a time. - Gave configurator sorting and filtering capabilities. - Use local storage to store user preferences. - Use configurator for everything. - Collapsible graphs. - Choice of localtime or UTC for graphs. - Upgrade to JQuery 1.6.
- Loading branch information
Showing
18 changed files
with
2,060 additions
and
1,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
*.swp | ||
*.pyc | ||
_trial_temp | ||
railroad/django.wsgi | ||
railroad/railroad/settings.py | ||
dropin.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,72 @@ | ||
from django.http import HttpResponse | ||
from railroad.viewhosts import views | ||
import itertools | ||
import json | ||
|
||
# This function is kind of crazy. It should give different results if called | ||
# twice with the same inputs. It's purpose is to suggest the right set of auto | ||
# complete possibilities when a user enters a common substring of two possible | ||
# auto complete suggestions. | ||
def transpose_combo(li, n, memo): | ||
key = repr(li) | ||
if key in memo: | ||
return memo[key].next() | ||
|
||
n = min(n,len(li)) | ||
combinations = itertools.combinations(li,n) | ||
transpose = zip(*combinations) | ||
memo[key] = iter(transpose) | ||
return memo[key].next() | ||
|
||
def autocomplete(request, context): | ||
query = request.GET.get('q', '') | ||
query = request.GET.get('term', '') | ||
limit = int(request.GET.get('limit', 10)) | ||
|
||
|
||
stat, obj = views.parse() | ||
|
||
choices = [] | ||
queries = [] | ||
q_results = [] | ||
result = "" | ||
|
||
if len(query.split(',')) > 1: | ||
queries = query.split(',') | ||
else: | ||
queries = [query] | ||
|
||
queries = [q.strip() for q in queries if q.strip()] | ||
queries = [q.strip() for q in query.split(',') if q.strip()] | ||
|
||
if context == 'host': | ||
choices = views.hostnames(stat) | ||
elif context == 'group': | ||
choices = [x['alias'] for x in views.grouplist(obj)] | ||
elif context == 'service': | ||
# servicesnames will return services with the sane name for different hosts, so | ||
# we make it a set to get rid of duplicate names | ||
# servicesnames will return services with the sane name for different | ||
# hosts, so we make it a set to get rid of duplicate names | ||
choices = set(views.servicenames(stat)) | ||
|
||
for q in queries: | ||
matching_names = [x for x in choices if x.lower().startswith(q)] | ||
matching_names = [x for x in choices if x.lower().startswith(q.lower())] | ||
q_results.append(matching_names) | ||
results = itertools.product(*q_results) | ||
|
||
# this craziness is to deal with this situation: let valid completions be | ||
# 'ab', 'ac'. User enters "a, a". Auto complete should give back ['ab, | ||
# ac'], not ['ab, ac', 'ac, ab']. | ||
memo = {} | ||
counts = {} | ||
for q in q_results: | ||
key = repr(q) # lists aren't hashable :( but strings are :) | ||
if key in counts: | ||
counts[key] += 1 | ||
else: | ||
counts[key] = 1 | ||
|
||
product_foder = [] | ||
for q in q_results: | ||
try: | ||
product_foder.append(transpose_combo(q, counts[repr(q)], memo)) | ||
except StopIteration: | ||
# That means the user entered too many of the substring. ignore an | ||
# excess entries. | ||
pass | ||
# end craziness | ||
|
||
results = itertools.product(*product_foder) | ||
results = [','.join(result) for result in results] | ||
result = '\n'.join(results) | ||
return HttpResponse(result) | ||
result = [ { "value" : r } for r in results ] | ||
|
||
return HttpResponse(json.dumps(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.