diff options
Diffstat (limited to 'nextcloud_apps')
-rwxr-xr-x | nextcloud_apps | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/nextcloud_apps b/nextcloud_apps index 574d932..228a197 100755 --- a/nextcloud_apps +++ b/nextcloud_apps @@ -18,23 +18,36 @@ import os class NextcloudApps: - if (sys.argv.__len__() == 2) and (sys.argv[1] == "config"): - print('graph_title Nextcloud pending App updates') - print('graph_args --base 1024 -l 0') - print('graph_vlabel updates available') - print('graph_info graph showing the number of available app updates') - print('graph_category nextcloud') - - print('num_updates_available.label available app updates') - print('num_updates_available.info number of available app updates') - elif (sys.argv.__len__() == 2) and (sys.argv[1] == 'autoconf'): - # check host if env variables are set + def config(self): + config = { + 'apps': [ + 'graph_title Nextcloud available App updates', + 'graph_args --base 1024 -l 0', + 'graph_vlabel updates available', + 'graph_info graph showing the number of available app updates', + 'graph_category nextcloud', + 'num_updates_available.label available app updates', + 'num_updates_available.info number of available app updates' + ] + } + + return config + + def get_data(self, api_response): + data ={ + 'nextcloud_available_updates': [] + } + + # precaution for Nextcloud versions prior to version 14 try: - if None not in {os.environ['url'], os.environ['username'], os.environ['password']}: - print('yes') + num_updates_available = api_response['ocs']['data']['nextcloud']['system']['apps']['num_updates_available'] + data['nextcloud_available_updates'].append('num_updates_available.value %s' % num_updates_available) except KeyError: - print('no env configuration options are missing') - else: + return False + + return data + + def run(self): # read the configuration from munin environment URL = os.environ['url'] auth = (os.environ['username'], os.environ['password']) @@ -52,8 +65,11 @@ class NextcloudApps: if r.status_code == 200: s.close() api_response = r.json() - num_updates_available = api_response['ocs']['data']['nextcloud']['system']['apps']['num_updates_available'] - print('num_updates_available.value %s' % num_updates_available) + + result = self.get_data(api_response) + + for key in result.keys(): + print('\n'.join(result[key])) elif r.status_code == 996: print('server error') @@ -64,7 +80,27 @@ class NextcloudApps: 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__": - NextcloudApps() + NextcloudApps().main() quit(0) |