diff --git a/server/migrations/0017_auto_20151103_1800.py b/server/migrations/0017_auto_20151103_1800.py new file mode 100644 index 00000000..66a235f9 --- /dev/null +++ b/server/migrations/0017_auto_20151103_1800.py @@ -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), + ), + ] diff --git a/server/models.py b/server/models.py index 981ec88f..b39c1eab 100644 --- a/server/models.py +++ b/server/models.py @@ -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) @@ -196,8 +196,8 @@ 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: @@ -205,8 +205,8 @@ class Meta: 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 @@ -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: @@ -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 diff --git a/server/plugins/machinemodels/machinemodels.py b/server/plugins/machinemodels/machinemodels.py new file mode 100644 index 00000000..30651dd1 --- /dev/null +++ b/server/plugins/machinemodels/machinemodels.py @@ -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 + \ No newline at end of file diff --git a/server/plugins/machinemodels/machinemodels.yapsy-plugin b/server/plugins/machinemodels/machinemodels.yapsy-plugin new file mode 100644 index 00000000..60f4068e --- /dev/null +++ b/server/plugins/machinemodels/machinemodels.yapsy-plugin @@ -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 \ No newline at end of file diff --git a/server/plugins/machinemodels/templates/front.html b/server/plugins/machinemodels/templates/front.html new file mode 100644 index 00000000..6dac60d9 --- /dev/null +++ b/server/plugins/machinemodels/templates/front.html @@ -0,0 +1,37 @@ +
+
+ {{ title }} +
+ +
+
+
+
+ {% block script %} + + + + +{% endblock %} \ No newline at end of file diff --git a/server/plugins/machinemodels/templates/id.html b/server/plugins/machinemodels/templates/id.html new file mode 100644 index 00000000..7b18ebc6 --- /dev/null +++ b/server/plugins/machinemodels/templates/id.html @@ -0,0 +1,38 @@ + +
+
+ {{ title }} +
+ +
+
+
+
+{% block script %} + + + + +{% endblock %} \ No newline at end of file