From 5de4020d2a2ed1028ce39d3a8bd3a8bd865fc8cd Mon Sep 17 00:00:00 2001 From: Tim Laszlo Date: Tue, 5 Jun 2012 14:41:43 -0500 Subject: web_reports: added a view to show the most common configuration problems --- src/lib/Bcfg2/Server/Reports/reports/views.py | 53 ++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server/Reports/reports/views.py') diff --git a/src/lib/Bcfg2/Server/Reports/reports/views.py b/src/lib/Bcfg2/Server/Reports/reports/views.py index 02d633a5e..38a219167 100644 --- a/src/lib/Bcfg2/Server/Reports/reports/views.py +++ b/src/lib/Bcfg2/Server/Reports/reports/views.py @@ -47,7 +47,7 @@ def timeview(fn): """ def _handle_timeview(request, **kwargs): """Send any posts back.""" - if request.method == 'POST': + if request.method == 'POST' and request.POST.get('op', '') == 'timeview': cal_date = request.POST['cal_date'] try: fmt = "%Y/%m/%d" @@ -154,6 +154,57 @@ def config_item_list(request, type, timestamp=None): context_instance=RequestContext(request)) +@timeview +def common_problems(request, timestamp=None, threshold=None): + """Mine config entries""" + + if request.method == 'POST': + try: + threshold = int(request.POST['threshold']) + view, args, kw = resolve(request.META['PATH_INFO']) + kw['threshold'] = threshold + return HttpResponseRedirect(reverse(view, + args=args, + kwargs=kw)) + except: + pass + + try: + threshold = int(threshold) + except: + threshold = 10 + + c_intr = Interaction.objects.get_interaction_per_client_ids(timestamp) + data_list = { 1: {}, 2: {}, 3: {}} + ldata = list(Entries_interactions.objects.filter( + interaction__in=c_intr).values()) + + entry_ids = set([x['entry_id'] for x in ldata]) + reason_ids = set([x['reason_id'] for x in ldata]) + for x in ldata: + type = x['type'] + data_key = (x['entry_id'], x['reason_id']) + try: + data_list[type][data_key].append(x['id']) + except KeyError: + data_list[type][data_key] = [x['id']] + + entries = Entries.objects.in_bulk(entry_ids) + reasons = Reason.objects.in_bulk(reason_ids) + + lists = [] + for type, type_name in TYPE_CHOICES: + lists.append([type_name.lower(), [(entries[e[0][0]], reasons[e[0][1]], e[1]) + for e in sorted(data_list[type].items(), key=lambda x: len(x[1]), reverse=True) + if len(e[1]) > threshold]]) + + return render_to_response('config_items/common.html', + {'lists': lists, + 'timestamp': timestamp, + 'threshold': threshold}, + context_instance=RequestContext(request)) + + @timeview def client_index(request, timestamp=None): """ -- cgit v1.2.3-1-g7c22