Skip to content

Commit

Permalink
#19 checking for OGC Exceptions on/off in WWW:LINK Resource Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
justb4 committed Jan 10, 2017
1 parent 7d78bf0 commit adb6815
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions GeoHealthCheck/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def add():
return redirect(url_for('add', lang=g.current_lang))

[title, success, response_time, message, start_time] = run_test_resource(
resource_type, url)
APP.config, resource_type, url)

if not success:
flash(message, 'danger')
Expand Down Expand Up @@ -502,7 +502,7 @@ def test(resource_identifier):
return redirect(request.referrer)

[title, success, response_time, message, start_time] = run_test_resource(
resource.resource_type, resource.url)
APP.config, resource.resource_type, resource.url)

if message not in ['OK', None, 'None']:
msg = gettext('ERROR')
Expand Down
1 change: 1 addition & 0 deletions GeoHealthCheck/config_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
GHC_SELF_REGISTER = False
GHC_NOTIFICATIONS = False
GHC_NOTIFICATIONS_VERBOSITY = True
GHC_WWW_LINK_EXCEPTION_CHECK = False
GHC_ADMIN_EMAIL = 'you@example.com'
GHC_SITE_TITLE = 'GeoHealthCheck Demonstration'
GHC_SITE_URL = 'http://host'
Expand Down
43 changes: 34 additions & 9 deletions GeoHealthCheck/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
LOGGER = logging.getLogger(__name__)


def run_test_resource(resource_type, url):
def run_test_resource(config, resource_type, url):
"""tests a CSW service and provides run metrics"""

if resource_type not in RESOURCE_TYPES.keys():
Expand All @@ -70,7 +70,7 @@ def run_test_resource(resource_type, url):
elif resource_type == 'OGC:WFS':
ows = WebFeatureService(url)
elif resource_type == 'OGC:WCS':
ows = WebCoverageService(url)
ows = WebCoverageService(url, version='1.0.0')
elif resource_type == 'OGC:WPS':
ows = WebProcessingService(url)
elif resource_type == 'OGC:CSW':
Expand All @@ -80,12 +80,36 @@ def run_test_resource(resource_type, url):
elif resource_type in ['WWW:LINK', 'urn:geoss:waf']:
ows = urlopen(url)
if resource_type == 'WWW:LINK':
import re
try:
title_re = re.compile("<title>(.+?)</title>")
title = title_re.search(ows.read()).group(1)
except:
title = url
content_type = ows.info().getheader('Content-Type')

# Check content if the response is not an image
if 'image/' not in content_type:
content = ows.read()
import re
try:
title_re = re.compile("<title>(.+?)</title>")
title = title_re.search(content).group(1)
except:
title = url

# Optional check for any OGC-Exceptions in Response
if config and config['GHC_WWW_LINK_EXCEPTION_CHECK']:
exception_text = None
try:
except_re = re.compile(
"ServiceException>|ExceptionReport>")
exception_text = except_re.search(content).group(0)
except:
# No Exception in Response text
pass

if exception_text:
# Found OGC-Exception in Response text
raise Exception(
"Exception in response: %s" % exception_text)

del content

elif resource_type == 'urn:geoss:waf':
title = 'WAF %s %s' % (gettext('for'), urlparse(url).hostname)
elif resource_type == 'FTP':
Expand Down Expand Up @@ -116,4 +140,5 @@ def run_test_resource(resource_type, url):
print('Usage: %s <resource_type> <url>' % sys.argv[0])
sys.exit(1)

print(run_test_resource(sys.argv[1], sys.argv[2]))
# TODO: need APP.config here, None for now
print(run_test_resource(None, sys.argv[1], sys.argv[2]))
3 changes: 2 additions & 1 deletion GeoHealthCheck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def db_commit():
last_run_success = last_run.success

# Run test
run_to_add = run_test_resource(res.resource_type, res.url)
run_to_add = run_test_resource(
APP.config, res.resource_type, res.url)

run1 = Run(res, run_to_add[1], run_to_add[2],
run_to_add[3], run_to_add[4])
Expand Down
1 change: 1 addition & 0 deletions docker/GeoHealthCheck/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ENV GHC_RUN_FREQUENCY 'hourly'
ENV GHC_SELF_REGISTER False
ENV GHC_NOTIFICATIONS False
ENV GHC_NOTIFICATIONS_VERBOSITY True
ENV GHC_WWW_LINK_EXCEPTION_CHECK False
ENV GHC_ADMIN_EMAIL 'you@example.com'
ENV GHC_SITE_TITLE 'GeoHealthCheck Demonstration'
ENV GHC_SITE_URL 'http://localhost'
Expand Down
1 change: 1 addition & 0 deletions docker/GeoHealthCheck/config_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
GHC_SELF_REGISTER = os.environ['GHC_SELF_REGISTER']
GHC_NOTIFICATIONS = os.environ['GHC_NOTIFICATIONS']
GHC_NOTIFICATIONS_VERBOSITY = os.environ['GHC_NOTIFICATIONS_VERBOSITY']
GHC_WWW_LINK_EXCEPTION_CHECK = os.environ['GHC_WWW_LINK_EXCEPTION_CHECK']
GHC_ADMIN_EMAIL = os.environ['GHC_ADMIN_EMAIL']
GHC_SITE_TITLE = os.environ['GHC_SITE_TITLE']
GHC_SITE_URL = os.environ['GHC_SITE_URL']
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ You can override these settings in ``instance/config_site.py``:
(i.e. ``hourly``, ``daily``, ``monthly``)
- **GHC_SELF_REGISTER**: allow registrations from users on the website
- **GHC_NOTIFICATIONS**: turn on email notifications
- **GHC_NOTIFICATIONS_VERBOSITY**: receive additional email notifications than just ``Failing`` and ``Fixed`` (default True)
- **GHC_NOTIFICATIONS_VERBOSITY**: receive additional email notifications than just ``Failing`` and ``Fixed`` (default ``True``)
- **GHC_WWW_LINK_EXCEPTION_CHECK**: turn on checking for OGC Exceptions in ``WWW:LINK`` Resource responses (default ``False``)
- **GHC_ADMIN_EMAIL**: email address of administrator / contact
- **GHC_SITE_TITLE**: title used for installation / deployment
- **GHC_SITE_URL**: url of the installation / deployment
Expand Down

0 comments on commit adb6815

Please sign in to comment.