forked from meichthys/nextcloud_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextcloudmonitor.py
40 lines (31 loc) · 1.3 KB
/
nextcloudmonitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Contains the NextcloudMonitor class"""
import requests
class NextcloudMonitor:
"""An object containing a dictionary representation of dat returned by
Nextcloud's monitoring api
Attributes:
nextcloud_url (str): Full https url to a nextcloud instance
user (str): Username of the Nextcloud user with access to the monitor api
app_password (str): App password generated from Nextcloud security settings page
verify_ssl (bool): Allow bypassing ssl verification, but verify by default
"""
def __init__(self, nextcloud_url, user, app_password, verify_ssl=True):
self.data = dict()
self.api_url = (
f"{nextcloud_url}/ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
)
self.user = user
self.password = app_password
self.verify_ssl = verify_ssl
self.update()
def update(self):
try:
response = requests.get(
self.api_url, auth=(self.user, self.password), verify=self.verify_ssl
)
self.data = response.json()["ocs"]["data"]
except Exception as error:
raise NextcloudMonitorError(f"Could not fetch nextcloud api data: {error}")
class NextcloudMonitorError(Exception):
"""Failed to fetch nextcloud monitor data."""
pass