Skip to content

Commit

Permalink
Handle missing optional values in ping and simple browser (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
crshanks authored Jan 16, 2025
1 parent db3d236 commit 8d7d964
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/monitortypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def is_step_monitor(monitor):
def prep_ping(monitor):
# Using list comprehension get the tag values with corresponding keys e.g. 'apdexTarget'
apdex_target = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'apdexTarget'][0][0]
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader'][0][0]
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader']
if custom_headers:
custom_headers = custom_headers[0][0]
custom_headers = { 'name': custom_headers.split(':')[0], 'value': custom_headers.split(':')[1] }
private_locations = next((tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'privateLocation'), [])
if private_locations:
Expand All @@ -66,7 +67,8 @@ def prep_ping(monitor):
# map the period values using the period map
period = SYNTHETIC_PERIOD_MAP[period]
redirect_is_failure = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'redirectIsFailure'][0][0]
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText'][0][0]
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText']
response_validation_text = response_validation_text[0][0] if response_validation_text else None
should_bypass_head_request = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'shouldBypassHeadRequest'][0][0]
useTlsValidation = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'useTlsValidation'][0][0]
# Create a dictionary with the monitor data
Expand Down Expand Up @@ -95,8 +97,9 @@ def prep_simple_browser(monitor):
# Using list comprehension get the tag values with corresponding keys e.g. 'apdexTarget'
apdex_target = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'apdexTarget'][0][0]
browsers = next((tag['values'][0] for tag in monitor['definition']['tags'] if tag['key'] == 'browsers'), None)
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader'][0][0]
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader']
if custom_headers:
custom_headers = custom_headers[0][0]
custom_headers = { 'name': custom_headers.split(':')[0], 'value': custom_headers.split(':')[1] }
devices = next((tag['values'][0] for tag in monitor['definition']['tags'] if tag['key'] == 'devices'), None)
enableScreenshotOnFailureAndScript = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'enableScreenshotOnFailureAndScript'][0][0]
Expand All @@ -111,7 +114,8 @@ def prep_simple_browser(monitor):
period = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'period'][0][0]
# map the period values using the period map
period = SYNTHETIC_PERIOD_MAP[period]
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText'][0][0]
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText']
response_validation_text = response_validation_text[0][0] if response_validation_text else None
runtime_type = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'runtimeType'][0][0]
runtime_type_version = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'runtimeTypeVersion'][0][0]
script_language = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'scriptLanguage'][0][0]
Expand Down

0 comments on commit 8d7d964

Please sign in to comment.