Tried to find an error in the system which was actually caused by choosing the wrong data format in the github webhook. Nice its not in the system! :)

This commit is contained in:
Dominic Bosch 2014-04-27 19:52:45 +02:00
parent df39fe2043
commit a6690acb84
9 changed files with 67 additions and 53 deletions

View file

@ -355,6 +355,10 @@ exports.handleAdminCommand = ( req, resp ) =>
# Parse events and register to user if it's a user specific event # Parse events and register to user if it's a user specific event
parsePushAndAnswerEvent = ( eventname, username, body, resp ) -> parsePushAndAnswerEvent = ( eventname, username, body, resp ) ->
# Currently we allow JSON and form data to arrive at webhooks.
# TODO We should allow to choose arriving formats, such as xml too
# TODO We should implement body selectors for webhooks as well to
# add flexibility in the way the data arrives
if typeof body is 'string' if typeof body is 'string'
try try
body = JSON.parse body body = JSON.parse body
@ -364,6 +368,7 @@ parsePushAndAnswerEvent = ( eventname, username, body, resp ) ->
catch err catch err
resp.send 400, 'Badly formed event!' resp.send 400, 'Badly formed event!'
return return
obj = obj =
eventname: eventname eventname: eventname
body: body body: body
@ -389,7 +394,7 @@ exports.handleMeasurements = ( req, resp ) =>
if obj.eventname is 'uptimestatistics' if obj.eventname is 'uptimestatistics'
# This is a hack to quickly allow storing of public accessible data # This is a hack to quickly allow storing of public accessible data
fPath = path.resolve __dirname, '..', 'webpages', 'public', 'data', 'histochart.json' fPath = path.resolve __dirname, '..', 'webpages', 'public', 'data', 'histochart.json'
fs.writeFile fPath, JSON.stringify( JSON.parse( body ), undefined, 2 ), 'utf8' fs.writeFile fPath, JSON.stringify( obj, undefined, 2 ), 'utf8'
### ###
Handles webhook posts Handles webhook posts

View file

@ -480,7 +480,7 @@ Request Handler
obj = parsePushAndAnswerEvent(name, null, body, resp); obj = parsePushAndAnswerEvent(name, null, body, resp);
if (obj.eventname === 'uptimestatistics') { if (obj.eventname === 'uptimestatistics') {
fPath = path.resolve(__dirname, '..', 'webpages', 'public', 'data', 'histochart.json'); fPath = path.resolve(__dirname, '..', 'webpages', 'public', 'data', 'histochart.json');
return fs.writeFile(fPath, JSON.stringify(JSON.parse(body), void 0, 2), 'utf8'); return fs.writeFile(fPath, JSON.stringify(obj, void 0, 2), 'utf8');
} }
}); });
}; };

View file

@ -153,7 +153,7 @@ fConvertDayHourToMinutes = ( strDayHour ) ->
# #
# Prepare the event section when a different event type is selected # Prepare the event section when a different event type is selected
fPrepareEventType = ( eventtype ) -> fPrepareEventType = ( eventtype, cb ) ->
$( '#select_event_type' ).val eventtype $( '#select_event_type' ).val eventtype
$( '#event_parameters > div' ).detach() $( '#event_parameters > div' ).detach()
switch eventtype switch eventtype
@ -161,6 +161,7 @@ fPrepareEventType = ( eventtype ) ->
# The user wants to react to custom event # The user wants to react to custom event
when 'Custom Event' when 'Custom Event'
$( '#event_parameters' ).append domInputEventName $( '#event_parameters' ).append domInputEventName
cb?()
# The user wants a webhook as event producer # The user wants a webhook as event producer
when 'Webhook' when 'Webhook'
@ -185,8 +186,12 @@ fPrepareEventType = ( eventtype ) ->
catch err catch err
fDisplayError 'Badly formed webhooks!' fDisplayError 'Badly formed webhooks!'
cb?()
fail: fFailedRequest 'Unable to get webhooks!' fail: () ->
fFailedRequest 'Unable to get webhooks!'
cb?()
when 'Event Poller' when 'Event Poller'
fIssueRequest fIssueRequest
@ -211,8 +216,11 @@ fPrepareEventType = ( eventtype ) ->
catch err catch err
console.error 'ERROR: non-object received for event poller from server: ' + data.message console.error 'ERROR: non-object received for event poller from server: ' + data.message
cb?()
fail: fFailedRequest 'Error fetching Event Poller' fail: () ->
fFailedRequest 'Error fetching Event Poller'
cb?()
# Fetch the required Event Poller parameters # Fetch the required Event Poller parameters
fFetchEventParams = ( name ) -> fFetchEventParams = ( name ) ->
@ -481,20 +489,18 @@ fOnLoad = () ->
# If the user is coming from an event UI he wants a rule to be setup for him # If the user is coming from an event UI he wants a rule to be setup for him
switch oParams.eventtype switch oParams.eventtype
when 'custom' when 'custom'
$( '#input_id' ).val "My '#{ oParams.eventname }' Rule" name = decodeURIComponent oParams.eventname
fPrepareEventType 'Custom Event' $( '#input_id' ).val "My '#{ name }' Rule"
$( '#input_eventname' ).val oParams.eventname fPrepareEventType 'Custom Event', () ->
$( '#input_eventname' ).focus() $( '#input_eventname' ).val name
editor.setValue "[\n\n]" # For now we don't prepare conditions $( '#input_eventname' ).focus()
editor.setValue "[\n\n]" # For now we don't prepare conditions
when 'webhook' when 'webhook'
$( '#input_id' ).val "My '#{ oParams.hookname }' Rule" name = decodeURIComponent oParams.hookname
fPrepareEventType 'Webhook' $( '#input_id' ).val "My '#{ name }' Rule"
domSelectWebhook.val oParams.hookname fPrepareEventType 'Webhook', () ->
$( 'select', domSelectWebhook ).val name
when 'poller'
$( '#input_id' ).val "My '#{ oParams.eventpoller }' Rule"
fPrepareEventType 'Event Poller'
# ACTIONS # ACTIONS

View file

@ -85,6 +85,7 @@ fShowWebhookUsage = ( hookid, hookname ) ->
fOnLoad = () -> fOnLoad = () ->
document.title = 'Create Webhooks!' document.title = 'Create Webhooks!'
$( '#pagetitle' ).text 'Create your own Webhooks!'
# Load existing Webhooks # Load existing Webhooks
fUpdateWebhookList fShowWebhookUsage fUpdateWebhookList fShowWebhookUsage

View file

@ -176,12 +176,13 @@
return Math.max(1, mins); return Math.max(1, mins);
}; };
fPrepareEventType = function(eventtype) { fPrepareEventType = function(eventtype, cb) {
$('#select_event_type').val(eventtype); $('#select_event_type').val(eventtype);
$('#event_parameters > div').detach(); $('#event_parameters > div').detach();
switch (eventtype) { switch (eventtype) {
case 'Custom Event': case 'Custom Event':
return $('#event_parameters').append(domInputEventName); $('#event_parameters').append(domInputEventName);
return typeof cb === "function" ? cb() : void 0;
case 'Webhook': case 'Webhook':
return fIssueRequest({ return fIssueRequest({
data: { data: {
@ -200,17 +201,21 @@
selHook.append($('<option>').text(hookname)); selHook.append($('<option>').text(hookname));
} }
if (i > 0) { if (i > 0) {
return $('#event_parameters').append(domSelectWebhook); $('#event_parameters').append(domSelectWebhook);
} else { } else {
fDisplayError('No webhooks found! Choose another Event Type or create a Webhook.'); fDisplayError('No webhooks found! Choose another Event Type or create a Webhook.');
return $('#select_event_type').val(''); $('#select_event_type').val('');
} }
} catch (_error) { } catch (_error) {
err = _error; err = _error;
return fDisplayError('Badly formed webhooks!'); fDisplayError('Badly formed webhooks!');
} }
return typeof cb === "function" ? cb() : void 0;
}, },
fail: fFailedRequest('Unable to get webhooks!') fail: function() {
fFailedRequest('Unable to get webhooks!');
return typeof cb === "function" ? cb() : void 0;
}
}); });
case 'Event Poller': case 'Event Poller':
return fIssueRequest({ return fIssueRequest({
@ -223,7 +228,7 @@
oEps = JSON.parse(data.message); oEps = JSON.parse(data.message);
if (JSON.stringify(oEps) === '{}') { if (JSON.stringify(oEps) === '{}') {
fDisplayError('No Event Pollers found! Create one first!'); fDisplayError('No Event Pollers found! Create one first!');
return $('#select_event_type').val(''); $('#select_event_type').val('');
} else { } else {
$('#event_parameters').append(domSelectEventPoller); $('#event_parameters').append(domSelectEventPoller);
$('#event_parameters').append(domInputEventTiming.show()); $('#event_parameters').append(domInputEventTiming.show());
@ -235,14 +240,18 @@
$('#select_eventpoller').append($('<option>').text(id + ' -> ' + evt)); $('#select_eventpoller').append($('<option>').text(id + ' -> ' + evt));
} }
} }
return fFetchEventParams($('option:selected', domSelectEventPoller).text()); fFetchEventParams($('option:selected', domSelectEventPoller).text());
} }
} catch (_error) { } catch (_error) {
err = _error; err = _error;
return console.error('ERROR: non-object received for event poller from server: ' + data.message); console.error('ERROR: non-object received for event poller from server: ' + data.message);
} }
return typeof cb === "function" ? cb() : void 0;
}, },
fail: fFailedRequest('Error fetching Event Poller') fail: function() {
fFailedRequest('Error fetching Event Poller');
return typeof cb === "function" ? cb() : void 0;
}
}); });
} }
}; };
@ -574,7 +583,7 @@
}; };
fOnLoad = function() { fOnLoad = function() {
var editor; var editor, name;
fIssueRequest({ fIssueRequest({
data: { data: {
command: 'get_public_key' command: 'get_public_key'
@ -607,20 +616,20 @@
}); });
switch (oParams.eventtype) { switch (oParams.eventtype) {
case 'custom': case 'custom':
$('#input_id').val("My '" + oParams.eventname + "' Rule"); name = decodeURIComponent(oParams.eventname);
fPrepareEventType('Custom Event'); $('#input_id').val("My '" + name + "' Rule");
$('#input_eventname').val(oParams.eventname); fPrepareEventType('Custom Event', function() {
$('#input_eventname').focus(); $('#input_eventname').val(name);
editor.setValue("[\n\n]"); $('#input_eventname').focus();
return editor.setValue("[\n\n]");
});
break; break;
case 'webhook': case 'webhook':
$('#input_id').val("My '" + oParams.hookname + "' Rule"); name = decodeURIComponent(oParams.hookname);
fPrepareEventType('Webhook'); $('#input_id').val("My '" + name + "' Rule");
domSelectWebhook.val(oParams.hookname); fPrepareEventType('Webhook', function() {
break; return $('select', domSelectWebhook).val(name);
case 'poller': });
$('#input_id').val("My '" + oParams.eventpoller + "' Rule");
fPrepareEventType('Event Poller');
} }
fIssueRequest({ fIssueRequest({
data: { data: {

View file

@ -100,6 +100,7 @@
fOnLoad = function() { fOnLoad = function() {
document.title = 'Create Webhooks!'; document.title = 'Create Webhooks!';
$('#pagetitle').text('Create your own Webhooks!');
fUpdateWebhookList(fShowWebhookUsage); fUpdateWebhookList(fShowWebhookUsage);
$('#but_submit').click(function() { $('#but_submit').click(function() {
var hookname; var hookname;

View file

@ -1,4 +1,4 @@
<h2>Rule Name : <input id="input_id" type="text" value="My new Rule"></h2> <h3>Rule Name : <input id="input_id" type="text" value="My new Rule"></h3>
<h2>EVENT</h2> <h2>EVENT</h2>
<div id="event_type"> <div id="event_type">
@ -19,14 +19,7 @@
<div id="conditions"> <div id="conditions">
Refer to <a target="_blank" href="https://github.com/harthur/js-select#selectors">js-select selectors</a> for valid selectors!<br> Refer to <a target="_blank" href="https://github.com/harthur/js-select#selectors">js-select selectors</a> for valid selectors!<br>
<div id="editor_conditions"> <div id="editor_conditions">
[ [ ]
{
"selector": ".nested_property",
"type": "string",
"operator": "<=",
"compare": "has this value"
}
]
</div> </div>
</div> </div>
<button class="outent20" id="fill_example">Fill with example condition</button> <button class="outent20" id="fill_example">Fill with example condition</button>

View file

@ -1,4 +1,3 @@
<h2>Create your own Webhooks</h2>
<h3>Label the Events received over the new Webhook with : <h3>Label the Events received over the new Webhook with :
<input type="text" id="inp_hookname" style="font-size:1em;width:300px" /></h3> <input type="text" id="inp_hookname" style="font-size:1em;width:300px" /></h3>
<button type="button" id="but_submit">Create Webhook!</button> <button type="button" id="but_submit">Create Webhook!</button>

View file

@ -32,7 +32,7 @@ input[type=password]:focus {
} }
button { button {
font-size: 1.2em; font-size: 1.1em;
} }
.indent20 { .indent20 {
@ -102,9 +102,9 @@ button {
} }
#pagetitle { #pagetitle {
font-size: 2em; font-size: 1.6em;
font-weight: bold; font-weight: bold;
padding-top: 5px; padding-top: 0px;
padding-bottom: 5px; padding-bottom: 5px;
} }