From 950017b54e97851dde0085211f334a9c189cd87b Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Fri, 3 Nov 2023 14:59:11 +0100 Subject: [PATCH 1/3] ns-api: add ns.netdata --- packages/ns-api/Makefile | 2 ++ packages/ns-api/README.md | 34 ++++++++++++++++++++ packages/ns-api/files/ns.netdata | 46 +++++++++++++++++++++++++++ packages/ns-api/files/ns.netdata.json | 13 ++++++++ 4 files changed, 95 insertions(+) create mode 100755 packages/ns-api/files/ns.netdata create mode 100644 packages/ns-api/files/ns.netdata.json diff --git a/packages/ns-api/Makefile b/packages/ns-api/Makefile index da52bf16a..2beff819d 100644 --- a/packages/ns-api/Makefile +++ b/packages/ns-api/Makefile @@ -101,6 +101,8 @@ define Package/ns-api/install $(INSTALL_DATA) ./files/ns.mwan.json $(1)/usr/share/rpcd/acl.d/ $(INSTALL_BIN) ./files/ns.dpi $(1)/usr/libexec/rpcd/ $(INSTALL_DATA) ./files/ns.dpi.json $(1)/usr/share/rpcd/acl.d/ + $(INSTALL_BIN) ./files/ns.netdata $(1)/usr/libexec/rpcd/ + $(INSTALL_DATA) ./files/ns.netdata.json $(1)/usr/share/rpcd/acl.d/ $(INSTALL_BIN) ./files/ns.storage $(1)/usr/libexec/rpcd/ $(INSTALL_DATA) ./files/ns.storage.json $(1)/usr/share/rpcd/acl.d/ $(INSTALL_BIN) ./files/ns.account $(1)/usr/libexec/rpcd/ diff --git a/packages/ns-api/README.md b/packages/ns-api/README.md index ff6efae2f..0047573a6 100644 --- a/packages/ns-api/README.md +++ b/packages/ns-api/README.md @@ -2966,3 +2966,37 @@ Example response: } } ``` + +## ns.netdata + +Configure netdata reporting daemon. + +### get-configuration + +Get current netdata configuration: +``` +api-cli ns.netdata get-configuration +``` + +Response example: +```json +{ + "hosts": [ + "1.2.3.4", + "google.it" + ], + "path": "/netdata" +} +``` + +### set-hosts + +Configure hosts to be monitored by fping: +``` +api-cli ns.netdata set-hosts --data '{"hosts": ["1.1.1.1", "google.com"]}' +``` + +Response example: +```json +{"result": "success"} +``` diff --git a/packages/ns-api/files/ns.netdata b/packages/ns-api/files/ns.netdata new file mode 100755 index 000000000..62794097a --- /dev/null +++ b/packages/ns-api/files/ns.netdata @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +# +# Copyright (C) 2022 Nethesi3 S.r.l. +# SPDX-License-Identifier: GPL-2.0-only +# + +# Read and set fping configuration for netdata + +import sys +import json + +# FIXME: set real path /etc/netdata/fping.conf +conf_file = "/tmp/fping.conf" + +def get_config(): + hosts = [] + try: + with open(conf_file, 'r') as fp: + for line in fp: + hosts.append(line.rstrip()) + except: + pass + return {"hosts": hosts, "path": "/netdata"} + +def set_config(config): + # FIXME: enable fping plugin on netdata + try: + with open(conf_file, 'w') as fp: + for h in config['hosts']: + fp.write(f"{h}\n") + return {"success": True} + except: + return {"success": False} + +cmd = sys.argv[1] + +if cmd == 'list': + print(json.dumps({"get-configuration": {}, "set-hosts": {"hosts": ["1.1.1.1", "google.com"]}})) +else: + action = sys.argv[2] + if action == "get-configuration": + print(json.dumps(get_config())) + elif action == "set-hosts": + args = json.loads(sys.stdin.read()) + print(json.dumps(set_config(args))) diff --git a/packages/ns-api/files/ns.netdata.json b/packages/ns-api/files/ns.netdata.json new file mode 100644 index 000000000..5764ef6d4 --- /dev/null +++ b/packages/ns-api/files/ns.netdata.json @@ -0,0 +1,13 @@ +{ + "netdata-manager": { + "description": "Read and set netdata configuration", + "write": {}, + "read": { + "ubus": { + "ns.netdata": [ + "*" + ] + } + } + } +} From c99023a5ac898a8219bdace76f4b7daf74f6a488 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Fri, 3 Nov 2023 15:01:12 +0100 Subject: [PATCH 2/3] files: add netdata proxy pass Allow accessing netdata from nginx and accessing it using https --- files/etc/nginx/conf.d/netdata.locations | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 files/etc/nginx/conf.d/netdata.locations diff --git a/files/etc/nginx/conf.d/netdata.locations b/files/etc/nginx/conf.d/netdata.locations new file mode 100644 index 000000000..970bbd37b --- /dev/null +++ b/files/etc/nginx/conf.d/netdata.locations @@ -0,0 +1,21 @@ +location = /netdata { + return 301 /netdata/; +} + +location ~ /netdata/(?.*) { + proxy_redirect off; + proxy_set_header Host $host; + + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_http_version 1.1; + proxy_pass_request_headers on; + proxy_set_header Connection "keep-alive"; + proxy_store off; + proxy_pass http://127.0.0.1:19999/$ndpath$is_args$args; + + gzip on; + gzip_proxied any; + gzip_types *; +} From a689987af1635a225d068a4496a1b9a2270c7d2f Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Thu, 9 Nov 2023 14:33:12 +0100 Subject: [PATCH 3/3] config: add fping Required for netdata monitoring --- config/netdata.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/config/netdata.conf b/config/netdata.conf index 4225a0180..e4636c07f 100644 --- a/config/netdata.conf +++ b/config/netdata.conf @@ -1 +1,2 @@ CONFIG_PACKAGE_netdata=y +CONFIG_PACKAGE_fping=y