-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci][feature] Added optional clean insights measurement collection
- Loading branch information
Showing
9 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class MeasurementsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'openwisp_utils.measurements' | ||
app_label = 'openwisp_measurements' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.2.7 on 2023-11-29 09:16 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
import model_utils.fields | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="OpenwispVersion", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
( | ||
"created", | ||
model_utils.fields.AutoCreatedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="created", | ||
), | ||
), | ||
( | ||
"modified", | ||
model_utils.fields.AutoLastModifiedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="modified", | ||
), | ||
), | ||
("module_version", models.JSONField(blank=True, default=dict)), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.db import models | ||
from openwisp_utils.base import TimeStampedEditableModel | ||
from packaging.version import parse as parse_version | ||
|
||
|
||
class OpenwispVersion(TimeStampedEditableModel): | ||
module_version = models.JSONField(default=dict, blank=True) | ||
|
||
@classmethod | ||
def has_openwisp_upgraded(cls, current_versions): | ||
openwisp_version = cls.objects.first() | ||
if not openwisp_version: | ||
cls.objects.create(module_version=current_versions) | ||
return False | ||
old_versions = openwisp_version.module_version | ||
for module, version in current_versions.items(): | ||
if ( | ||
module not in old_versions | ||
or parse_version(old_versions[module]) < version | ||
): | ||
openwisp_version.module_version = current_versions | ||
openwisp_version.save() | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from celery import shared_task | ||
from django.utils.html import escape | ||
from openwisp_utils.admin_theme.system_info import ( | ||
get_enabled_openwisp_modules, | ||
get_os_details, | ||
) | ||
|
||
from .models import OpenwispVersion | ||
|
||
CLEAN_INSIGHTS_URL = 'https://analytics.openwisp.io/ci/cleaninsights.php' | ||
|
||
|
||
@shared_task | ||
def send_clean_insights_measurements(): | ||
current_versions = get_enabled_openwisp_modules() | ||
data = current_versions.copy() | ||
data.update(get_os_details()) | ||
for key in data.keys(): | ||
data[key] = escape(data[key]) | ||
if OpenwispVersion.has_openwisp_upgraded(current_versions): | ||
# TODO: Write logic for sending upgrade event | ||
pass | ||
else: | ||
# TODO: Write logic for sending event with module info | ||
pass |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters