Skip to content

Commit

Permalink
Add better timeout handling in webhook saving
Browse files Browse the repository at this point in the history
There's now a 10s timeout on webhook tests. If webhook tests fail, we
show a quick curl line that'll help check whether the webhook is working
correctly.
  • Loading branch information
thinkst-marco committed Aug 25, 2017
1 parent 69d8447 commit 7617cd1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion httpd_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def render_POST(self, request):

if webhook and not is_webhook_valid(webhook):
response['Error'] = 3
raise Exception('Invalid webhook supplied')
raise Exception('Invalid webhook supplied. Confirm you can POST to this URL.')

alert_email_enabled = False if not email else True
alert_webhook_enabled = False if not webhook else True
Expand Down
8 changes: 7 additions & 1 deletion queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,15 @@ def is_webhook_valid(url):
"channel": "HTTP",
"time": datetime.datetime.now().strftime('%Y-%m-%d %T') }
try:
response = requests.post(url, simplejson.dumps(payload), headers={'content-type': 'application/json'})
response = requests.post(url,
simplejson.dumps(payload),
headers={'content-type': 'application/json'},
timeout=10)
response.raise_for_status()
return True
except requests.exceptions.Timeout as e:
log.err('Timed out sending test payload to webhook: {url}'.format(url=url))
return False
except requests.exceptions.RequestException as e:
log.err('Failed sending test payload to webhook: {url} with error {error}'.format(url=url,error=e))
return False
Expand Down
2 changes: 1 addition & 1 deletion templates/generate_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ <h3>Your AWS key token is active!</h3>
$('#memo_errors').show();
$('textarea[name=memo]').addClass('error-outline').removeClass('success-outline');
} else if (data['Error'] == '3'){
$('#endpoints_errors').html('Invalid webhook supplied');
$('#endpoints_errors').html('<p>Invalid webhook supplied, confirm you can POST to this URL with:</p><p><pre>curl -H "Content-Type: application/json" -d \'{"":""}\' URL</pre></p>');
$('#endpoints_errors').show();
$('#endpoints').addClass('error-outline').removeClass('success-outline');
} else {
Expand Down
9 changes: 9 additions & 0 deletions templates/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@
border-radius: 6px;
margin-bottom: 24px;
}
#endpoints_errors {
border: 1px solid red;
margin: 24px 0px;
padding: 0px 5px;
}
#endpoints_errors pre {
color: #eceeef;
background: firebrick;
}
.map{
position: relative;
margin-bottom: 10px;
Expand Down
2 changes: 1 addition & 1 deletion templates/static/styles.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7617cd1

Please sign in to comment.