Skip to content

Commit

Permalink
nextcloud-security-scan: Handle error on https://scan.nextcloud.com/
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Jul 16, 2024
1 parent eef9d44 commit d11a2b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Monitoring Plugins:
Monitoring Plugins:

* about-me: Determines date of birth of cloud VMs more accurately

* nextcloud-security-scan: Handle error on https://scan.nextcloud.com/

### Fixed ("bug")

Expand Down
17 changes: 12 additions & 5 deletions check-plugins/nextcloud-security-scan/nextcloud-security-scan
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2024031401'
__version__ = '2024071601'

DESCRIPTION = 'Checks the security of your private Nextcloud server.'

Expand Down Expand Up @@ -73,7 +73,8 @@ def parse_args():

parser.add_argument(
'--trigger',
help='Trigger re-scan of the Nextcloud server if result on scan.nextcloud.com is older than n days. '
help='Trigger re-scan of the Nextcloud server if result on scan.nextcloud.com is older '
'than n days. '
'Default: %(default)s (days)',
dest='TRIGGER',
type=int,
Expand Down Expand Up @@ -107,6 +108,8 @@ def get_uuid_from_scan_nextcloud_com(nc_url, args):
)
if not success:
return (success, result)
if result == '':
return (False, 'The scan for {} failed. Either no Nextcloud or ownCloud can be found there or you tried to scan too many servers.'.format(nc_url)) # pylint: disable=C0301
try:
return (True, json.loads(result)['uuid'])
except Exception:
Expand All @@ -131,7 +134,7 @@ def trigger_rescan_nextcloud_com(nc_url, args):
if not success:
return (success, result)
if not result:
return (True, 'Result was outdated. Re-scan triggered. Check again in ~5 minutes to get the newest scan result.')
return (True, 'Result was outdated. Re-scan triggered. Check again in ~5 minutes to get the newest scan result.') # pylint: disable=C0301
try:
return (True, json.loads(result))
except Exception:
Expand Down Expand Up @@ -187,9 +190,13 @@ def main():
today = lib.time.now(as_type='datetime')
delta = scan_date - today
if abs(delta.days) > args.TRIGGER:
tmp = lib.base.coe(trigger_rescan_nextcloud_com(args.URL, args))
lib.base.coe(trigger_rescan_nextcloud_com(args.URL, args))

msg += '"{}" rating for {}, checked at {}, on '.format(get_rating_string(result['rating']), result['domain'], result['scannedAt']['date'][:10])
msg += '"{}" rating for {}, checked at {}, on '.format(
get_rating_string(result['rating']),
result['domain'],
result['scannedAt']['date'][:10],
)

# Version
msg += '{} v{} '.format(result['product'], result['version'])
Expand Down

0 comments on commit d11a2b7

Please sign in to comment.