-
-
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] Add a check which inspects device configuration status peri…
…odically #54 [influxdb] Add support for retention_policy in read
- Loading branch information
Showing
18 changed files
with
432 additions
and
46 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
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 +1,2 @@ | ||
from .config_applied import ConfigApplied # noqa | ||
from .ping import Ping # 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
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,35 @@ | ||
from swapper import load_model | ||
|
||
from ...device.utils import SHORT_RP | ||
from ..settings import CONFIG_CHECK_MAX_TIME | ||
from .base import BaseCheck | ||
|
||
AlertSettings = load_model('monitoring', 'AlertSettings') | ||
|
||
|
||
class ConfigApplied(BaseCheck): | ||
def check(self, store=True): | ||
# If the device is down do not run config applied checks | ||
if self.related_object.monitoring.status == 'critical': | ||
return | ||
if not hasattr(self.related_object, 'config'): | ||
return | ||
result = int(self.related_object.config.status == 'applied') | ||
if store: | ||
self._get_metric().write( | ||
result, retention_policy=SHORT_RP, | ||
) | ||
return result | ||
|
||
def _get_metric(self): | ||
metric, created = self._get_or_create_metric(configuration='config_applied') | ||
if created: | ||
self._create_alert_setting(metric) | ||
return metric | ||
|
||
def _create_alert_setting(self, metric): | ||
alert_s = AlertSettings( | ||
metric=metric, operator='<', value=1, seconds=CONFIG_CHECK_MAX_TIME * 60 | ||
) | ||
alert_s.full_clean() | ||
alert_s.save() |
38 changes: 38 additions & 0 deletions
38
openwisp_monitoring/check/migrations/0005_create_config_applied.py
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,38 @@ | ||
from django.db import migrations | ||
from openwisp_monitoring.check.settings import AUTO_CONFIG_CHECK | ||
from openwisp_monitoring.check.tasks import auto_create_config_check | ||
|
||
|
||
def add_config_applied_checks(apps, schema_editor): | ||
if not AUTO_CONFIG_CHECK: | ||
return | ||
Device = apps.get_model('config', 'Device') | ||
for device in Device.objects.all(): | ||
auto_create_config_check.delay( | ||
model=Device.__name__.lower(), | ||
app_label=Device._meta.app_label, | ||
object_id=str(device.pk), | ||
) | ||
|
||
|
||
def remove_config_applied_checks(apps, schema_editor): | ||
Check = apps.get_model('check', 'Check') | ||
Metric = apps.get_model('monitoring', 'Metric') | ||
Check.objects.filter( | ||
check='openwisp_monitoring.check.classes.ConfigApplied' | ||
).delete() | ||
Metric.objects.filter(configuration='config_applied').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('check', '0004_rename_active_to_is_active'), | ||
('monitoring', '0016_metric_configuration'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
add_config_applied_checks, reverse_code=remove_config_applied_checks | ||
), | ||
] |
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.