2022-08-17 08:50:24 -07:00
|
|
|
import { IWebhookFunctions } from 'n8n-core';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
2020-12-02 02:54:10 -08:00
|
|
|
IHookFunctions,
|
2020-12-02 02:24:25 -08:00
|
|
|
INodeType,
|
2020-12-02 02:54:10 -08:00
|
|
|
INodeTypeDescription,
|
2020-12-02 02:24:25 -08:00
|
|
|
IWebhookResponseData,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class TheHiveTrigger implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'TheHive Trigger',
|
|
|
|
name: 'theHiveTrigger',
|
2021-03-18 05:06:51 -07:00
|
|
|
icon: 'file:thehive.svg',
|
2020-12-02 02:24:25 -08:00
|
|
|
group: ['trigger'],
|
|
|
|
version: 1,
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Starts the workflow when TheHive events occur',
|
2020-12-02 02:24:25 -08:00
|
|
|
defaults: {
|
|
|
|
name: 'TheHive Trigger',
|
|
|
|
},
|
|
|
|
inputs: [],
|
|
|
|
outputs: ['main'],
|
|
|
|
webhooks: [
|
|
|
|
{
|
|
|
|
name: 'default',
|
|
|
|
httpMethod: 'POST',
|
|
|
|
reponseMode: 'onReceived',
|
|
|
|
path: 'webhook',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Events',
|
|
|
|
name: 'events',
|
|
|
|
type: 'multiOptions',
|
|
|
|
default: [],
|
|
|
|
required: true,
|
|
|
|
description: 'Events types',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: '*',
|
|
|
|
value: '*',
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'Any time any event is triggered (Wildcard Event)',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Alert Created',
|
|
|
|
value: 'alert_create',
|
|
|
|
description: 'Triggered when an alert is created',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Alert Deleted',
|
|
|
|
value: 'alert_delete',
|
|
|
|
description: 'Triggered when an alert is deleted',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Alert Updated',
|
|
|
|
value: 'alert_update',
|
|
|
|
description: 'Triggered when an alert is updated',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Case Created',
|
|
|
|
value: 'case_create',
|
|
|
|
description: 'Triggered when a case is created',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Case Deleted',
|
|
|
|
value: 'case_delete',
|
|
|
|
description: 'Triggered when a case is deleted',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Case Updated',
|
|
|
|
value: 'case_update',
|
|
|
|
description: 'Triggered when a case is updated',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Log Created',
|
|
|
|
value: 'case_task_log_create',
|
|
|
|
description: 'Triggered when a task log is created',
|
|
|
|
},
|
2022-06-20 07:54:01 -07:00
|
|
|
{
|
|
|
|
name: 'Log Deleted',
|
|
|
|
value: 'case_task_log_delete',
|
|
|
|
description: 'Triggered when a task log is deleted',
|
|
|
|
},
|
2020-12-19 09:19:12 -08:00
|
|
|
{
|
|
|
|
name: 'Log Updated',
|
|
|
|
value: 'case_task_log_update',
|
|
|
|
description: 'Triggered when a task log is updated',
|
|
|
|
},
|
|
|
|
{
|
2022-06-20 07:54:01 -07:00
|
|
|
name: 'Observable Created',
|
|
|
|
value: 'case_artifact_create',
|
|
|
|
description: 'Triggered when an observable is created',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Observable Deleted',
|
|
|
|
value: 'case_artifact_delete',
|
|
|
|
description: 'Triggered when an observable is deleted',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Observable Updated',
|
|
|
|
value: 'case_artifact_update',
|
|
|
|
description: 'Triggered when an observable is updated',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Task Created',
|
|
|
|
value: 'case_task_create',
|
|
|
|
description: 'Triggered when a task is created',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Task Deleted',
|
|
|
|
value: 'case_task_delete',
|
|
|
|
description: 'Triggered when a task is deleted',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Task Updated',
|
|
|
|
value: 'case_task_update',
|
|
|
|
description: 'Triggered when a task is updated',
|
2020-12-19 09:19:12 -08:00
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2020-12-02 02:24:25 -08:00
|
|
|
};
|
|
|
|
// @ts-ignore (because of request)
|
|
|
|
webhookMethods = {
|
|
|
|
default: {
|
|
|
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
async create(this: IHookFunctions): Promise<boolean> {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
async delete(this: IHookFunctions): Promise<boolean> {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
|
|
|
// Get the request body
|
|
|
|
const bodyData = this.getBodyData();
|
|
|
|
const events = this.getNodeParameter('events', []) as string[];
|
2020-12-02 02:54:10 -08:00
|
|
|
if (!bodyData.operation || !bodyData.objectType) {
|
2020-12-02 02:24:25 -08:00
|
|
|
// Don't start the workflow if mandatory fields are not specified
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't start the workflow if the event is not fired
|
2020-12-19 09:19:12 -08:00
|
|
|
// Replace Creation with Create for TheHive 3 support
|
|
|
|
const operation = (bodyData.operation as string).replace('Creation', 'Create');
|
|
|
|
const event = `${(bodyData.objectType as string).toLowerCase()}_${operation.toLowerCase()}`;
|
2020-12-02 02:54:10 -08:00
|
|
|
if (events.indexOf('*') === -1 && events.indexOf(event) === -1) {
|
2020-12-02 02:24:25 -08:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// The data to return and so start the workflow with
|
|
|
|
const returnData: IDataObject[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
returnData.push({
|
|
|
|
event,
|
|
|
|
body: this.getBodyData(),
|
|
|
|
headers: this.getHeaderData(),
|
|
|
|
query: this.getQueryData(),
|
|
|
|
});
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
return {
|
2022-08-17 08:50:24 -07:00
|
|
|
workflowData: [this.helpers.returnJsonArray(returnData)],
|
2020-12-02 02:24:25 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|