From 7d78ac9db8705b04f841166380b17c021f6399b9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 16 Nov 2020 17:07:05 +0100 Subject: [PATCH] bundles/vnstat: add flag to generate statistics images, add to home.router --- bundles/vnstat/files/generate-vnstati | 14 ++++++++++++++ bundles/vnstat/files/index.html | 14 ++++++++++++++ bundles/vnstat/files/vnstat.conf | 17 ++++++++--------- bundles/vnstat/items.py | 9 +++++++++ bundles/vnstat/metadata.py | 20 ++++++++++++++++++++ nodes/home/router.py | 8 ++++++++ 6 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 bundles/vnstat/files/generate-vnstati create mode 100644 bundles/vnstat/files/index.html diff --git a/bundles/vnstat/files/generate-vnstati b/bundles/vnstat/files/generate-vnstati new file mode 100644 index 0000000..797c10c --- /dev/null +++ b/bundles/vnstat/files/generate-vnstati @@ -0,0 +1,14 @@ +#!/bin/bash + +TARGET=$1 + +if [[ -z "$TARGET" ]] +then + echo "Usage: $0 " + exit 1 +fi + +vnstati --output "$TARGET/daily.png" --days +vnstati --output "$TARGET/monthly.png" --months +vnstati --output "$TARGET/yearly.png" --years +vnstati --output "$TARGET/top10.png" --top10 diff --git a/bundles/vnstat/files/index.html b/bundles/vnstat/files/index.html new file mode 100644 index 0000000..2f00f6a --- /dev/null +++ b/bundles/vnstat/files/index.html @@ -0,0 +1,14 @@ + + + + ${node.name} - ${interface} + + +

${node.name} - ${interface}

+

TOP 10 Days

+

Daily Statistics

+

monthly Statistics

+

+

All times in UTC

+ + diff --git a/bundles/vnstat/files/vnstat.conf b/bundles/vnstat/files/vnstat.conf index 26d6896..4f08cc7 100644 --- a/bundles/vnstat/files/vnstat.conf +++ b/bundles/vnstat/files/vnstat.conf @@ -46,16 +46,15 @@ HourlyRate 1 SummaryRate 1 SummaryLayout 1 TransparentBg 0 -CBackground "FFFFFF" -CEdge "AEAEAE" -CHeader "606060" -CHeaderTitle "FFFFFF" -CHeaderDate "FFFFFF" -CText "000000" +CBackground "333333" +CEdge "444444" +CHeader "444444" +CHeaderTitle "EDEDED" +CHeaderDate "EDEDED" +CText "EDEDED" CLine "B0B0B0" CLineL "-" -CRx "92CF00" -CTx "606060" +CRx "009FC5" +CTx "85BD00" CRxD "-" CTxD "-" - diff --git a/bundles/vnstat/items.py b/bundles/vnstat/items.py index bb3662c..7458341 100644 --- a/bundles/vnstat/items.py +++ b/bundles/vnstat/items.py @@ -6,8 +6,17 @@ files = { 'svc_systemd:vnstat:restart', }, }, + '/usr/local/bin/generate-vnstati': { + 'mode': '0755', + }, } +if node.metadata['vnstat'].get('generate-web-dashboard', False): + files['/var/www/vnstat/index.html'] = { + 'content_type': 'mako', + 'context': node.metadata['vnstat'], + } + svc_systemd = { 'vnstat': { 'needs': { diff --git a/bundles/vnstat/metadata.py b/bundles/vnstat/metadata.py index efd0ae0..dad5a9a 100644 --- a/bundles/vnstat/metadata.py +++ b/bundles/vnstat/metadata.py @@ -23,3 +23,23 @@ def get_default_interface(metadata): } return {} + + +@metadata_reactor +def nginx_dashboard(metadata): + if not node.has_bundle('nginx'): + raise DoNotRunAgain + + if not metadata.get('vnstat/generate-web-dashboard', False): + return {} + + return { + 'cron': { + 'vnstat_generate_web_dashboard': '*/10 * * * * root /usr/local/bin/generate-vnstati /var/www/vnstat', + }, + 'nginx': { + 'vhosts': { + 'vnstat': {}, + }, + }, + } diff --git a/nodes/home/router.py b/nodes/home/router.py index 26230f8..60999e8 100644 --- a/nodes/home/router.py +++ b/nodes/home/router.py @@ -5,6 +5,7 @@ nodes['home.router'] = { 'bundles': { 'iptables', 'netdata', + 'nginx', 'pppd', 'radvd', 'dhcpd', @@ -59,6 +60,12 @@ nodes['home.router'] = { 'enp1s0.42', }, }, + 'nginx': { + 'use_ssl_for_all_connections': False, + 'restrict-to-interfaces': { + 'enp1s0.42', + }, + }, 'radvd': { 'integrate-with-pppd': True, 'interfaces': { @@ -107,6 +114,7 @@ nodes['home.router'] = { }, }, 'vnstat': { + 'generate-web-dashboard': True, 'interface': 'enp1s0.100', }, 'vm': {