Skip to content

Commit

Permalink
Remove indexes on long fields
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed Nov 3, 2015
1 parent cbd534f commit cc4bb20
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 9 deletions.
59 changes: 59 additions & 0 deletions server/migrations/0017_auto_20151103_1800.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('server', '0016_auto_20151026_0851'),
]

operations = [
migrations.AlterField(
model_name='condition',
name='condition_data',
field=models.TextField(),
),
migrations.AlterField(
model_name='condition',
name='condition_name',
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name='fact',
name='fact_data',
field=models.TextField(),
),
migrations.AlterField(
model_name='fact',
name='fact_name',
field=models.CharField(max_length=255, db_index=True),
),
migrations.AlterField(
model_name='historicalfact',
name='fact_data',
field=models.TextField(),
),
migrations.AlterField(
model_name='historicalfact',
name='fact_name',
field=models.CharField(max_length=255, db_index=True),
),
migrations.AlterField(
model_name='machine',
name='sal_version',
field=models.CharField(db_index=True, max_length=255, null=True, blank=True),
),
migrations.AlterField(
model_name='osquerycolumn',
name='column_data',
field=models.TextField(null=True, blank=True),
),
migrations.AlterField(
model_name='osquerycolumn',
name='column_name',
field=models.CharField(max_length=255, db_index=True),
),
]
18 changes: 9 additions & 9 deletions server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Machine(models.Model):
warnings = models.IntegerField(default=0)
activity = models.TextField(editable=False, null=True, blank=True)
puppet_version = models.TextField(null=True, blank=True)
sal_version = models.TextField(db_index=True, null=True, blank=True)
sal_version = models.CharField(db_index=True, null=True, blank=True, max_length=255)
last_puppet_run = models.DateTimeField(db_index=True, blank=True,null=True)
puppet_errors = models.IntegerField(db_index=True, default=0)

Expand Down Expand Up @@ -196,17 +196,17 @@ def save(self, *args, **kwargs):

class Fact(models.Model):
machine = models.ForeignKey(Machine, related_name='facts')
fact_name = models.TextField(db_index=True)
fact_data = models.TextField(db_index=True)
fact_name = models.CharField(db_index=True, max_length=255)
fact_data = models.TextField()
def __unicode__(self):
return '%s: %s' % (self.fact_name, self.fact_data)
class Meta:
ordering = ['fact_name']

class HistoricalFact(models.Model):
machine = models.ForeignKey(Machine, related_name='historical_facts')
fact_name = models.TextField(db_index=True)
fact_data = models.TextField(db_index=True)
fact_name = models.CharField(db_index=True, max_length=255)
fact_data = models.TextField()
fact_recorded = models.DateTimeField(db_index=True)
def __unicode__(self):
return self.fact_name
Expand All @@ -215,8 +215,8 @@ class Meta:

class Condition(models.Model):
machine = models.ForeignKey(Machine, related_name='conditions')
condition_name = models.TextField(db_index=True)
condition_data = models.TextField(db_index=True)
condition_name = models.CharField(max_length=255)
condition_data = models.TextField()
def __unicode__(self):
return self.condition_name
class Meta:
Expand All @@ -234,8 +234,8 @@ class Meta:

class OSQueryColumn(models.Model):
osquery_result = models.ForeignKey(OSQueryResult, related_name='osquery_columns')
column_name = models.TextField(db_index=True)
column_data = models.TextField(db_index=True, null=True, blank=True)
column_name = models.CharField(db_index=True, max_length=255)
column_data = models.TextField(null=True, blank=True)
action = models.CharField(max_length=255, null=True, blank=True)
def __unicode__(self):
return self.column_name
Expand Down
49 changes: 49 additions & 0 deletions server/plugins/machinemodels/machinemodels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from yapsy.IPlugin import IPlugin
from yapsy.PluginManager import PluginManager
from django.template import loader, Context
from django.db.models import Count
from server.models import *
from django.shortcuts import get_object_or_404
import server.utils as utils

class MunkiVersion(IPlugin):
def plugin_type(self):
return 'builtin'

def widget_width(self):
return 4

def widget_content(self, page, machines=None, theid=None):
# The data is data is pulled from the database and passed to a template.

# There are three possible views we're going to be rendering to - front, bu_dashbaord and group_dashboard. If page is set to bu_dashboard, or group_dashboard, you will be passed a business_unit or machine_group id to use (mainly for linking to the right search).
if page == 'front':
t = loader.get_template('munkiversion/templates/front.html')

if page == 'bu_dashboard':
t = loader.get_template('munkiversion/templates/id.html')

if page == 'group_dashboard':
t = loader.get_template('munkiversion/templates/id.html')

try:
munki_info = machines.values('munki_version').annotate(count=Count('munki_version')).order_by('munki_version')
except:
munki_info = []

c = Context({
'title': 'Munki Version',
'data': munki_info,
'theid': theid,
'page': page
})
return t.render(c)

def filter_machines(self, machines, data):
# You will be passed a QuerySet of machines, you then need to perform some filtering based on the 'data' part of the url from the show_widget output. Just return your filtered list of machines and the page title.

machines = machines.filter(munki_version__exact=data)

title = 'Machines running version '+data+' of MSC'
return machines, title

9 changes: 9 additions & 0 deletions server/plugins/machinemodels/machinemodels.yapsy-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Core]
Name = MunkiVersion
Module = munkiversion

[Documentation]
Author = Graham Gilbert
Version = 0.1
Website = http://grahamgilbert.com
Description = A pie chart of Munki versions
37 changes: 37 additions & 0 deletions server/plugins/machinemodels/templates/front.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="panel panel-default">
<div class="panel-heading">
{{ title }}
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div id="munkiversiongraph" style="max-height: 250px;"></div>
</div>
</div>
{% block script %}
<!-- Morris Charts JavaScript -->
<script src="/static/js/plugins/morris/raphael.min.js"></script>
<script src="/static/js/plugins/morris/morris.min.js"></script>
<script type="text/javascript">
$(function() {
Morris.Donut({
element: 'munkiversiongraph',
data: [
{% for item in data %}
{% if item.munki_version %}
{
label: "{{ item.munki_version }}",
value: {{ item.count }}
},

{% endif %}
{% endfor %}
],
resize: true
}).on('click', function(i, row){
console.log(row['label']);
var url_mask = "{% url 'machine_list_front' 'MunkiVersion' 'abc123' %}".replace(/abc123/, row['label'].toString());
window.location=url_mask;
});
});
</script>
{% endblock %}
38 changes: 38 additions & 0 deletions server/plugins/machinemodels/templates/id.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

<div class="panel panel-default">
<div class="panel-heading">
{{ title }}
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div id="munkiversiongraph" style="max-height: 250px;"></div>
</div>
</div>
{% block script %}
<!-- Morris Charts JavaScript -->
<script src="/static/js/plugins/morris/raphael.min.js"></script>
<script src="/static/js/plugins/morris/morris.min.js"></script>
<script type="text/javascript">
$(function() {
Morris.Donut({
element: 'munkiversiongraph',
data: [
{% for item in data %}
{% if item.munki_version %}
{
label: "{{ item.munki_version }}",
value: {{ item.count }}
},

{% endif %}
{% endfor %}
],
resize: true
}).on('click', function(i, row){
console.log(row['label']);
var url_mask = "{% url 'machine_list_id' 'MunkiVersion' 'abc123' page theid %}".replace(/abc123/, row['label'].toString());
window.location=url_mask;
});
});
</script>
{% endblock %}

0 comments on commit cc4bb20

Please sign in to comment.