diff options
-rwxr-xr-x | check | 8 | ||||
-rw-r--r-- | kerbana/settings.py | 5 | ||||
-rw-r--r-- | rrd/admin.py | 5 | ||||
-rw-r--r-- | rrd/apps.py | 2 | ||||
-rw-r--r-- | rrd/migrations/0001_initial.py | 69 | ||||
-rw-r--r-- | rrd/models.py | 57 |
6 files changed, 142 insertions, 4 deletions
@@ -55,7 +55,13 @@ case $SUBCMD in ;; "run") cd "$root" - ./manage runserver + ./manage.py runserver + cd - + ;; + "devdb") + cd "$root" + ./manage.py migrate + ./manage.py createsuperuser --username admin --email admin@example.org cd - ;; *) diff --git a/kerbana/settings.py b/kerbana/settings.py index 9cccae0..d2ea290 100644 --- a/kerbana/settings.py +++ b/kerbana/settings.py @@ -31,13 +31,13 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'rrd.apps.RRDConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'rrd', ] MIDDLEWARE = [ @@ -135,4 +135,7 @@ MQTT_USER = None MQTT_PASSWORD = None MQTT_TOPIC = "kerbana/#" +RRD_DB_PATH = BASE_DIR / ".." / "data" / "rrd" +RRD_GRAPH_PATH = BASE_DIR / ".." / "data" / "graph" + from .config import * diff --git a/rrd/admin.py b/rrd/admin.py index 8c38f3f..d83650b 100644 --- a/rrd/admin.py +++ b/rrd/admin.py @@ -1,3 +1,8 @@ from django.contrib import admin +from . import models + # Register your models here. +admin.site.register(models.DataSource) +admin.site.register(models.Graph) +admin.site.register(models.Dashboard) diff --git a/rrd/apps.py b/rrd/apps.py index ef97edc..61733ba 100644 --- a/rrd/apps.py +++ b/rrd/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class RrdConfig(AppConfig): +class RRDConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'rrd' diff --git a/rrd/migrations/0001_initial.py b/rrd/migrations/0001_initial.py new file mode 100644 index 0000000..c4bbee8 --- /dev/null +++ b/rrd/migrations/0001_initial.py @@ -0,0 +1,69 @@ +# Generated by Django 3.2.21 on 2023-12-08 13:48 + +from django.conf import settings +from django.db import migrations, models +import pathlib + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='DataSource', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('topic', models.CharField(max_length=512)), + ('path', models.FilePathField(max_length=512, path=pathlib.PurePosixPath('/home/valhalla/projects/software/kerbana/django-kerbana/../data/rrd'), recursive=True)), + ('rrd_config', models.TextField()), + ('active', models.BooleanField(default=True)), + ('groups_read', models.ManyToManyField(related_name='datasource_read', to='auth.Group')), + ('groups_write', models.ManyToManyField(related_name='datasource_write', to='auth.Group')), + ('users_read', models.ManyToManyField(related_name='datasource_read', to=settings.AUTH_USER_MODEL)), + ('users_write', models.ManyToManyField(related_name='datasource_write', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Graph', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=64)), + ('path', models.FilePathField(max_length=512, path=pathlib.PurePosixPath('/home/valhalla/projects/software/kerbana/django-kerbana/../data/graph'), recursive=True)), + ('rrd_config', models.TextField()), + ('data_sources', models.ManyToManyField(to='rrd.DataSource')), + ('groups_read', models.ManyToManyField(related_name='graph_read', to='auth.Group')), + ('groups_write', models.ManyToManyField(related_name='graph_write', to='auth.Group')), + ('users_read', models.ManyToManyField(related_name='graph_read', to=settings.AUTH_USER_MODEL)), + ('users_write', models.ManyToManyField(related_name='graph_write', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Dashboard', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=64)), + ('template', models.TextField()), + ('data_sources', models.ManyToManyField(to='rrd.DataSource')), + ('graphs', models.ManyToManyField(to='rrd.Graph')), + ('groups_read', models.ManyToManyField(related_name='dashboard_read', to='auth.Group')), + ('groups_write', models.ManyToManyField(related_name='dashboard_write', to='auth.Group')), + ('users_read', models.ManyToManyField(related_name='dashboard_read', to=settings.AUTH_USER_MODEL)), + ('users_write', models.ManyToManyField(related_name='dashboard_write', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/rrd/models.py b/rrd/models.py index 71a8362..49efd57 100644 --- a/rrd/models.py +++ b/rrd/models.py @@ -1,3 +1,58 @@ from django.db import models +from django.conf import settings +import django.contrib.auth.models as amodels -# Create your models here. + +class ModelWithPerms(models.Model): + users_read = models.ManyToManyField( + amodels.User, + related_name="%(class)s_read" + ) + users_write = models.ManyToManyField( + amodels.User, + related_name="%(class)s_write" + ) + groups_read = models.ManyToManyField( + amodels.Group, + related_name="%(class)s_read" + ) + groups_write = models.ManyToManyField( + amodels.Group, + related_name="%(class)s_write" + ) + + class Meta: + abstract = True + + +class DataSource(ModelWithPerms): + # an mqtt topic can be as long as 65,535 bytes when UTF-8 encoded, + # which is probably too much for a sensible db + topic = models.CharField(max_length=512) + path = models.FilePathField( + path=settings.RRD_DB_PATH, + recursive=True, + max_length=512, + ) + rrd_config = models.TextField() + active = models.BooleanField( + default=True, + ) + + +class Graph(ModelWithPerms): + title = models.CharField(max_length=64) + data_sources = models.ManyToManyField(DataSource) + path = models.FilePathField( + path=settings.RRD_GRAPH_PATH, + recursive=True, + max_length=512, + ) + rrd_config = models.TextField() + + +class Dashboard(ModelWithPerms): + title = models.CharField(max_length=64) + graphs = models.ManyToManyField(Graph) + data_sources = models.ManyToManyField(DataSource) + template = models.TextField() |