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
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'
try
body = JSON.parse body
@ -364,6 +368,7 @@ parsePushAndAnswerEvent = ( eventname, username, body, resp ) ->
catch err
resp.send 400, 'Badly formed event!'
return
obj =
eventname: eventname
body: body
@ -389,7 +394,7 @@ exports.handleMeasurements = ( req, resp ) =>
if obj.eventname is 'uptimestatistics'
# This is a hack to quickly allow storing of public accessible data
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

View file

@ -480,7 +480,7 @@ Request Handler
obj = parsePushAndAnswerEvent(name, null, body, resp);
if (obj.eventname === 'uptimestatistics') {
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
fPrepareEventType = ( eventtype ) ->
fPrepareEventType = ( eventtype, cb ) ->
$( '#select_event_type' ).val eventtype
$( '#event_parameters > div' ).detach()
switch eventtype
@ -161,6 +161,7 @@ fPrepareEventType = ( eventtype ) ->
# The user wants to react to custom event
when 'Custom Event'
$( '#event_parameters' ).append domInputEventName
cb?()
# The user wants a webhook as event producer
when 'Webhook'
@ -185,8 +186,12 @@ fPrepareEventType = ( eventtype ) ->
catch err
fDisplayError 'Badly formed webhooks!'
cb?()
fail: fFailedRequest 'Unable to get webhooks!'
fail: () ->
fFailedRequest 'Unable to get webhooks!'
cb?()
when 'Event Poller'
fIssueRequest
@ -211,8 +216,11 @@ fPrepareEventType = ( eventtype ) ->
catch err
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
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
switch oParams.eventtype
when 'custom'
$( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
fPrepareEventType 'Custom Event'
$( '#input_eventname' ).val oParams.eventname
$( '#input_eventname' ).focus()
editor.setValue "[\n\n]" # For now we don't prepare conditions
name = decodeURIComponent oParams.eventname
$( '#input_id' ).val "My '#{ name }' Rule"
fPrepareEventType 'Custom Event', () ->
$( '#input_eventname' ).val name
$( '#input_eventname' ).focus()
editor.setValue "[\n\n]" # For now we don't prepare conditions
when 'webhook'
$( '#input_id' ).val "My '#{ oParams.hookname }' Rule"
fPrepareEventType 'Webhook'
domSelectWebhook.val oParams.hookname
when 'poller'
$( '#input_id' ).val "My '#{ oParams.eventpoller }' Rule"
fPrepareEventType 'Event Poller'
name = decodeURIComponent oParams.hookname
$( '#input_id' ).val "My '#{ name }' Rule"
fPrepareEventType 'Webhook', () ->
$( 'select', domSelectWebhook ).val name
# ACTIONS

View file

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

View file

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

View file

@ -100,6 +100,7 @@
fOnLoad = function() {
document.title = 'Create Webhooks!';
$('#pagetitle').text('Create your own Webhooks!');
fUpdateWebhookList(fShowWebhookUsage);
$('#but_submit').click(function() {
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>
<div id="event_type">
@ -19,14 +19,7 @@
<div id="conditions">
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">
[
{
"selector": ".nested_property",
"type": "string",
"operator": "<=",
"compare": "has this value"
}
]
[ ]
</div>
</div>
<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 :
<input type="text" id="inp_hookname" style="font-size:1em;width:300px" /></h3>
<button type="button" id="but_submit">Create Webhook!</button>

View file

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