|
9 | 9 | from jsonfield import JSONField |
10 | 10 |
|
11 | 11 | from openwisp_monitoring.check import settings as app_settings |
12 | | -from openwisp_monitoring.check.tasks import ( |
13 | | - auto_create_config_check, |
14 | | - auto_create_iperf3_check, |
15 | | - auto_create_ping, |
16 | | - auto_create_wifi_clients_check, |
17 | | -) |
| 12 | +from openwisp_monitoring.check.tasks import auto_create_check |
18 | 13 | from openwisp_utils.base import TimeStampedEditableModel |
19 | 14 |
|
20 | 15 | from ...utils import transaction_on_commit |
@@ -108,74 +103,54 @@ def perform_check_delayed(self, duration=0): |
108 | 103 |
|
109 | 104 | perform_check.apply_async(args=[self.id], countdown=duration) |
110 | 105 |
|
111 | | - |
112 | | -def auto_ping_receiver(sender, instance, created, **kwargs): |
113 | | - """Implements OPENWISP_MONITORING_AUTO_PING. |
114 | | -
|
115 | | - The creation step is executed in the background. |
116 | | - """ |
117 | | - # we need to skip this otherwise this task will be executed |
118 | | - # every time the configuration is requested via checksum |
119 | | - if not created: |
120 | | - return |
121 | | - transaction_on_commit( |
122 | | - lambda: auto_create_ping.delay( |
123 | | - model=sender.__name__.lower(), |
124 | | - app_label=sender._meta.app_label, |
125 | | - object_id=str(instance.pk), |
| 106 | + @classmethod |
| 107 | + def auto_create_check_receiver(cls, created, **kwargs): |
| 108 | + if not created: |
| 109 | + return |
| 110 | + transaction_on_commit(lambda: _auto_check_receiver(created=created, **kwargs)) |
| 111 | + |
| 112 | + |
| 113 | +def _auto_check_receiver(sender, instance, **kwargs): |
| 114 | + model = sender.__name__.lower() |
| 115 | + app_label = sender._meta.app_label |
| 116 | + 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', |
126 | 124 | ) |
127 | | - ) |
128 | | - |
129 | | - |
130 | | -def auto_config_check_receiver(sender, instance, created, **kwargs): |
131 | | - """Implements OPENWISP_MONITORING_AUTO_DEVICE_CONFIG_CHECK. |
132 | | -
|
133 | | - The creation step is executed in the background. |
134 | | - """ |
135 | | - # we need to skip this otherwise this task will be executed |
136 | | - # every time the configuration is requested via checksum |
137 | | - if not created: |
138 | | - return |
139 | | - transaction_on_commit( |
140 | | - lambda: auto_create_config_check.delay( |
141 | | - model=sender.__name__.lower(), |
142 | | - app_label=sender._meta.app_label, |
143 | | - object_id=str(instance.pk), |
| 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', |
144 | 132 | ) |
145 | | - ) |
146 | | - |
147 | | - |
148 | | -def auto_iperf3_check_receiver(sender, instance, created, **kwargs): |
149 | | - """Implements OPENWISP_MONITORING_AUTO_IPERF3. |
150 | | -
|
151 | | - The creation step is executed in the background. |
152 | | - """ |
153 | | - # we need to skip this otherwise this task will be executed |
154 | | - # every time the configuration is requested via checksum |
155 | | - if not created: |
156 | | - return |
157 | | - transaction_on_commit( |
158 | | - lambda: auto_create_iperf3_check.delay( |
159 | | - model=sender.__name__.lower(), |
160 | | - app_label=sender._meta.app_label, |
161 | | - object_id=str(instance.pk), |
| 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', |
162 | 140 | ) |
163 | | - ) |
164 | | - |
165 | | - |
166 | | -def auto_wifi_clients_check_receiver(sender, instance, created, **kwargs): |
167 | | - """Implements OPENWISP_MONITORING_AUTO_WIFI_CLIENTS_CHECK. |
168 | | -
|
169 | | - The creation step is executed in the background. |
170 | | - """ |
171 | | - # we need to skip this otherwise this task will be executed |
172 | | - # every time the configuration is requested via checksum |
173 | | - if not created: |
174 | | - return |
175 | | - transaction_on_commit( |
176 | | - lambda: auto_create_wifi_clients_check.delay( |
177 | | - model=sender.__name__.lower(), |
178 | | - app_label=sender._meta.app_label, |
179 | | - object_id=str(instance.pk), |
| 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: |
| 150 | + auto_create_check.delay( |
| 151 | + model=model, |
| 152 | + app_label=app_label, |
| 153 | + object_id=object_id, |
| 154 | + check_type='openwisp_monitoring.check.classes.DataCollected', |
| 155 | + check_name='Monitoring Data Collected', |
180 | 156 | ) |
181 | | - ) |
0 commit comments