diff options
Diffstat (limited to 'src/lib')
-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 | ||||
-rw-r--r-- | src/lib/Server/Reports/urls.py | 1 |
4 files changed, 64 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': diff --git a/src/lib/Server/Reports/urls.py b/src/lib/Server/Reports/urls.py index 9f602cb4d..cefa4d465 100644 --- a/src/lib/Server/Reports/urls.py +++ b/src/lib/Server/Reports/urls.py @@ -5,6 +5,7 @@ urlpatterns = patterns('', # (r'^Bcfg2.Server.Reports/', include('Bcfg2.Server.Reports.apps.foo.urls.foo')), (r'^/*$','Bcfg2.Server.Reports.reports.views.index'), + (r'^clients/(?P<timestamp>(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])@([01][0-9]|2[0-3]):([0-5][0-9]|60):([0-5][0-9]|60))/$','Bcfg2.Server.Reports.reports.views.client_index'), (r'^clients/(?P<hostname>\S+)/(?P<pk>\d+)/$', 'Bcfg2.Server.Reports.reports.views.client_detail'), (r'^clients/(?P<hostname>\S+)/manage/$', 'Bcfg2.Server.Reports.reports.views.client_manage'), (r'^clients/(?P<hostname>\S+)/$', 'Bcfg2.Server.Reports.reports.views.client_detail'), |