Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a builtin action for triggering webhooks #43538

Merged
merged 35 commits into from
Aug 23, 2019
Merged
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d8fa533
feat(webhook-action): Introduced new action type for webhooks
gmmorris Aug 19, 2019
4b05878
feat(webhook-action): Defined secret username and password validation
gmmorris Aug 19, 2019
c9e44bf
feat(webhook-action): Defined the basic configuration object with key…
gmmorris Aug 19, 2019
fee15cd
feat(webhook-action): Defined the advanced configurations for proxy a…
gmmorris Aug 19, 2019
3520e6e
feat(webhook-action): Defined the the overriding url field on the con…
gmmorris Aug 19, 2019
5f1a631
feat(webhook-action): Defined the basic parameters object for the action
gmmorris Aug 19, 2019
1949a55
feat(webhook-action): Reduced HTTP methods down to just POST & PUT to…
gmmorris Aug 20, 2019
5dbedcf
feat(webhook-action): Changed `username` field to `user` to align wit…
gmmorris Aug 20, 2019
9ec86c6
refactor(webhook-action): Introduced enum in place of strings adding …
gmmorris Aug 20, 2019
d3fda32
refactor(alerting-integration-test): Extract Slack Simulator so its e…
gmmorris Aug 20, 2019
4aee48e
Merge branch 'refactor/external-service-simulator' into actions/webhooks
gmmorris Aug 20, 2019
06a1d54
refactor(webhook-action): Use the type system to differenciate betwee…
gmmorris Aug 20, 2019
13bc887
feat(webhook-action): Exposed built in Webhook action
gmmorris Aug 20, 2019
0e531e8
refactor(alerting-integration-test): Extracted Slack Service simulator
gmmorris Aug 21, 2019
7d9b18f
fix(webhook-action): Merged rejigging of integrations tests
gmmorris Aug 21, 2019
a375358
feat(webhook-action): Webhook action makes athenticated calls to targ…
gmmorris Aug 21, 2019
538ca67
feat(webhook-action): Webhook action support both POST and PUT as met…
gmmorris Aug 21, 2019
b1d0a28
feat(webhook-action): Webhook action now supports composite urls
gmmorris Aug 21, 2019
b9a84b6
feat(webhook-action): Webhook action can now handle unreachable and f…
gmmorris Aug 21, 2019
a5ca4bd
feat(webhook-action): Removed proxy and timeouts from the Webhook act…
gmmorris Aug 21, 2019
016ddcb
fix(webhook-action): Fixed clash in SimualtedService whitelisting
gmmorris Aug 21, 2019
05326d7
refactor(webhook-action): Actions now use shared schema and Axios as …
gmmorris Aug 22, 2019
b15392f
Merge branch 'master' into actions/webhooks
gmmorris Aug 22, 2019
d20f718
feat(webhook-action): Added i18n wrapping for an unrechableWebhook er…
gmmorris Aug 22, 2019
a94343a
Merge branch 'master' into actions/webhooks
gmmorris Aug 22, 2019
402aacc
refactor(webhook-action): unify result and retry messaging beltween a…
gmmorris Aug 23, 2019
dcd9f75
refactor(webhook-action): export each function individually
gmmorris Aug 23, 2019
290ae25
refactor(webhook-action): removed Hapi/basic and replaced with simple…
gmmorris Aug 23, 2019
b660982
refactor(webhook-action): cleaned up error handling from webhooks
gmmorris Aug 23, 2019
6939311
fix(webhook-action): Ununified result messaging as i18n cant handle r…
gmmorris Aug 23, 2019
495a9f7
disabled webhook action registration and integration tests inorder to…
gmmorris Aug 23, 2019
3aa3400
fix(action-webhook): only return a retry in seconds if the service ha…
gmmorris Aug 23, 2019
73414f4
refactor(action-webhook): removed composite url support
gmmorris Aug 23, 2019
93ae024
refactor(action-webhook): removed unused code
gmmorris Aug 23, 2019
6cd70f1
fix(action-webhook): removed unused type
gmmorris Aug 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -8,7 +8,10 @@ import expect from '@kbn/expect';

import { FtrProviderContext } from '../../../ftr_provider_context';

import { SLACK_ACTION_SIMULATOR_URI } from '../../../fixtures/plugins/actions';
import {
ExternalServiceSimulator,
getExternalServiceSimulatorPath,
} from '../../../fixtures/plugins/actions';

export default function slackTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
@@ -22,7 +25,9 @@ export default function slackTest({ getService }: FtrProviderContext) {
before(() => {
const kibanaServer = getService('kibanaServer');
const kibanaUrl = kibanaServer.status && kibanaServer.status.kibanaServerUrl;
slackSimulatorURL = `${kibanaUrl}${SLACK_ACTION_SIMULATOR_URI}`;
slackSimulatorURL = `${kibanaUrl}${getExternalServiceSimulatorPath(
ExternalServiceSimulator.SLACK
)}`;
});

after(() => esArchiver.unload('empty_kibana'));
Original file line number Diff line number Diff line change
@@ -3,94 +3,28 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import Joi from 'joi';
import Hapi from 'hapi';
import { initPlugin as initSlack } from './slack_simulation';

const NAME = 'actions-FTS-external-service-simulators';

export const SLACK_ACTION_SIMULATOR_URI = `/api/_${NAME}/slack`;
export enum ExternalServiceSimulator {
SLACK = 'slack',
}

interface SlackRequest extends Hapi.Request {
payload: {
text: string;
};
export function getExternalServiceSimulatorPath(service: ExternalServiceSimulator): string {
return `/api/_${NAME}/${service}`;
}

export const SLACK_ACTION_SIMULATOR_URI = `/api/_${NAME}/slack`;

// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
require: ['actions'],
name: NAME,
init: initPlugin,
});
}

function initPlugin(server: any) {
server.route({
method: 'POST',
path: `${SLACK_ACTION_SIMULATOR_URI}`,
options: {
auth: false,
validate: {
options: { abortEarly: false },
payload: Joi.object().keys({
text: Joi.string(),
}),
},
init: (server: Hapi.Server) => {
initSlack(server, getExternalServiceSimulatorPath(ExternalServiceSimulator.SLACK));
},
handler: slackHandler,
});
}

// Slack simulator: create a slack action pointing here, and you can get
// different responses based on the message posted. See the README.md for
// more info.

function slackHandler(request: SlackRequest, h: any) {
const body = request.payload;
const text = body && body.text;

if (text == null) {
return htmlResponse(h, 400, 'bad request to slack simulator');
}

switch (text) {
case 'success':
return htmlResponse(h, 200, 'ok');

case 'no_text':
return htmlResponse(h, 400, 'no_text');

case 'invalid_payload':
return htmlResponse(h, 400, 'invalid_payload');

case 'invalid_token':
return htmlResponse(h, 403, 'invalid_token');

case 'status_500':
return htmlResponse(h, 500, 'simulated slack 500 response');

case 'rate_limit':
const response = {
retry_after: 1,
ok: false,
error: 'rate_limited',
};

return h
.response(response)
.type('application/json')
.header('retry-after', '1')
.code(429);
}

return htmlResponse(h, 400, 'unknown request to slack simulator');
}

function htmlResponse(h: any, code: number, text: string) {
return h
.response(text)
.type('text/html')
.code(code);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import Joi from 'joi';
import Hapi from 'hapi';

interface SlackRequest extends Hapi.Request {
payload: {
text: string;
};
}
export function initPlugin(server: Hapi.Server, path: string) {
server.route({
method: 'POST',
path,
options: {
auth: false,
validate: {
options: { abortEarly: false },
payload: Joi.object().keys({
text: Joi.string(),
}),
},
},
handler: slackHandler,
});
}
// Slack simulator: create a slack action pointing here, and you can get
// different responses based on the message posted. See the README.md for
// more info.

function slackHandler(request: SlackRequest, h: any) {
const body = request.payload;
const text = body && body.text;

if (text == null) {
return htmlResponse(h, 400, 'bad request to slack simulator');
}

switch (text) {
case 'success':
return htmlResponse(h, 200, 'ok');

case 'no_text':
return htmlResponse(h, 400, 'no_text');

case 'invalid_payload':
return htmlResponse(h, 400, 'invalid_payload');

case 'invalid_token':
return htmlResponse(h, 403, 'invalid_token');

case 'status_500':
return htmlResponse(h, 500, 'simulated slack 500 response');

case 'rate_limit':
const response = {
retry_after: 1,
ok: false,
error: 'rate_limited',
};

return h
.response(response)
.type('application/json')
.header('retry-after', '1')
.code(429);
}

return htmlResponse(h, 400, 'unknown request to slack simulator');
}

function htmlResponse(h: any, code: number, text: string) {
return h
.response(text)
.type('text/html')
.code(code);
}