Skip to content

Commit

Permalink
feat: add integration with ckanext-status
Browse files Browse the repository at this point in the history
so far this just checks the iiif server status
  • Loading branch information
alycejenni committed Jun 21, 2024
1 parent a8f9027 commit d637dd1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
27 changes: 27 additions & 0 deletions ckanext/nhm/lib/utils.py
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions ckanext/nhm/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d637dd1

Please sign in to comment.