88from django .utils .translation import gettext_lazy as _
99from jsonfield import JSONField
1010
11- from openwisp_monitoring .check import settings as app_settings
12- from openwisp_monitoring .check .tasks import auto_create_check
1311from openwisp_utils .base import TimeStampedEditableModel
1412
1513from ...utils import transaction_on_commit
14+ from .. import settings as app_settings
15+ from ..tasks import auto_create_check
1616
1717
1818class AbstractCheck (TimeStampedEditableModel ):
@@ -33,7 +33,7 @@ class AbstractCheck(TimeStampedEditableModel):
3333 content_object = GenericForeignKey ('content_type' , 'object_id' )
3434 check_type = models .CharField (
3535 _ ('check type' ),
36- choices = app_settings .CHECK_CLASSES ,
36+ choices = app_settings .CHECK_CHOICES ,
3737 db_index = True ,
3838 max_length = 128 ,
3939 )
@@ -114,43 +114,14 @@ def _auto_check_receiver(sender, instance, **kwargs):
114114 model = sender .__name__ .lower ()
115115 app_label = sender ._meta .app_label
116116 object_id = str (instance .pk )
117- if app_settings .AUTO_PING :
118- auto_create_check .delay (
119- model = model ,
120- app_label = app_label ,
121- object_id = object_id ,
122- check_type = 'openwisp_monitoring.check.classes.Ping' ,
123- check_name = 'Ping' ,
124- )
125- if app_settings .AUTO_CONFIG_CHECK :
126- auto_create_check .delay (
127- model = model ,
128- app_label = app_label ,
129- object_id = object_id ,
130- check_type = 'openwisp_monitoring.check.classes.ConfigApplied' ,
131- check_name = 'Configuration Applied' ,
132- )
133- if app_settings .AUTO_IPERF3 :
134- auto_create_check .delay (
135- model = model ,
136- app_label = app_label ,
137- object_id = object_id ,
138- check_type = 'openwisp_monitoring.check.classes.Iperf3' ,
139- check_name = 'Iperf3' ,
140- )
141- if app_settings .AUTO_WIFI_CLIENTS_CHECK :
142- auto_create_check .delay (
143- model = model ,
144- app_label = app_label ,
145- object_id = object_id ,
146- check_type = 'openwisp_monitoring.check.classes.WifiClients' ,
147- check_name = 'WiFi Clients' ,
148- )
149- if app_settings .AUTO_DATA_COLLECTED_CHECK :
117+
118+ for class_string , name , auto_create_setting in app_settings .CHECK_CLASSES :
119+ if not getattr (app_settings , auto_create_setting ):
120+ continue
150121 auto_create_check .delay (
151122 model = model ,
152123 app_label = app_label ,
153124 object_id = object_id ,
154- check_type = 'openwisp_monitoring.check.classes.DataCollected' ,
155- check_name = 'Monitoring Data Collected' ,
125+ check_type = class_string ,
126+ check_name = name ,
156127 )
0 commit comments