diff options
author | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-06-26 21:05:19 +0000 |
---|---|---|
committer | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-06-26 21:05:19 +0000 |
commit | 197aa7c0997ae91b8b1210b81daf952d6c681cb2 (patch) | |
tree | 27e21db1ae081e7c1190ff42a602300b508255ba /src/lib/Server/Reports/reports | |
parent | 83d43c6957a5e392cc7d82f14329f8305ef3ca79 (diff) | |
download | bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.tar.gz bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.tar.bz2 bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.zip |
updates reporting system to filter out 'expired' clients--allowing retired machines to disappear from reports
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3373 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Reports/reports')
-rw-r--r-- | src/lib/Server/Reports/reports/models.py | 26 | ||||
-rw-r--r-- | src/lib/Server/Reports/reports/templates/clients/index.html | 19 | ||||
-rw-r--r-- | src/lib/Server/Reports/reports/views.py | 32 |
3 files changed, 63 insertions, 14 deletions
diff --git a/src/lib/Server/Reports/reports/models.py b/src/lib/Server/Reports/reports/models.py index dff68d272..b54d83912 100644 --- a/src/lib/Server/Reports/reports/models.py +++ b/src/lib/Server/Reports/reports/models.py @@ -1,6 +1,8 @@ '''Django models for BCFG reports''' from django.db import models +from django.db.models import Q from datetime import datetime, timedelta +from time import strptime KIND_CHOICES = ( #These are the kinds of config elements @@ -16,6 +18,28 @@ PING_CHOICES = ( ('Up (Y)', 'Y'), ('Down (N)', 'N') ) +class ClientManager(models.Manager): + '''extended client manager functions''' + def active(self,timestamp='now'): + '''returns a set of clients that have been created and have not yet been + expired as of optional timestmamp argument. Timestamp should be a + string formatted in the fashion: 2006-01-01 00:00:00''' + + if timestamp=='now': + timestamp = datetime.now() + else: + print timestamp + try: + timestamp = datetime(*strptime(timestamp, "%Y-%m-%d %H:%M:%S")[0:6]) + except ValueError: + return self.filter(expiration__lt=timestamp, creation__gt=timestamp); + #this is a really hacky way to return an empty QuerySet + #this should return Client.objects.none() in Django development version. + + return self.filter(Q(expiration__gt=timestamp) | Q(expiration__isnull=True), + creation__lt=timestamp) + + class Client(models.Model): '''object representing every client we have seen stats for''' creation = models.DateTimeField() @@ -28,6 +52,8 @@ class Client(models.Model): def __str__(self): return self.name + objects = ClientManager() + class Admin: pass diff --git a/src/lib/Server/Reports/reports/templates/clients/index.html b/src/lib/Server/Reports/reports/templates/clients/index.html index f8dd9167c..cc33f72de 100644 --- a/src/lib/Server/Reports/reports/templates/clients/index.html +++ b/src/lib/Server/Reports/reports/templates/clients/index.html @@ -1,5 +1,11 @@ {% extends "base.html" %} +{% block extra_header_info %} +<script type="text/javascript" src="{% url Bcfg2.Server.Reports.reports.views.client_index %}../site_media/sorttable.js"></script> +<script type="text/javascript" src="{% url Bcfg2.Server.Reports.reports.views.client_index %}../site_media/CalendarPopup.js"></script> +<script language="JavaScript">var cal = new CalendarPopup();</script> +{% endblock%} + {% block title %}Client Index Listing{% endblock %} {% block pagebanner %} @@ -10,6 +16,19 @@ {% endblock %} {% block content %} +<div> +<span class="mini-date"> +<b>Enter date or use calendar popup: </b> +<form name="timestamp-select"> +<input type="text" name="date1" value="{{timestamp_date}}" size=10>@ +<input type="text" name="time" value="{{timestamp_time}}" size=8> +<a href="" onClick="cal.select(document.forms['timestamp-select'].date1,'anchor1','yyyy-MM-dd'); return false;" + name="anchor1" ID="anchor1">Calendar</A> +<input type="button" name="go" value="Go" onClick="location.href='{% url Bcfg2.Server.Reports.reports.views.client_index %}'+document.forms['timestamp-select'].date1.value+'@'+document.forms['timestamp-select'].time.value;" /> + | <input type="button" name="now" value="Now" onClick="location.href='{% url Bcfg2.Server.Reports.reports.views.client_index %}';"/> +</form> +</span><br/><br/><br/></div> + {% if client_list_a %} <table><tr><td align="top"> <ul style="list-style-type:none;"> diff --git a/src/lib/Server/Reports/reports/views.py b/src/lib/Server/Reports/reports/views.py index 1d7fabe52..3f58fb0d8 100644 --- a/src/lib/Server/Reports/reports/views.py +++ b/src/lib/Server/Reports/reports/views.py @@ -27,7 +27,7 @@ def config_item_modified(request, eyedee =None, timestamp = 'now'): "WHERE reports_client.current_interaction_id = reports_modified_interactions.interaction_id "+ "AND reports_modified_interactions.interaction_id = reports_interaction.id "+ "AND reports_modified_interactions.modified_id = %s", [eyedee]) - associated_client_list = Client.objects.filter(id__in=[x[0] for x in cursor.fetchall()]) + associated_client_list = Client.objects.active(timestamp).filter(id__in=[x[0] for x in cursor.fetchall()]) else: interact_queryset = Interaction.objects.interaction_per_client(timestamp) interactionlist = [] @@ -37,7 +37,7 @@ def config_item_modified(request, eyedee =None, timestamp = 'now'): "WHERE reports_modified_interactions.interaction_id IN %s "+ "AND reports_modified_interactions.interaction_id = reports_interaction.id "+ "AND reports_modified_interactions.modified_id = %s", [interactionlist, eyedee]) - associated_client_list = Client.objects.filter(id__in=[x[0] for x in cursor.fetchall()]) + associated_client_list = Client.objects.active(timestamp).filter(id__in=[x[0] for x in cursor.fetchall()]) else: associated_client_list = [] @@ -62,7 +62,7 @@ def config_item_bad(request, eyedee = None, timestamp = 'now'): "WHERE reports_client.current_interaction_id = reports_bad_interactions.interaction_id "+ "AND reports_bad_interactions.interaction_id = reports_interaction.id "+ "AND reports_bad_interactions.bad_id = %s", [eyedee]) - associated_client_list = Client.objects.filter(id__in=[x[0] for x in cursor.fetchall()]) + associated_client_list = Client.objects.active(timestamp).filter(id__in=[x[0] for x in cursor.fetchall()]) else: interact_queryset = Interaction.objects.interaction_per_client(timestamp) interactionlist = [] @@ -72,7 +72,7 @@ def config_item_bad(request, eyedee = None, timestamp = 'now'): "WHERE reports_bad_interactions.interaction_id IN %s "+ "AND reports_bad_interactions.interaction_id = reports_interaction.id "+ "AND reports_bad_interactions.bad_id = %s", [interactionlist, eyedee]) - associated_client_list = Client.objects.filter(id__in=[x[0] for x in cursor.fetchall()]) + associated_client_list = Client.objects.active(timestamp).filter(id__in=[x[0] for x in cursor.fetchall()]) else: associated_client_list = None @@ -94,8 +94,7 @@ def bad_item_index(request, timestamp = 'now'): if timestamp == 'now': bad_kinds = dict([(x,x.kind) for x in Bad.objects.filter(interactions__in= [c.current_interaction - for c in Client.objects.all()]).distinct()]) - #this will need expiration support + for c in Client.objects.active(timestamp)]).distinct()]) kinds = list(Set(bad_kinds.values())) item_list_dict = dict([(x,[]) for x in kinds]) for obj in bad_kinds: @@ -104,8 +103,7 @@ def bad_item_index(request, timestamp = 'now'): else: #this isn't done yet bad_kinds = dict([(x,x.kind) for x in Bad.objects.filter(interactions__in= [c.current_interaction - for c in Client.objects.all()]).distinct()]) - #this will need expiration support + for c in Client.objects.active(timestamp)]).distinct()]) kinds = list(Set(bad_kinds.values())) item_list_dict = dict([(x,[]) for x in kinds]) for obj in bad_kinds: @@ -128,7 +126,7 @@ def modified_item_index(request, timestamp = 'now'): if timestamp == 'now': mod_kinds = dict([(x,x.kind) for x in Modified.objects.filter(interactions__in= [c.current_interaction - for c in Client.objects.all()]).distinct()]) + for c in Client.objects.active(timestamp)]).distinct()]) #this will need expiration support kinds = list(Set(mod_kinds.values())) item_list_dict = dict([(x,[]) for x in kinds]) @@ -138,7 +136,7 @@ def modified_item_index(request, timestamp = 'now'): else: #this isn't done yet mod_kinds = dict([(x,x.kind) for x in Modified.objects.filter(interactions__in= [c.current_interaction - for c in Client.objects.all()]).distinct()]) + for c in Client.objects.active(timestamp)]).distinct()]) #this will need expiration support kinds = list(Set(mod_kinds.values())) item_list_dict = dict([(x,[]) for x in kinds]) @@ -156,12 +154,18 @@ def modified_item_index(request, timestamp = 'now'): 'timestamp_time' : timestamp[11:19]}) -def client_index(request): - client_list = Client.objects.all().order_by('name') +def client_index(request, timestamp = 'now'): + timestamp = timestamp.replace("@"," ") + client_list = Client.objects.active(timestamp).order_by('name') client_list_a = client_list[:len(client_list)/2] client_list_b = client_list[len(client_list)/2:] + if timestamp == 'now': + timestamp = datetime.now().isoformat('@') return render_to_response('clients/index.html', {'client_list_a': client_list_a, - 'client_list_b': client_list_b}) + 'client_list_b': client_list_b, + 'timestamp' : timestamp, + 'timestamp_date' : timestamp[:10], + 'timestamp_time' : timestamp[11:19]}) def client_detail(request, hostname = None, pk = None): #SETUP error pages for when you specify a client or interaction that doesn't exist @@ -212,7 +216,7 @@ def display_timing(request, timestamp = 'now'): #+------+-------+----------------+-----------+---------+----------------+-------+ #| name | parse | probe download | inventory | install | cfg dl & parse | total | #+------+-------+----------------+-----------+---------+----------------+-------+ - client_list = Client.objects.all().order_by('name') + client_list = Client.objects.active(timestamp.replace("@"," ")).order_by('name') stats_list = [] if not timestamp == 'now': |