aboutsummaryrefslogtreecommitdiffstats
path: root/nextcloud_shares
diff options
context:
space:
mode:
Diffstat (limited to 'nextcloud_shares')
-rwxr-xr-xnextcloud_shares108
1 files changed, 69 insertions, 39 deletions
diff --git a/nextcloud_shares b/nextcloud_shares
index 03462bd..adc4add 100755
--- a/nextcloud_shares
+++ b/nextcloud_shares
@@ -19,35 +19,51 @@ import os
class NextcloudShares:
- if (sys.argv.__len__() == 2) and (sys.argv[1] == "config"):
- print('graph_title Nextcloud Shares')
- print('graph_args --base 1024 -l 0')
- print('graph_vlabel number of shares')
- print('graph_info graph showing the number of shares')
- print('graph_category nextcloud')
-
- print('num_fed_shares_received.label federated shares recieved')
- print('num_fed_shares_received.info current total of federated shares recieved')
- print('num_fed_shares_sent.label federated shares sent')
- print('num_fed_shares_sent.info current total of federated shares sent')
- print('num_shares.label total number of shares')
- print('num_shares.info current over all total of shares')
- print('num_shares_groups.label group shares')
- print('num_shares_groups.info current total of group shares')
- print('num_shares_link.label link shares')
- print('num_shares_link.info current total of shares through a link')
- print('num_shares_link_no_password.label link shares without a password')
- print('num_shares_link_no_password.info current total of shares through a link without a password protection')
- print('num_shares_user.label user shares')
- print('num_shares_user.info current total of user shares')
- elif (sys.argv.__len__() == 2) and (sys.argv[1] == 'autoconf'):
- # check host if env variables are set
- try:
- if None not in {os.environ['url'], os.environ['username'], os.environ['password']}:
- print('yes')
- except KeyError:
- print('no env configuration options are missing')
- else:
+ def config(self):
+ config = {
+ 'shares': [
+ 'graph_title Nextcloud Shares',
+ 'graph_args --base 1024 -l 0',
+ 'graph_vlabel number of shares',
+ 'graph_info graph showing the number of shares',
+ 'graph_category nextcloud',
+ 'num_fed_shares_received.label federated shares recieved',
+ 'num_fed_shares_received.info current total of federated shares recieved',
+ 'num_fed_shares_sent.label federated shares sent',
+ 'num_fed_shares_sent.info current total of federated shares sent',
+ 'num_shares.label total number of shares',
+ 'num_shares.info current over all total of shares',
+ 'num_shares_groups.label group shares',
+ 'num_shares_groups.info current total of group shares',
+ 'num_shares_link.label link shares',
+ 'num_shares_link.info current total of shares through a link',
+ 'num_shares_link_no_password.label link shares without a password',
+ 'num_shares_link_no_password.info current total of shares through a link without a password protection',
+ 'num_shares_user.label user shares',
+ 'num_shares_user.info current total of user shares'
+ ]
+ }
+
+ return config
+
+ def get_data(self, api_response):
+ data ={
+ 'nextcloud_shares': [],
+ }
+ shares = api_response['ocs']['data']['nextcloud']['shares']
+
+ # use regex to remove permission stats from api response
+ reg = re.compile("num.*")
+ share_keys = shares.keys()
+ sharelist = list(filter(reg.match, share_keys))
+
+ data['nextcloud_shares'].append('multigraph nextcloud_shares')
+ for key in sharelist:
+ data['nextcloud_shares'].append(str(key) + ".value " + str(shares[key]))
+
+ return data
+
+ def run(self):
# read the configuration from munin environment
URL = os.environ['url']
auth = (os.environ['username'], os.environ['password'])
@@ -65,17 +81,11 @@ class NextcloudShares:
if r.status_code == 200:
s.close()
api_response = r.json()
- shares = api_response['ocs']['data']['nextcloud']['shares']
- # use regex to remove permission stats from api response
- reg = re.compile("num.*")
- share_keys = shares.keys()
- sharelist = list(filter(reg.match, share_keys))
+ result = self.get_data(api_response)
- result = list()
- for key in sharelist:
- result.append(str(key) + ".value " + str(shares[key]))
- print("\n".join(result))
+ for key in result.keys():
+ print('\n'.join(result[key]))
elif r.status_code == 996:
print('server error')
@@ -86,7 +96,27 @@ class NextcloudShares:
else:
print('unknown error')
+ def main(self):
+ if (sys.argv.__len__() == 2) and (sys.argv[1] == "config"):
+ for key in self.config().keys():
+ print('\n'.join(self.config()[key]))
+ try:
+ if os.environ['MUNIN_CAP_DIRTYCONFIG'] == '1':
+ self.run()
+ except KeyError:
+ pass
+
+ elif (sys.argv.__len__() == 2) and (sys.argv[1] == 'autoconf'):
+ # check host if env variables are set
+ try:
+ if None not in {os.environ['url'], os.environ['username'], os.environ['password']}:
+ print('yes')
+ except KeyError:
+ print('no env configuration options are missing')
+ else:
+ self.run()
+
if __name__ == "__main__":
- NextcloudShares()
+ NextcloudShares().main()
quit(0)