Skip to content

Commit

Permalink
nextcloud-stats: KeyError: apps (fix #731)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Dec 21, 2023
1 parent 49bf6e8 commit 2a8d22a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions check-plugins/nextcloud-stats/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions check-plugins/nextcloud-stats/nextcloud-stats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2a8d22a

Please sign in to comment.