From d637dd1dc11288e6c8d0526a395bc9557bfe376a Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Fri, 14 Jun 2024 14:46:03 +0100 Subject: [PATCH 01/15] feat: add integration with ckanext-status so far this just checks the iiif server status --- ckanext/nhm/lib/utils.py | 27 ++++++++++++++++++ ckanext/nhm/plugin.py | 59 ++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 ckanext/nhm/lib/utils.py diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py new file mode 100644 index 00000000..490a05c4 --- /dev/null +++ b/ckanext/nhm/lib/utils.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# This file is part of ckanext-nhm +# Created by the Natural History Museum in London, UK + +from ckan.plugins import toolkit +import requests + + +def get_iiif_status(): + health = {} + + url = toolkit.config.get('ckanext.iiif.image_server_url') + r = requests.get(url + '/status') + if r.ok: + health['ping'] = True + response_json = r.json() + else: + response_json = {} + + health['status'] = response_json.get('status') + mss = response_json.get('profiles', {}).get('mss', {}) + health['specimens'] = mss.get('mss_status', {}).get('status', ':(') + health['es'] = mss.get('es', {'status': 'red', 'response_time': None}) + + return health diff --git a/ckanext/nhm/plugin.py b/ckanext/nhm/plugin.py index 4466db24..757c780d 100644 --- a/ckanext/nhm/plugin.py +++ b/ckanext/nhm/plugin.py @@ -31,6 +31,14 @@ IVersionedDatastore, IVersionedDatastoreDownloads, ) +from ckanext.nhm.lib.utils import get_iiif_status + +try: + from ckanext.status.interfaces import IStatus + + status_available = True +except ImportError: + status_available = False log = logging.getLogger(__name__) @@ -63,6 +71,8 @@ class NHMPlugin(SingletonPlugin, toolkit.DefaultDatasetForm): implements(interfaces.IClick) implements(interfaces.IConfigurable) implements(IVersionedDatastoreDownloads, inherit=True) + if status_available: + implements(IStatus) ## IConfigurable def configure(self, config): @@ -710,3 +720,52 @@ def download_modify_eml(self, eml_dict, query): ) eml_dict['creator'] = creators return eml_dict + + ## IStatus + def modify_status_reports(self, status_reports): + iiif_health = get_iiif_status() + + # overall image server status + if iiif_health['ping'] and iiif_health['status'] == ':)': + status_text = toolkit._('connected') + status_type = 'good' + elif iiif_health['ping'] and iiif_health['status'] != ':)': + status_text = toolkit._('connected (issues)') + status_type = 'ok' + else: + status_text = toolkit._('disconnected') + status_type = 'bad' + + status_reports.append( + { + 'label': toolkit._('Image server'), + 'value': status_text, + 'group': toolkit._('Images'), + 'help': toolkit._( + 'The IIIF server provides most of the images in datasets (some are externally hosted)' + ), + 'state': status_type, + } + ) + + # specimen images + if iiif_health['ping'] and iiif_health['specimens'] == ':)': + status_text = toolkit._('connected') + status_type = 'good' + else: + status_text = toolkit._('disconnected') + status_type = 'bad' + + status_reports.append( + { + 'label': toolkit._('Specimen images'), + 'value': status_text, + 'group': toolkit._('Images'), + 'help': toolkit._( + 'Specimen images are a specific subset of images used in e.g. our Collection specimens dataset' + ), + 'state': status_type, + } + ) + + return status_reports diff --git a/pyproject.toml b/pyproject.toml index 28c9037c..8bdbf136 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,8 +33,9 @@ dependencies = [ "ckanext-ldap>=3.2.0", "ckanext-query-dois>=4.0.0", "ckanext-statistics>=3.1.0", - "ckanext-versioned-datastore>=5.1.0" + "ckanext-versioned-datastore>=5.1.0", # this also depends on ckanext-dcat==1.3.0 (see readme) + "requests" ] [project.optional-dependencies] From b4c99ab960855838729058a419921ef18d9de1a0 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Fri, 21 Jun 2024 12:19:33 +0100 Subject: [PATCH 02/15] fix: use (un)available instead of (dis)connected --- ckanext/nhm/plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ckanext/nhm/plugin.py b/ckanext/nhm/plugin.py index 757c780d..0ffef219 100644 --- a/ckanext/nhm/plugin.py +++ b/ckanext/nhm/plugin.py @@ -727,13 +727,13 @@ def modify_status_reports(self, status_reports): # overall image server status if iiif_health['ping'] and iiif_health['status'] == ':)': - status_text = toolkit._('connected') + status_text = toolkit._('available') status_type = 'good' elif iiif_health['ping'] and iiif_health['status'] != ':)': - status_text = toolkit._('connected (issues)') + status_text = toolkit._('available (issues)') status_type = 'ok' else: - status_text = toolkit._('disconnected') + status_text = toolkit._('unavailable') status_type = 'bad' status_reports.append( @@ -750,10 +750,10 @@ def modify_status_reports(self, status_reports): # specimen images if iiif_health['ping'] and iiif_health['specimens'] == ':)': - status_text = toolkit._('connected') + status_text = toolkit._('available') status_type = 'good' else: - status_text = toolkit._('disconnected') + status_text = toolkit._('unavailable') status_type = 'bad' status_reports.append( From ea1d8f2e3977bbf4cc66772ac550f32164ced143 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Fri, 21 Jun 2024 12:21:44 +0100 Subject: [PATCH 03/15] fix: change wording of specimen images help text --- ckanext/nhm/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/nhm/plugin.py b/ckanext/nhm/plugin.py index 0ffef219..b1eb9b89 100644 --- a/ckanext/nhm/plugin.py +++ b/ckanext/nhm/plugin.py @@ -762,7 +762,7 @@ def modify_status_reports(self, status_reports): 'value': status_text, 'group': toolkit._('Images'), 'help': toolkit._( - 'Specimen images are a specific subset of images used in e.g. our Collection specimens dataset' + 'Specimen images are a specific subset of images used primarily in the Collection specimens and Index lots datasets' ), 'state': status_type, } From 444adba8b38bcadbb720e934c540e87b165a2ca4 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Fri, 21 Jun 2024 17:16:55 +0100 Subject: [PATCH 04/15] feat: add link to status page in user icons, with indicator --- ckanext/nhm/lib/helpers.py | 24 ++++++++++++++++++++++++ ckanext/nhm/theme/assets/less/nhm.less | 17 +++++++++++++++++ ckanext/nhm/theme/templates/header.html | 16 ++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/ckanext/nhm/lib/helpers.py b/ckanext/nhm/lib/helpers.py index 0188c10f..0bc2baa7 100644 --- a/ckanext/nhm/lib/helpers.py +++ b/ckanext/nhm/lib/helpers.py @@ -1599,3 +1599,27 @@ def get_record_iiif_manifest_url(resource_id: str, record_id: int) -> str: {'builder_id': 'record', 'resource_id': resource_id, 'record_id': record_id}, ) return toolkit.url_for('iiif.resource', identifier=manifest_id, _external=True) + + +def get_status_indicator(): + """ + Check if we need to display a status indicator, and if so what type. + + :return: 'red', 'amber', or None (if no alerts) + """ + # is there a status message? + status_message = toolkit.config.get('ckanext.status.message', None) + if status_message: + return 'red' + + status_reports = toolkit.get_action('status_list')({}, {}) + + # are there any 'bad' items? + red_status = [r for r in status_reports if r['state'] == 'bad'] + if len(red_status) > 0: + return 'red' + + # are there any reports with small issues? + amber_status = [r for r in status_reports if r['state'] == 'ok'] + if len(amber_status) > 0: + return 'amber' diff --git a/ckanext/nhm/theme/assets/less/nhm.less b/ckanext/nhm/theme/assets/less/nhm.less index ef4c14eb..9cc1682a 100644 --- a/ckanext/nhm/theme/assets/less/nhm.less +++ b/ckanext/nhm/theme/assets/less/nhm.less @@ -236,6 +236,23 @@ body { & .notifications { padding-right: 10px; } + + & .status-indicator { + font-size: @font-size-body-s; + position: absolute; + top: 0; + margin-left: 1.3em; + padding: 0 2px; + border-radius: @rounding; + + &.status-indicator-red { + background: @warning2; + } + + &.status-indicator-amber { + background: orange; + } + } } .icon-pad() { diff --git a/ckanext/nhm/theme/templates/header.html b/ckanext/nhm/theme/templates/header.html index 29853d0b..d0ab1079 100755 --- a/ckanext/nhm/theme/templates/header.html +++ b/ckanext/nhm/theme/templates/header.html @@ -71,6 +71,22 @@ {% endif %} + {# Status page #} + {% set status_indicator = h.get_status_indicator() %} +
+ + {{ _('System status') }} + {% if status_indicator %} + + {{ _('Status alert') }} + + + {% endif %} + + +
+ {# Logout #} {% block header_account_log_out_link %} From 244db06193ec96cab10a209185315068d980a298 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Thu, 4 Jul 2024 10:02:35 +0100 Subject: [PATCH 05/15] fix: add status indicator when logged out as well convert the status icon to a macro so it can be duplicated into the logged in and logged out bars --- ckanext/nhm/theme/templates/header.html | 36 +++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ckanext/nhm/theme/templates/header.html b/ckanext/nhm/theme/templates/header.html index d0ab1079..aa5b1cd5 100755 --- a/ckanext/nhm/theme/templates/header.html +++ b/ckanext/nhm/theme/templates/header.html @@ -7,6 +7,24 @@ {# We do not want a search #}{% block header_site_search %}{% endblock %} +{% set status_indicator = h.get_status_indicator() %} +{% macro status_indicator() %} +
+ + {{ _('System status') }} + {% if status_indicator %} + + {{ _('Status alert') }} + + + {% endif %} + + +
+{% endmacro %} + + {% block header_wrapper %}