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

#13 Add support for NC-Token #15

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions nextcloud.chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
3 changes: 3 additions & 0 deletions nextcloud.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# 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

local:
url: 'http://localhost'
user: 'mylogin'
pass: 'mypassword'
# token: 'yourtoken'
timeout: 1