From 06a88f0f963a9d032c660ec864d05f6483960a09 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Sat, 16 Nov 2024 00:38:05 +0530 Subject: [PATCH] [req-changes] Documented "deactivated" status --- docs/user/device-health-status.rst | 5 +++++ docs/user/settings.rst | 2 +- openwisp_monitoring/device/apps.py | 1 + openwisp_monitoring/device/base/models.py | 3 +++ .../device/migrations/0001_squashed_0002_devicemonitoring.py | 4 ++++ openwisp_monitoring/device/settings.py | 2 ++ .../device/static/monitoring/js/device-map.js | 3 ++- .../sample_device_monitoring/migrations/0001_initial.py | 1 + 8 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/user/device-health-status.rst b/docs/user/device-health-status.rst index 7dfd4e4ce..dff9cb710 100644 --- a/docs/user/device-health-status.rst +++ b/docs/user/device-health-status.rst @@ -36,3 +36,8 @@ been crossed). Example: ping is by default a critical metric which is expected to be always 1 (reachable). + +``DEACTIVATED`` +--------------- + +The device is deactivate. All active and passive checks are disabled. diff --git a/docs/user/settings.rst b/docs/user/settings.rst index 9490ff99e..3fdf63805 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -337,7 +337,7 @@ By default, if devices are not reachable by pings they are flagged as ============ ========================================================== **type**: ``dict`` **default**: ``{'unknown': 'unknown', 'ok': 'ok', 'problem': 'problem', - 'critical': 'critical'}`` + 'critical': 'critical', 'deactivated': 'deactivated'}`` ============ ========================================================== This setting allows to change the health status labels, for example, if we diff --git a/openwisp_monitoring/device/apps.py b/openwisp_monitoring/device/apps.py index 84d0ab871..904709abd 100644 --- a/openwisp_monitoring/device/apps.py +++ b/openwisp_monitoring/device/apps.py @@ -363,6 +363,7 @@ def register_dashboard_items(self): 'problem': app_settings.HEALTH_STATUS_LABELS['problem'], 'critical': app_settings.HEALTH_STATUS_LABELS['critical'], 'unknown': app_settings.HEALTH_STATUS_LABELS['unknown'], + 'deactivated': app_settings.HEALTH_STATUS_LABELS['deactivated'], }, }, ) diff --git a/openwisp_monitoring/device/base/models.py b/openwisp_monitoring/device/base/models.py index 51dc8b265..872bc53f9 100644 --- a/openwisp_monitoring/device/base/models.py +++ b/openwisp_monitoring/device/base/models.py @@ -338,6 +338,7 @@ class AbstractDeviceMonitoring(TimeStampedEditableModel): ('ok', _(app_settings.HEALTH_STATUS_LABELS['ok'])), ('problem', _(app_settings.HEALTH_STATUS_LABELS['problem'])), ('critical', _(app_settings.HEALTH_STATUS_LABELS['critical'])), + ('deactivated', _(app_settings.HEALTH_STATUS_LABELS['deactivated'])), ) status = StatusField( _('health status'), @@ -347,11 +348,13 @@ class AbstractDeviceMonitoring(TimeStampedEditableModel): '"{1}" means the device is operating normally; \n' '"{2}" means the device is having issues but it\'s still reachable; \n' '"{3}" means the device is not reachable or in critical conditions;' + '"{4}" means the device is deactivated;' ).format( app_settings.HEALTH_STATUS_LABELS['unknown'], app_settings.HEALTH_STATUS_LABELS['ok'], app_settings.HEALTH_STATUS_LABELS['problem'], app_settings.HEALTH_STATUS_LABELS['critical'], + app_settings.HEALTH_STATUS_LABELS['deactivated'], ), ) diff --git a/openwisp_monitoring/device/migrations/0001_squashed_0002_devicemonitoring.py b/openwisp_monitoring/device/migrations/0001_squashed_0002_devicemonitoring.py index 80279e23d..d9cffe09c 100644 --- a/openwisp_monitoring/device/migrations/0001_squashed_0002_devicemonitoring.py +++ b/openwisp_monitoring/device/migrations/0001_squashed_0002_devicemonitoring.py @@ -88,6 +88,10 @@ class Migration(migrations.Migration): 'critical', _(app_settings.HEALTH_STATUS_LABELS['critical']), ), + ( + 'deactivated', + _(app_settings.HEALTH_STATUS_LABELS['deactivated']), + ), ], default='unknown', db_index=True, diff --git a/openwisp_monitoring/device/settings.py b/openwisp_monitoring/device/settings.py index d239e3eac..238051768 100644 --- a/openwisp_monitoring/device/settings.py +++ b/openwisp_monitoring/device/settings.py @@ -27,6 +27,7 @@ def get_health_status_labels(): 'ok': 'ok', 'problem': 'problem', 'critical': 'critical', + 'deactivated': 'deactivated', }, ) try: @@ -34,6 +35,7 @@ def get_health_status_labels(): assert 'ok' in labels assert 'problem' in labels assert 'critical' in labels + assert 'deactivated' in labels except AssertionError as e: # pragma: no cover raise ImproperlyConfigured( 'OPENWISP_MONITORING_HEALTH_STATUS_LABELS must contain the following ' diff --git a/openwisp_monitoring/device/static/monitoring/js/device-map.js b/openwisp_monitoring/device/static/monitoring/js/device-map.js index 00fc8a15a..986f4ceb2 100644 --- a/openwisp_monitoring/device/static/monitoring/js/device-map.js +++ b/openwisp_monitoring/device/static/monitoring/js/device-map.js @@ -5,12 +5,13 @@ const loadingOverlay = $('#device-map-container .ow-loading-spinner'); const localStorageKey = 'ow-map-shown'; const mapContainer = $('#device-map-container'); - const statuses = ['critical', 'problem', 'ok', 'unknown']; + const statuses = ['critical', 'problem', 'ok', 'unknown', 'deactivated']; const colors = { ok: '#267126', problem: '#ffb442', critical: '#a72d1d', unknown: '#353c44', + deactivated: '#0000', }; const getLocationDeviceUrl = function (pk) { return window._owGeoMapConfig.locationDeviceUrl.replace('000', pk); diff --git a/tests/openwisp2/sample_device_monitoring/migrations/0001_initial.py b/tests/openwisp2/sample_device_monitoring/migrations/0001_initial.py index 2ff29a4f9..173721f23 100644 --- a/tests/openwisp2/sample_device_monitoring/migrations/0001_initial.py +++ b/tests/openwisp2/sample_device_monitoring/migrations/0001_initial.py @@ -63,6 +63,7 @@ class Migration(migrations.Migration): ('ok', 'ok'), ('problem', 'problem'), ('critical', 'critical'), + ('deactivated', 'deactivated'), ], db_index=True, default='unknown',