diff --git a/README.md b/README.md index 5ccb146..107d090 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,15 @@ on your distribution. Read your given release of netdata for more information. Optional: Copy health configuration `health.d/nextcloud.conf` to `/etc/netdata/health.d/` to enable warnings if there are pending app updates. -Log in as aministrator in Nextcloud and create a new app password for netdata. -Note: The [metadata](https://apps.nextcloud.com/apps/metadata) plugin must be installed and activated in Nextcloud. +To set up proper credentials, either: +- Log in as administrator in Nextcloud Web GUI and create a new app password for netdata, OR +- use Nextcloud CLI `occ config:app:set serverinfo token --value yourtoken` to generate dedicated token Edit the config file `/etc/netdata/python.d/nextcloud.conf` to set the Nextcloud API URL, -user name and app password. +`user`+`pass` or the `token`. Note: both `user`+`pass` and token cannot be configured simultaneously. -Please note: beginning with v0.2 the configuration only needs the hostname and not -the full URL to the monitoring API! +Please note: beginning with v0.2 the configuration only needs the base url (i.e. `https://your-hostname`) +and not the full URL to the monitoring API! Restart netdata to activate the plugin after you have made these changes. diff --git a/nextcloud.chart.py b/nextcloud.chart.py index e5650c6..4decb5a 100644 --- a/nextcloud.chart.py +++ b/nextcloud.chart.py @@ -89,6 +89,10 @@ def __init__(self, configuration=None, name=None): self.definitions = CHARTS self.user = self.configuration.get('user') self.password = self.configuration.get('pass') + if self.configuration.get('token'): + if self.user or self.password: + raise BaseException("Cannot use token with user/password") + self.header = {"NC-Token": self.configuration.get('token')} self.url = self.configuration.get( 'url', 'http://localhost')+'/ocs/v2.php/apps/serverinfo/api/v1/info?format=json' diff --git a/nextcloud.conf b/nextcloud.conf index ba317d5..23b139b 100644 --- a/nextcloud.conf +++ b/nextcloud.conf @@ -3,6 +3,8 @@ # url: the base URL where nextcloud is reachable # user: user # pass: app password +# token: alternative to user+pass. Can be generated via `occ config:app:set serverinfo token --value yourtoken` +# If token is configured, the username and password must be omitted # timeout: allowed time to address nextcloud api # more configuration options: https://github.com/netdata/netdata/blob/master/collectors/python.d.plugin/python_modules/bases/FrameworkServices/UrlService.py#L42-L56 @@ -10,4 +12,5 @@ local: url: 'http://localhost' user: 'mylogin' pass: 'mypassword' +# token: 'yourtoken' timeout: 1