Skip to content

Commit

Permalink
[feature] Auto install monitoring scripts #204
Browse files Browse the repository at this point in the history
Closes #204

Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
nepython and nemesifier authored Jan 31, 2021
1 parent 6e225db commit 748d3ca
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,22 @@ Example usage:
cd tests/
./manage.py run_checks
Monitoring scripts
------------------

The monitoring scripts which are automatically installed by a `migration file of device-monitoring app <https://github.com/openwisp/openwisp-monitoring/blob/master/openwisp_monitoring/device/migrations/0002_create_template.py>`_
are required to make the `checks <https://github.com/openwisp/openwisp-monitoring#available-checks>`_ and
`metrics <#openwisp_monitoring_metrics>`_ work.

The ``netjson-monitoring`` script collects the required data from the openwrt device in realtime. This
data is then sent by the ``openwisp-monitoring`` script to the server in the form of JSON data via SSL.
All the dependencies are updated and installed (if needed) by ``update-openwisp-packages`` script.
The OpenWRT dependencies needed for the monitoring scripts to work are ``libubus-lua``, ``lua-cjson`` and
``rpcd-mod-iwinfo``.

**WARNING**: Please create a new template if you wish to implement customizations. If you modify the
default template to create your custom template then your code can get overwritten post an update.

Installing for development
--------------------------

Expand Down
67 changes: 67 additions & 0 deletions openwisp_monitoring/device/migrations/0002_create_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated by Django 3.1.2 on 2020-12-20 06:15

import uuid
from collections import OrderedDict

from django.db import migrations
from django.db.models import Q

from . import (
TEMPLATE_CRONTAB_MONITORING_01,
TEMPLATE_MONITORING_UUID,
TEMPLATE_NETJSON_MONITORING_01,
TEMPLATE_OPENWISP_MONITORING_01,
TEMPLATE_POST_RELOAD_HOOK_01,
TEMPLATE_RC_LOCAL_01,
TEMPLATE_UPDATE_OPENWISP_PACKAGES_01,
)


def migrate_data(apps, schema_editor):
Template = apps.get_model('config', 'Template')
if Template.objects.filter(
Q(config__contains='/usr/sbin/openwisp-monitoring')
& Q(config__contains='/usr/sbin/netjson-monitoring'),
).exists():
return
default_template = Template(
pk=uuid.UUID(TEMPLATE_MONITORING_UUID),
name='Monitoring (default)',
default=True,
organization=None,
backend='netjsonconfig.OpenWrt',
config=OrderedDict(
{
'files': [
TEMPLATE_OPENWISP_MONITORING_01,
TEMPLATE_NETJSON_MONITORING_01,
TEMPLATE_CRONTAB_MONITORING_01,
TEMPLATE_RC_LOCAL_01,
TEMPLATE_UPDATE_OPENWISP_PACKAGES_01,
TEMPLATE_POST_RELOAD_HOOK_01,
],
'openwisp': [
OrderedDict(
{
'config_name': 'monitoring',
'config_value': 'monitoring',
'included_interfaces': 'tun0 tap0 tap1 wlan0 wlan1 br-lan eth1',
}
)
],
}
),
)
default_template.full_clean()
default_template.save()


class Migration(migrations.Migration):

dependencies = [
('device_monitoring', '0001_squashed_0002_devicemonitoring'),
]

operations = [
migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop)
]
Loading

0 comments on commit 748d3ca

Please sign in to comment.