-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Fix creation of checks for existing devices #348
- Loading branch information
1 parent
4e27edb
commit 148f4cf
Showing
3 changed files
with
65 additions
and
57 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,32 +1,10 @@ | ||
import swapper | ||
from django.db import migrations | ||
|
||
from openwisp_monitoring.check.settings import AUTO_PING | ||
from openwisp_monitoring.check.tasks import auto_create_ping | ||
|
||
|
||
def create_device_ping(apps, schema_editor): | ||
if AUTO_PING: | ||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
Check = apps.get_model('check', 'Check') | ||
Device = apps.get_model('config', 'Device') | ||
for device in Device.objects.all(): | ||
auto_create_ping( | ||
model=Device.__name__.lower(), | ||
app_label=Device._meta.app_label, | ||
object_id=str(device.pk), | ||
check_model=Check, | ||
content_type_model=ContentType, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('check', '0002_check_unique_together'), | ||
swapper.dependency('monitoring', 'Metric'), | ||
('check', '0001_initial_squashed_0002_check_unique_together'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_device_ping, reverse_code=migrations.RunPython.noop) | ||
] | ||
operations = [] |
34 changes: 1 addition & 33 deletions
34
openwisp_monitoring/check/migrations/0005_create_config_applied.py
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 |
---|---|---|
@@ -1,42 +1,10 @@ | ||
from django.db import migrations | ||
|
||
from openwisp_monitoring.check.settings import AUTO_CONFIG_CHECK | ||
from openwisp_monitoring.check.tasks import auto_create_config_check | ||
|
||
|
||
def add_config_applied_checks(apps, schema_editor): | ||
if not AUTO_CONFIG_CHECK: | ||
return | ||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
Check = apps.get_model('check', 'Check') | ||
Device = apps.get_model('config', 'Device') | ||
for device in Device.objects.all(): | ||
auto_create_config_check( | ||
model=Device.__name__.lower(), | ||
app_label=Device._meta.app_label, | ||
object_id=str(device.pk), | ||
check_model=Check, | ||
content_type_model=ContentType, | ||
) | ||
|
||
|
||
def remove_config_applied_checks(apps, schema_editor): | ||
Check = apps.get_model('check', 'Check') | ||
Metric = apps.get_model('monitoring', 'Metric') | ||
Check.objects.filter( | ||
check='openwisp_monitoring.check.classes.ConfigApplied' | ||
).delete() | ||
Metric.objects.filter(configuration='config_applied').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('check', '0004_rename_active_to_is_active'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
add_config_applied_checks, reverse_code=remove_config_applied_checks | ||
) | ||
] | ||
operations = [] |
62 changes: 62 additions & 0 deletions
62
openwisp_monitoring/check/migrations/0007_create_checks.py
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,62 @@ | ||
import swapper | ||
from django.db import migrations | ||
|
||
from openwisp_monitoring.check.settings import AUTO_CONFIG_CHECK, AUTO_PING | ||
from openwisp_monitoring.check.tasks import auto_create_config_check, auto_create_ping | ||
|
||
|
||
def create_ping_checks(apps, schema_editor): | ||
if AUTO_PING: | ||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
Check = apps.get_model('check', 'Check') | ||
Device = apps.get_model('config', 'Device') | ||
for device in Device.objects.all(): | ||
auto_create_ping( | ||
model=Device.__name__.lower(), | ||
app_label=Device._meta.app_label, | ||
object_id=str(device.pk), | ||
check_model=Check, | ||
content_type_model=ContentType, | ||
) | ||
|
||
|
||
def create_config_applied_checks(apps, schema_editor): | ||
if not AUTO_CONFIG_CHECK: | ||
return | ||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
Check = apps.get_model('check', 'Check') | ||
Device = apps.get_model('config', 'Device') | ||
for device in Device.objects.all(): | ||
auto_create_config_check( | ||
model=Device.__name__.lower(), | ||
app_label=Device._meta.app_label, | ||
object_id=str(device.pk), | ||
check_model=Check, | ||
content_type_model=ContentType, | ||
) | ||
|
||
|
||
def remove_config_applied_checks(apps, schema_editor): | ||
Check = apps.get_model('check', 'Check') | ||
Metric = apps.get_model('monitoring', 'Metric') | ||
Check.objects.filter( | ||
check='openwisp_monitoring.check.classes.ConfigApplied' | ||
).delete() | ||
Metric.objects.filter(configuration='config_applied').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('check', '0006_rename_check_check_check_type'), | ||
swapper.dependency('monitoring', 'Metric'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
create_ping_checks, reverse_code=migrations.RunPython.noop | ||
), | ||
migrations.RunPython( | ||
create_config_applied_checks, reverse_code=remove_config_applied_checks | ||
), | ||
] |