Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netdata api #213

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/netdata.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CONFIG_PACKAGE_netdata=y
CONFIG_PACKAGE_fping=y
21 changes: 21 additions & 0 deletions files/etc/nginx/conf.d/netdata.locations
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
location = /netdata {
return 301 /netdata/;
}

location ~ /netdata/(?<ndpath>.*) {
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 *;
}
2 changes: 2 additions & 0 deletions packages/ns-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
34 changes: 34 additions & 0 deletions packages/ns-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
```
46 changes: 46 additions & 0 deletions packages/ns-api/files/ns.netdata
Original file line number Diff line number Diff line change
@@ -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)))
13 changes: 13 additions & 0 deletions packages/ns-api/files/ns.netdata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"netdata-manager": {
"description": "Read and set netdata configuration",
"write": {},
"read": {
"ubus": {
"ns.netdata": [
"*"
]
}
}
}
}