summaryrefslogtreecommitdiffstats
path: root/reports/brpt
diff options
context:
space:
mode:
authorJoey Hagedorn <hagedorn@mcs.anl.gov>2006-08-02 19:32:13 +0000
committerJoey Hagedorn <hagedorn@mcs.anl.gov>2006-08-02 19:32:13 +0000
commit9f129bdd9f08139a5cb1cd7d1bd3c05ce0cfe9da (patch)
treece40de298abb9dda23bb71955e2710a335576283 /reports/brpt
parent10b489ff62f00356a49dea6978c48354c0cf2ffc (diff)
downloadbcfg2-9f129bdd9f08139a5cb1cd7d1bd3c05ce0cfe9da.tar.gz
bcfg2-9f129bdd9f08139a5cb1cd7d1bd3c05ce0cfe9da.tar.bz2
bcfg2-9f129bdd9f08139a5cb1cd7d1bd3c05ce0cfe9da.zip
New Reports: support for new pinging structure; this one works.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2028 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'reports/brpt')
-rw-r--r--reports/brpt/reports/models.py34
-rw-r--r--reports/brpt/reports/templates/clients/client-nodebox.html6
-rw-r--r--reports/brpt/reports/views.py38
3 files changed, 45 insertions, 33 deletions
diff --git a/reports/brpt/reports/models.py b/reports/brpt/reports/models.py
index 82a4899fc..c1818fd66 100644
--- a/reports/brpt/reports/models.py
+++ b/reports/brpt/reports/models.py
@@ -11,7 +11,11 @@ KIND_CHOICES = (
('Directory', 'Directory'),
('Permissions','Permissions'),
)
-
+PING_CHOICES = (
+ #These are possible ping states
+ ('Up (Y)', 'Y'),
+ ('Down (N)', 'N')
+)
class Client(models.Model):
'''object representing every client we have seen stats for'''
creation = models.DateTimeField()
@@ -19,6 +23,7 @@ class Client(models.Model):
current_interaction = models.ForeignKey('Interaction',
null=True, blank=True,
related_name="parent_client")
+ expiration = models.DateTimeField()
def __str__(self):
return self.name
@@ -27,19 +32,31 @@ class Client(models.Model):
pass
class Metadata(models.Model):
+ '''insert magical interface to client metadata here'''
client = models.ForeignKey(Client)
timestamp = models.DateTimeField()
- #INSERT magic interface to Metadata HERE
def __str__(self):
return self.timestamp
class Repository(models.Model):
+ '''insert magical interface to subversioned repository here'''
timestamp = models.DateTimeField()
- #INSERT magic interface to repo (SVN'd version) here
def __str__(self):
return self.timestamp
+class Ping(models.Model):
+ '''represents a ping of a client (sparsely)'''
+ client = models.ForeignKey(Client, related_name="pings")
+ starttime = models.DateTimeField()
+ endtime = models.DateTimeField()
+ status = models.CharField(maxlength=4, choices=PING_CHOICES)#up/down
+
+ class Meta:
+ get_latest_by = 'endtime'
+
class InteractiveManager(models.Manager):
+ '''manages interactions objects'''
+
'''returns most recent interaction as of specified timestamp in format:
'2006-01-01 00:00:00' or 'now' or None->'now' '''
def interaction_per_client(self, maxdate = None):
@@ -47,16 +64,17 @@ class InteractiveManager(models.Manager):
cursor = connection.cursor()
#in order to prevent traceback when zero records are returned.
- #this could mask unsupported database errors
+ #this could mask some database errors
try:
if (maxdate == 'now' or maxdate == None):
cursor.execute("select reports_interaction.id, x.client_id from (select client_id, MAX(timestamp) "+
- "as timer from reports_interaction GROUP BY client_id) x, reports_interaction where "+
- "reports_interaction.client_id = x.client_id AND reports_interaction.timestamp = x.timer")
+ "as timer from reports_interaction GROUP BY client_id) x, reports_interaction where "+
+ "reports_interaction.client_id = x.client_id AND reports_interaction.timestamp = x.timer")
else:
cursor.execute("select reports_interaction.id, x.client_id from (select client_id, timestamp, MAX(timestamp) "+
- "as timer from reports_interaction WHERE timestamp < %s GROUP BY client_id) x, reports_interaction where "+
- "reports_interaction.client_id = x.client_id AND reports_interaction.timestamp = x.timer", [maxdate])
+ "as timer from reports_interaction WHERE timestamp < %s GROUP BY client_id) x, reports_interaction where "+
+ "reports_interaction.client_id = x.client_id AND reports_interaction.timestamp = x.timer",
+ [maxdate])
in_idents = [item[0] for item in cursor.fetchall()]
except:
in_idents = []
diff --git a/reports/brpt/reports/templates/clients/client-nodebox.html b/reports/brpt/reports/templates/clients/client-nodebox.html
index e92a5a874..dade598cf 100644
--- a/reports/brpt/reports/templates/clients/client-nodebox.html
+++ b/reports/brpt/reports/templates/clients/client-nodebox.html
@@ -31,7 +31,7 @@
<div class="bad">
<span class="nodelisttitle"><a href="javascript:toggleLayer('{{client.name}}-bad');" title="Click to expand" class="commentLink">{{interaction.bad_items.count}}</a> items did not verify and are considered Dirty.<br /></span>
<div class="items" id="{{client.name}}-bad"><ul class="plain">
- {% for bad in interaction.bad_items.all|sortwell %} {% comment %}HOWDOI? order_by('kind', 'name'){% endcomment %}
+ {% for bad in interaction.bad_items.all|sortwell %}
<li><strong>{{bad.kind}}: </strong><tt><a href="/elements/bad/{{bad.id}}">{{bad.name}}</a></tt></li>
{% endfor %}
</ul></div>
@@ -41,7 +41,7 @@
<div class="modified">
<span class="nodelisttitle"><a href="javascript:toggleLayer('{{client.name}}-modified');" title="Click to expand" class="commentLink">{{interaction.modified_items.count}}</a> items were modified in the last run.<br /></span>
<div class="items" id="{{client.name}}-modified"><ul class="plain">
- {% for modified in interaction.modified_items.all|sortwell %} {% comment %}HOWDOI? order_by('kind', 'name'){% endcomment %}
+ {% for modified in interaction.modified_items.all|sortwell %}
<li><strong>{{modified.kind}}: </strong><tt><a href="/elements/modified/{{modified.id}}">{{modified.name}}</a></tt></li>
{% endfor %}
</ul></div>
@@ -51,7 +51,7 @@
<div class="extra">
<span class="nodelisttitle"><a href="javascript:toggleLayer('{{client.name}}-extra');" title="Click to expand" class="commentLink">{{interaction.extra_items.count}}</a> extra configuration elements on the node.<br /></span>
<div class="items" id="{{client.name}}-extra"><ul class="plain">
- {% for extra in interaction.extra_items.all|sortwell %} {% comment %}HOWDOI? order_by('kind', 'name'){% endcomment %}
+ {% for extra in interaction.extra_items.all|sortwell %}
<li><strong>{{extra.kind}}: </strong><tt>{{extra.name}}</tt></li>
{% endfor %}
</ul></div>
diff --git a/reports/brpt/reports/views.py b/reports/brpt/reports/views.py
index be61910f8..1c2d09e70 100644
--- a/reports/brpt/reports/views.py
+++ b/reports/brpt/reports/views.py
@@ -41,9 +41,6 @@ def config_item_modified(request, eyedee =None, timestamp = 'now'):
if timestamp == 'now':
timestamp = datetime.now().isoformat('@')
- for q in connection.queries:
- print q
-
return render_to_response('config_items/index.html', {'item':item,
'mod_or_bad':mod_or_bad,
'associated_client_list':associated_client_list,
@@ -79,10 +76,6 @@ def config_item_bad(request, eyedee = None, timestamp = 'now'):
if timestamp == 'now':
timestamp = datetime.now().isoformat('@')
-
- for q in connection.queries:
- print q
-
return render_to_response('config_items/index.html', {'item':item,
'mod_or_bad':mod_or_bad,
'associated_client_list':associated_client_list,
@@ -106,29 +99,16 @@ def client_detail(request, hostname = None, pk = None):
interaction = client.current_interaction
else:
interaction = client.interactions.get(pk=pk)#can this be a get object or 404?
-
- #for q in connection.queries:
- # print q
-
return render_to_response('clients/detail.html', {'client': client, 'interaction': interaction})
def display_sys_view(request, timestamp = 'now'):
client_lists = prepare_client_lists(request, timestamp)
-
- #for q in connection.queries:
- # print q
-
-
return render_to_response('displays/sys_view.html', client_lists)
def display_summary(request, timestamp = 'now'):
client_lists = prepare_client_lists(request, timestamp)
#this returns timestamp and the timestamp parts too
-
- #for q in connection.queries:
- # print q
-
return render_to_response('displays/summary.html', client_lists)
def display_timing(request, timestamp = 'now'):
@@ -213,7 +193,21 @@ def prepare_client_lists(request, timestamp = 'now'):
[clean_client_list.append(x) for x in Client.objects.filter(id__in=[y.client_id for y in interact_queryset.filter(state='clean')])]
[bad_client_list.append(x) for x in Client.objects.filter(id__in=[y.client_id for y in interact_queryset.filter(state='dirty')])]
- [down_client_list.append(x) for x in Client.objects.filter(id__in=[y.client_id for y in interact_queryset.filter(pingable='N')])]#need to change the PINGING data structure
+
+ client_ping_dict = {}
+ [client_ping_dict.__setitem__(x,'Y') for x in client_interaction_dict.keys()]#unless we know otherwise...
+
+ try:
+ cursor.execute("select reports_ping.status, x.client_id from (select client_id, MAX(endtime) "+
+ "as timer from reports_ping GROUP BY client_id) x, reports_ping where "+
+ "reports_ping.client_id = x.client_id AND reports_ping.endtime = x.timer")
+ [client_ping_dict.__setitem__(x[1],x[0]) for x in cursor.fetchall()]
+ except:
+ pass #This is to fix problems when you have only zero records returned
+
+ client_down_ids = [y for y in client_ping_dict.keys() if client_ping_dict[y]=='N']
+ if not client_down_ids == []:
+ [down_client_list.append(x) for x in Client.objects.filter(id__in=client_down_ids)]
if (timestamp == 'now' or timestamp == None):
cursor.execute("select client_id, MAX(timestamp) as timestamp from reports_interaction GROUP BY client_id")
@@ -225,7 +219,7 @@ def prepare_client_lists(request, timestamp = 'now'):
datetimestamp = datetime(t[0], t[1], t[2], t[3], t[4], t[5])
stale_all_client_list = Client.objects.filter(id__in=[x[0] for x in cursor.fetchall() if datetimestamp - x[1] > timedelta(days=1)])
- [stale_up_client_list.append(x) for x in stale_all_client_list if client_interaction_dict[x.id].pingable=='Y']
+ [stale_up_client_list.append(x) for x in stale_all_client_list if not client_ping_dict[x.id]=='N']
cursor.execute("SELECT reports_client.id FROM reports_client, reports_interaction, reports_modified_interactions WHERE reports_client.id=reports_interaction.client_id AND reports_interaction.id = reports_modified_interactions.interaction_id GROUP BY reports_client.id")