Skip to content

Commit 8d7d964

Browse files
authored
Handle missing optional values in ping and simple browser (#58)
1 parent db3d236 commit 8d7d964

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/monitortypes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def is_step_monitor(monitor):
5151
def prep_ping(monitor):
5252
# Using list comprehension get the tag values with corresponding keys e.g. 'apdexTarget'
5353
apdex_target = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'apdexTarget'][0][0]
54-
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader'][0][0]
54+
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader']
5555
if custom_headers:
56+
custom_headers = custom_headers[0][0]
5657
custom_headers = { 'name': custom_headers.split(':')[0], 'value': custom_headers.split(':')[1] }
5758
private_locations = next((tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'privateLocation'), [])
5859
if private_locations:
@@ -66,7 +67,8 @@ def prep_ping(monitor):
6667
# map the period values using the period map
6768
period = SYNTHETIC_PERIOD_MAP[period]
6869
redirect_is_failure = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'redirectIsFailure'][0][0]
69-
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText'][0][0]
70+
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText']
71+
response_validation_text = response_validation_text[0][0] if response_validation_text else None
7072
should_bypass_head_request = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'shouldBypassHeadRequest'][0][0]
7173
useTlsValidation = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'useTlsValidation'][0][0]
7274
# Create a dictionary with the monitor data
@@ -95,8 +97,9 @@ def prep_simple_browser(monitor):
9597
# Using list comprehension get the tag values with corresponding keys e.g. 'apdexTarget'
9698
apdex_target = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'apdexTarget'][0][0]
9799
browsers = next((tag['values'][0] for tag in monitor['definition']['tags'] if tag['key'] == 'browsers'), None)
98-
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader'][0][0]
100+
custom_headers = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'customHeader']
99101
if custom_headers:
102+
custom_headers = custom_headers[0][0]
100103
custom_headers = { 'name': custom_headers.split(':')[0], 'value': custom_headers.split(':')[1] }
101104
devices = next((tag['values'][0] for tag in monitor['definition']['tags'] if tag['key'] == 'devices'), None)
102105
enableScreenshotOnFailureAndScript = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'enableScreenshotOnFailureAndScript'][0][0]
@@ -111,7 +114,8 @@ def prep_simple_browser(monitor):
111114
period = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'period'][0][0]
112115
# map the period values using the period map
113116
period = SYNTHETIC_PERIOD_MAP[period]
114-
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText'][0][0]
117+
response_validation_text = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'responseValidationText']
118+
response_validation_text = response_validation_text[0][0] if response_validation_text else None
115119
runtime_type = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'runtimeType'][0][0]
116120
runtime_type_version = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'runtimeTypeVersion'][0][0]
117121
script_language = [tag['values'] for tag in monitor['definition']['tags'] if tag['key'] == 'scriptLanguage'][0][0]

0 commit comments

Comments
 (0)