aboutsummaryrefslogtreecommitdiffstats
path: root/nextcloud_files.py
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2019-06-26 14:49:04 +0200
committernico <nico@magicbroccoli.de>2019-06-26 14:49:04 +0200
commitfc6a0f36c4f05ee233d24db0220b587a5b09c54e (patch)
tree78ec3d943d269199518bcaaaff98158dafc52e88 /nextcloud_files.py
parent214d77e643cb6e7852c51ffc32f96daacdbf3ab2 (diff)
code optimizations
* memory optimization * runtime reduction * code cleanup
Diffstat (limited to 'nextcloud_files.py')
-rwxr-xr-xnextcloud_files.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/nextcloud_files.py b/nextcloud_files.py
index ee12d77..f56860a 100755
--- a/nextcloud_files.py
+++ b/nextcloud_files.py
@@ -18,32 +18,24 @@ import os
class NextcloudStorage:
- def config(self):
- config = {
- 'filecount': [
- 'graph_title Nextcloud Files',
- 'graph_args --base 1000 -l 0',
- 'graph_vlabel number of files',
- 'graph_info graph showing the number of files',
- 'graph_category nextcloud',
- 'num_files.label number of files',
- 'num_files.info current number of files in the repository',
- 'num_files.min 0'
- ]
- }
-
- return config
-
- def get_data(self, api_response):
- data = {
- 'nextcloud_filecount': [],
- }
-
- # append the total number of files present
+ def __init__(self):
+ self.config = [
+ # filecount
+ 'graph_title Nextcloud Files',
+ 'graph_args --base 1000 -l 0',
+ 'graph_printf %.0lf',
+ 'graph_vlabel number of files',
+ 'graph_info graph showing the number of files',
+ 'graph_category nextcloud',
+ 'num_files.label number of files',
+ 'num_files.info current number of files in the repository',
+ 'num_files.min 0'
+ ]
+ self.result = list()
+
+ def parse_data(self, api_response):
num_files = api_response['ocs']['data']['nextcloud']['storage']['num_files']
- data['nextcloud_filecount'].append('num_files.value %s' % num_files)
-
- return data
+ self.result.append('num_files.value %s' % num_files)
def run(self):
# init request session with specific header and credentials
@@ -59,10 +51,11 @@ class NextcloudStorage:
# if status code is successful continue
if r.status_code == 200:
- result = self.get_data(r.json())
+ self.parse_data(r.json())
- # for key in results print every entry in dict
- [print('\n'.join(result[key])) for key in result.keys()]
+ # output results to stdout
+ for el in self.result:
+ print(el, file=sys.stdout)
elif r.status_code == 996:
print('server error')
@@ -78,10 +71,14 @@ class NextcloudStorage:
if sys.argv.__len__() >= 2:
# check if first argument is config or autoconf if not fetch data
if sys.argv[1] == "config":
- # for key in config().keys() print every entry in dict
- [print('\n'.join(self.config()[key])) for key in self.config().keys()]
+ # output config list to stdout
+ for el in self.config:
+ print(el, file=sys.stdout)
+
+ # if DIRTYCONFIG true also return the corresponding values
if os.environ.get('MUNIN_CAP_DIRTYCONFIG') == '1':
self.run()
+
elif sys.argv[1] == 'autoconf':
if None in [os.environ.get('username'), os.environ.get('password')]:
print('env variables are missing')