-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Added check for WiFi Clients
- Loading branch information
Showing
12 changed files
with
416 additions
and
16 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
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
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,3 +1,4 @@ | ||
from .config_applied import ConfigApplied # noqa | ||
from .iperf3 import Iperf3 # noqa | ||
from .ping import Ping # noqa | ||
from .wifi_client import WifiClient # noqa |
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,52 @@ | ||
from django.utils import timezone | ||
from swapper import load_model | ||
|
||
from ...db import timeseries_db | ||
from .. import settings as app_settings | ||
from .base import BaseCheck | ||
|
||
AlertSettings = load_model('monitoring', 'AlertSettings') | ||
|
||
|
||
class WifiClient(BaseCheck): | ||
def check(self, store=True): | ||
values = timeseries_db.read( | ||
key='wifi_clients', | ||
fields='COUNT(DISTINCT(clients))', | ||
tags={ | ||
'content_type': self.related_object._meta.label_lower, | ||
'object_id': str(self.related_object.pk), | ||
}, | ||
since=int( | ||
( | ||
timezone.localtime() | ||
- timezone.timedelta( | ||
minutes=app_settings.WIFI_CLIENT_CHECK_INTERVAL | ||
) | ||
).timestamp() | ||
), | ||
) | ||
if not values: | ||
result = 0 | ||
else: | ||
result = values[0]['count'] | ||
if store: | ||
self.store_result(result) | ||
return result | ||
|
||
def store_result(self, result): | ||
max_metric = self._get_metric('max_wifi_clients') | ||
max_metric.write(result) | ||
min_metric = self._get_metric('min_wifi_clients') | ||
min_metric.write(result) | ||
|
||
def _get_metric(self, configuration): | ||
metric, created = self._get_or_create_metric(configuration=configuration) | ||
if created: | ||
self._create_alert_setting(metric) | ||
return metric | ||
|
||
def _create_alert_setting(self, metric): | ||
alert_s = AlertSettings(metric=metric) | ||
alert_s.full_clean() | ||
alert_s.save() |
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
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
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
Oops, something went wrong.