From 2a8d22ab599d1aa44e8cba797a4011a8d2ff034e Mon Sep 17 00:00:00 2001 From: Markus Frei Date: Thu, 21 Dec 2023 10:07:33 +0100 Subject: [PATCH] nextcloud-stats: KeyError: apps (fix #731) --- CHANGELOG.md | 7 +++++++ check-plugins/nextcloud-stats/README.rst | 12 +++++------ check-plugins/nextcloud-stats/nextcloud-stats | 20 +++++++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8d3fdb..b81f6d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,13 @@ Monitoring Plugins: * mysql-memory: Enhance output, set threshold to 95% +### Fixed ("bug") + +Monitoring Plugins: + +* nextcloud-stats: KeyError: apps ([#731](https://github.com/Linuxfabrik/monitoring-plugins/issues/731)) + + ## 2023112901 ### Breaking Changes diff --git a/check-plugins/nextcloud-stats/README.rst b/check-plugins/nextcloud-stats/README.rst index 44a37391..2ed17c7b 100644 --- a/check-plugins/nextcloud-stats/README.rst +++ b/check-plugins/nextcloud-stats/README.rst @@ -64,12 +64,12 @@ Output: .. code-block:: text - 8 users (3/5/7 in the last 5min/1h/24h), 116.4K files, 50 apps, v24.0.8.3 - * Shares: 142 (18 groups, 57 links [56 w/o password], 0 mails, 0 rooms, 14 users, 0 federated sent) - * Federated Shares: 0 received - * Storages: 14 (0 home, 14 other, 0 local) - * PHP: v8.1.13, upload_max_filesize=9.8GiB, max_execution_time=3600s, memory_limit=1.0GiB - * DB: mysql v10.6.11, size=148.7MiB + 77 users (22/30/53 in the last 5min/1h/24h), 4.4M files, 75 apps (0 updates available), v27.1.3.2 + * Shares: 557 (0 groups, 488 links [478 w/o password], 25 mails, 0 rooms, 23 users, 0 federated sent) + * Federated Shares: 1 received + * Storages: 144 (23 home, 120 other, 1 local) + * PHP: v8.2.13, upload_max_filesize=9.8GiB, max_execution_time=3600s, memory_limit=1.0GiB + * DB: mysql v10.6.16, size=2.9GiB * Web: Apache, local memcache: Memcache\Redis, locking memcache: Memcache\Redis diff --git a/check-plugins/nextcloud-stats/nextcloud-stats b/check-plugins/nextcloud-stats/nextcloud-stats index 93c8a667..cd17d3ee 100755 --- a/check-plugins/nextcloud-stats/nextcloud-stats +++ b/check-plugins/nextcloud-stats/nextcloud-stats @@ -23,7 +23,7 @@ import lib.url # pylint: disable=C0413 from lib.globals import STATE_OK, STATE_UNKNOWN # pylint: disable=C0413 __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2023112901' +__version__ = '2023122101' DESCRIPTION = """This plugin lets you track the number of active users over time, the number of shares in various categories and some storage @@ -57,7 +57,8 @@ def parse_args(): parser.add_argument( '--no-proxy', - help='Do not use a proxy. Default: %(default)s', + help='Do not use a proxy. ' + 'Default: %(default)s', dest='NO_PROXY', action='store_true', default=DEFAULT_NO_PROXY, @@ -72,14 +73,16 @@ def parse_args(): parser.add_argument( '--url', - help='Nextcloud API URL. Default: %(default)s', + help='Nextcloud API URL. ' + 'Default: %(default)s', dest='URL', default=DEFAULT_URL, ) parser.add_argument( '--username', - help='Nextcloud API username. Default: %(default)s', + help='Nextcloud API username. ' + 'Default: %(default)s', dest='USERNAME', default=DEFAULT_USERNAME, ) @@ -101,7 +104,7 @@ def main(): lib.base.cu('--url parameter has to start with "http://" or https://".') if not args.URL.endswith('/info'): lib.base.cu('--url parameter has to end in "/info".') - URL = args.URL + '?format=json' + url = args.URL + '?format=json&skipApps=false' # Add the authentication and api request header auth = '{}:{}'.format(args.USERNAME, args.PASSWORD) @@ -113,7 +116,7 @@ def main(): # and get the info from the API jsonst = lib.base.coe( lib.url.fetch( - URL, + url, insecure=args.INSECURE, no_proxy=args.NO_PROXY, header=header, @@ -128,7 +131,6 @@ def main(): lib.base.cu('Sorry, something went wrong - no "ok" state returned.') # extract some application specific data - nc_system_apps_app_updates = result['ocs']['data']['nextcloud']['system']['apps']['app_updates'] # pylint: disable=C0301 nc_system_apps_num_installed = result['ocs']['data']['nextcloud']['system']['apps']['num_installed'] # pylint: disable=C0301 nc_system_apps_num_updates_available = result['ocs']['data']['nextcloud']['system']['apps']['num_updates_available'] # pylint: disable=C0301 nc_system_memcache_local = result['ocs']['data']['nextcloud']['system']['memcache.local'] # pylint: disable=C0301 @@ -173,13 +175,15 @@ def main(): perfdata = '' # build the (long) multiline message - msg += '{} users ({}/{}/{} in the last 5min/1h/24h), {} files, {} apps, v{}\n'.format( + msg += '{} users ({}/{}/{} in the last 5min/1h/24h), {} files, {} apps ({} {} available), v{}\n'.format( # pylint: disable=C0301 nc_storage_num_users, nc_active_users_last5min, nc_active_users_last1h, nc_active_users_last24h, lib.human.number2human(nc_storage_num_files), nc_system_apps_num_installed, + nc_system_apps_num_updates_available, + lib.txt.pluralize('update', nc_system_apps_num_updates_available), nc_system_version, ) msg += '* Shares: {} ({} groups, {} links [{} w/o password], {} mails, {} rooms, {} users, {} federated sent)\n'.format( # pylint: disable=C0301