Skip to content

Commit

Permalink
[req-changes] "Client" > "Clients"
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Jan 6, 2025
1 parent 8683982 commit 6bacb24
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 112 deletions.
34 changes: 17 additions & 17 deletions docs/user/checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,49 @@ parameters used for iperf3 checks (e.g. timing, port, username, password,
<device-checks-and-alert-settings>` to enable alerts for the iperf3
check.

.. _wifi_client_check:
.. _wifi_clients_check:

WiFi Client
-----------
WiFi Clients
------------

This check sends alerts based on the total number of WiFi Clients
connected to a device. It sends two types of alerts:

- **Maximum WiFi Users**: When the total number of WiFi clients connected
to an access point exceeds a predetermined threshold. This functionality
provides valuable insights into the network's performance, signaling
when a specific access point is overwhelmed by an excessive number of
WiFi users.
- **Minimum WiFi Users**: When the total number of WiFi clients connected
to an access point remains at zero for a duration exceeding the
specified tolerance period. It serves as an indicator of whether the
- **Maximum WiFi Clients**: When the total number of WiFi clients
connected to an access point exceeds a predetermined threshold. This
functionality provides valuable insights into the network's performance,
signaling when a specific access point is overwhelmed by an excessive
number of WiFi clients.
- **Minimum WiFi Clients**: When the total number of WiFi clients
connected to an access point remains at zero for a duration exceeding
the specified tolerance period. It serves as an indicator of whether the
access point is malfunctioning or if its placement is hindering user
connectivity.

This check is **disabled by default**. To enable auto creation of this
check, set :ref:`openwisp_monitoring_auto_wifi_client_check` to ``True``
check, set :ref:`openwisp_monitoring_auto_wifi_clients_check` to ``True``
and configure the task scheduling in your Django project:

.. code-block:: python
from datetime import timedelta
OPENWISP_MONITORING_AUTO_WIFI_CLIENT_CHECK = True
OPENWISP_MONITORING_AUTO_WIFI_CLIENTS_CHECK = True
CELERY_BEAT_SCHEDULE.update(
{
"run_wifi_client_checks": {
"task": "openwisp_monitoring.check.tasks.run_wifi_client_checks",
"run_wifi_clients_checks": {
"task": "openwisp_monitoring.check.tasks.run_wifi_clients_checks",
# Run check every 5 minutes
"schedule": timedelta(minutes=5),
"relative": True,
},
}
)
You can also :doc:`add the WiFi Client check
You can also :doc:`add the WiFi Clients check
<device-checks-and-alert-settings>` directly from the device page.

You can use the
:ref:`openwisp_monitoring_wifi_client_check_snooze_schedule` setting to
:ref:`openwisp_monitoring_wifi_clients_check_snooze_schedule` setting to
disable this check on specific dates, such as during scheduled
maintenance, to avoid generating unnecessary alerts.
28 changes: 14 additions & 14 deletions docs/user/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,24 @@ check when running on multiple servers. Make sure it is always greater
than the total iperf3 check time, i.e. greater than the TCP + UDP test
time. By default, it is set to **600 seconds (10 mins)**.

.. _openwisp_monitoring_auto_wifi_client_check:
.. _openwisp_monitoring_auto_wifi_clients_check:

``OPENWISP_MONITORING_AUTO_WIFI_CLIENT_CHECK``
----------------------------------------------
``OPENWISP_MONITORING_AUTO_WIFI_CLIENTS_CHECK``
-----------------------------------------------

============ =========
**type**: ``bool``
**default**: ``False``
============ =========

This setting allows you to choose whether :ref:`WiFi Client
<wifi_client_check>` checks should be created automatically for newly
This setting allows you to choose whether :ref:`WiFi Clients
<wifi_clients_check>` checks should be created automatically for newly
registered devices. It's disabled by default.

.. _openwisp_monitoring_wifi_client_check_snooze_schedule:

``OPENWISP_MONITORING_WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE``
---------------------------------------------------------
``OPENWISP_MONITORING_WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE``
----------------------------------------------------------

============ ========
**type**: ``list``
Expand All @@ -330,26 +330,26 @@ E.g.:

.. code-block:: python
OPENWISP_MONITORING_WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE = [
OPENWISP_MONITORING_WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE = [
# Date ranges can expand over months
("12-24", "01-05"),
# Date ranges can be single day
("01-26", "01-26"),
]
.. _openwisp_monitoring_wifi_client_check_interval:
.. _openwisp_monitoring_wifi_clients_check_interval:

``OPENWISP_MONITORING_WIFI_CLIENT_CHECK_INTERVAL``
--------------------------------------------------
``OPENWISP_MONITORING_WIFI_CLIENTS_CHECK_INTERVAL``
---------------------------------------------------

============ =======
**type**: ``int``
**default**: ``5``
============ =======

This setting allows you to configure the WiFi Client check interval used
by :ref:`WiFi Client checks <wifi_client_check>`. By default it is set to
5 minutes.
This setting allows you to configure the WiFi Clients check interval used
by :ref:`WiFi Clients checks <wifi_clients_check>`. By default it is set
to 5 minutes.

.. _openwisp_monitoring_auto_charts:

Expand Down
6 changes: 3 additions & 3 deletions openwisp_monitoring/check/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def _connect_signals(self):
dispatch_uid='auto_iperf3_check',
)

if app_settings.AUTO_WIFI_CLIENT_CHECK:
from .base.models import auto_wifi_client_check_receiver
if app_settings.AUTO_WIFI_CLIENTS_CHECK:
from .base.models import auto_wifi_clients_check_receiver

post_save.connect(
auto_wifi_client_check_receiver,
auto_wifi_clients_check_receiver,
sender=load_model('config', 'Device'),
dispatch_uid='auto_wifi_clients_check',
)
8 changes: 4 additions & 4 deletions openwisp_monitoring/check/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
auto_create_config_check,
auto_create_iperf3_check,
auto_create_ping,
auto_create_wifi_client_check,
auto_create_wifi_clients_check,
)
from openwisp_utils.base import TimeStampedEditableModel

Expand Down Expand Up @@ -163,8 +163,8 @@ def auto_iperf3_check_receiver(sender, instance, created, **kwargs):
)


def auto_wifi_client_check_receiver(sender, instance, created, **kwargs):
"""Implements OPENWISP_MONITORING_AUTO_WIFI_CLIENT_CHECK.
def auto_wifi_clients_check_receiver(sender, instance, created, **kwargs):
"""Implements OPENWISP_MONITORING_AUTO_WIFI_CLIENTS_CHECK.
The creation step is executed in the background.
"""
Expand All @@ -173,7 +173,7 @@ def auto_wifi_client_check_receiver(sender, instance, created, **kwargs):
if not created:
return
transaction_on_commit(
lambda: auto_create_wifi_client_check.delay(
lambda: auto_create_wifi_clients_check.delay(
model=sender.__name__.lower(),
app_label=sender._meta.app_label,
object_id=str(instance.pk),
Expand Down
2 changes: 1 addition & 1 deletion openwisp_monitoring/check/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .config_applied import ConfigApplied # noqa
from .iperf3 import Iperf3 # noqa
from .ping import Ping # noqa
from .wifi_client import WifiClient # noqa
from .wifi_client import WifiClients # noqa
8 changes: 4 additions & 4 deletions openwisp_monitoring/check/classes/wifi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AlertSettings = load_model('monitoring', 'AlertSettings')


class WifiClient(BaseCheck):
class WifiClients(BaseCheck):
def check(self, store=True):
values = timeseries_db.read(
key='wifi_clients',
Expand All @@ -21,7 +21,7 @@ def check(self, store=True):
(
timezone.localtime()
- timezone.timedelta(
minutes=app_settings.WIFI_CLIENT_CHECK_INTERVAL
minutes=app_settings.WIFI_CLIENTS_CHECK_INTERVAL
)
).timestamp()
),
Expand All @@ -35,9 +35,9 @@ def check(self, store=True):
return result

def store_result(self, result):
max_metric = self._get_metric('max_wifi_clients')
max_metric = self._get_metric('wifi_clients_max')
max_metric.write(result)
min_metric = self._get_metric('min_wifi_clients')
min_metric = self._get_metric('wifi_clients_min')
min_metric.write(result)

def _get_metric(self, configuration):
Expand Down
12 changes: 6 additions & 6 deletions openwisp_monitoring/check/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
('openwisp_monitoring.check.classes.Ping', 'Ping'),
('openwisp_monitoring.check.classes.ConfigApplied', 'Configuration Applied'),
('openwisp_monitoring.check.classes.Iperf3', 'Iperf3'),
('openwisp_monitoring.check.classes.WifiClient', 'Wifi Client'),
('openwisp_monitoring.check.classes.WifiClients', 'WiFi Clients'),
),
)
AUTO_PING = get_settings_value('AUTO_PING', True)
Expand All @@ -20,12 +20,12 @@
getattr(settings, 'OPENWISP_CONTROLLER_MANAGEMENT_IP_ONLY', True),
)
PING_CHECK_CONFIG = get_settings_value('PING_CHECK_CONFIG', {})
AUTO_WIFI_CLIENT_CHECK = get_settings_value('AUTO_WIFI_CLIENT_CHECK', False)
WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE = get_settings_value(
'WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE', []
AUTO_WIFI_CLIENTS_CHECK = get_settings_value('AUTO_WIFI_CLIENTS_CHECK', False)
WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE = get_settings_value(
'WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE', []
)
WIFI_CLIENT_CHECK_INTERVAL = int(
get_settings_value('WIFI_CLIENT_CHECK_INTERVAL', 5)
WIFI_CLIENTS_CHECK_INTERVAL = int(
get_settings_value('WIFI_CLIENTS_CHECK_INTERVAL', 5)
) # in minutes
AUTO_IPERF3 = get_settings_value('AUTO_IPERF3', False)
IPERF3_CHECK_CONFIG = get_settings_value('IPERF3_CHECK_CONFIG', {})
Expand Down
18 changes: 9 additions & 9 deletions openwisp_monitoring/check/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from openwisp_utils.tasks import OpenwispCeleryTask

from .settings import CHECKS_LIST, WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE
from .settings import CHECKS_LIST, WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,12 +54,12 @@ def run_checks(checks=None):


@shared_task(time_limit=2 * 60 * 60)
def run_wifi_client_checks():
if WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE:
def run_wifi_clients_checks():
if WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE:
today = timezone.localdate()
# Format as MM-DD
today_month_day = today.strftime("%m-%d")
for start_date, end_date in WIFI_CLIENT_CHECK_SNOOZE_SCHEDULE:
for start_date, end_date in WIFI_CLIENTS_CHECK_SNOOZE_SCHEDULE:
# Check if the date range wraps around the new year
if start_date <= end_date:
# Normal range within the same year
Expand All @@ -70,7 +70,7 @@ def run_wifi_client_checks():
if today_month_day >= start_date or today_month_day <= end_date:
return

run_checks(checks=['openwisp_monitoring.check.classes.WifiClient'])
run_checks(checks=['openwisp_monitoring.check.classes.WifiClients'])


@shared_task(time_limit=30 * 60)
Expand Down Expand Up @@ -174,16 +174,16 @@ def auto_create_iperf3_check(


@shared_task(base=OpenwispCeleryTask)
def auto_create_wifi_client_check(
def auto_create_wifi_clients_check(
model, app_label, object_id, check_model=None, content_type_model=None
):
"""Implements the auto creation of the wifi_clients check.
Called by the
openwisp_monitoring.check.models.auto_wifi_client_check_receiver.
openwisp_monitoring.check.models.auto_wifi_clients_check_receiver.
"""
Check = check_model or get_check_model()
check_path = 'openwisp_monitoring.check.classes.WifiClient'
check_path = 'openwisp_monitoring.check.classes.WifiClients'
has_check = Check.objects.filter(
object_id=object_id, content_type__model='device', check_type=check_path
).exists()
Expand All @@ -193,7 +193,7 @@ def auto_create_wifi_client_check(
content_type_model = content_type_model or ContentType
ct = content_type_model.objects.get_by_natural_key(app_label=app_label, model=model)
check = Check(
name='Wifi Client',
name='Wifi Clients',
check_type=check_path,
content_type=ct,
object_id=object_id,
Expand Down
6 changes: 3 additions & 3 deletions openwisp_monitoring/check/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models.signals import post_save
from swapper import load_model

from ..base.models import auto_wifi_client_check_receiver
from ..base.models import auto_wifi_clients_check_receiver

Device = load_model('config', 'Device')

Expand All @@ -24,7 +24,7 @@ class AutoWifiClientCheck(object):
def setUpClass(cls):
super().setUpClass()
post_save.connect(
auto_wifi_client_check_receiver,
auto_wifi_clients_check_receiver,
sender=Device,
dispatch_uid='auto_wifi_clients_check',
)
Expand All @@ -33,7 +33,7 @@ def setUpClass(cls):
def tearDownClass(cls):
super().tearDownClass()
post_save.disconnect(
auto_wifi_client_check_receiver,
auto_wifi_clients_check_receiver,
sender=Device,
dispatch_uid='auto_wifi_clients_check',
)
Loading

0 comments on commit 6bacb24

Please sign in to comment.