diff --git a/public/components/integrations/components/add_integration_flyout.tsx b/public/components/integrations/components/add_integration_flyout.tsx index 77e34a9f0..8fd1ffe79 100644 --- a/public/components/integrations/components/add_integration_flyout.tsx +++ b/public/components/integrations/components/add_integration_flyout.tsx @@ -23,12 +23,15 @@ import { EuiTitle, } from '@elastic/eui'; import React, { Fragment, useState } from 'react'; +import { HttpStart } from '../../../../../../src/core/public'; +import { INTEGRATIONS_BASE } from '../../../../common/constants/shared'; interface IntegrationFlyoutProps { onClose: () => void; onCreate: (name: string, dataSource: string) => void; integrationName: string; integrationType: string; + http: HttpStart; } export const doTypeValidation = (toCheck: any, required: any): boolean => { @@ -156,6 +159,17 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) { }, ]; + const createDataSourceMappings = async (targetDataSource: string): Promise => { + const data = await fetch(`${INTEGRATIONS_BASE}/repository/${integrationName}/schema`).then( + (response) => { + return response.json(); + } + ); + Object.keys(data.data.mappings).forEach(function (k) { + createMappings(k, data.data.mappings[k], targetDataSource); + }); + }; + const onCreateSelectChange = (value: any) => { setCreateDatasourceOption(value); }; @@ -210,6 +224,43 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) { }); }; + const createMappings = async ( + componentName: string, + payload: any, + dataSourceName: string + ): Promise<{ [key: string]: { properties: any } } | null> => { + if (componentName !== integrationType) { + return fetch(`/api/console/proxy?path=_component_template/${componentName}&method=POST`, { + method: 'POST', + headers: [ + ['osd-xsrf', 'true'], + ['Content-Type', 'application/json'], + ], + body: JSON.stringify(payload), + }) + .then((response) => response.json()) + .catch((err: any) => { + console.error(err); + return null; + }); + } else { + payload.index_patterns = [dataSourceName]; + return fetch(`/api/console/proxy?path=_index_template/${componentName}&method=POST`, { + method: 'POST', + headers: [ + ['osd-xsrf', 'true'], + ['Content-Type', 'application/json'], + ], + body: JSON.stringify(payload), + }) + .then((response) => response.json()) + .catch((err: any) => { + console.error(err); + return null; + }); + } + }; + const fetchIntegrationMappings = async ( targetName: string ): Promise<{ [key: string]: { template: { mappings: { properties?: any } } } } | null> => { @@ -336,7 +387,9 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) { append={ {}} + onClick={() => { + createDataSourceMappings(createDataSource); + }} disabled={createDataSource.length === 0} > Create diff --git a/public/components/integrations/components/integration.tsx b/public/components/integrations/components/integration.tsx index de6501a56..42b0cb672 100644 --- a/public/components/integrations/components/integration.tsx +++ b/public/components/integrations/components/integration.tsx @@ -99,7 +99,6 @@ export function Integration(props: AvailableIntegrationProps) { }; async function addIntegrationRequest(templateName: string, name: string, dataSource: string) { - console.log(name); http .post(`${INTEGRATIONS_BASE}/store/${templateName}`, { body: JSON.stringify({ name, dataSource }), @@ -163,6 +162,7 @@ export function Integration(props: AvailableIntegrationProps) { }} integrationName={integrationTemplateId} integrationType={integration.type} + http={http} /> )} diff --git a/server/adaptors/integrations/__data__/repository/nginx/schemas/logs-1.0.0.mapping.json b/server/adaptors/integrations/__data__/repository/nginx/schemas/logs-1.0.0.mapping.json index 7e924d67c..4cc358145 100644 --- a/server/adaptors/integrations/__data__/repository/nginx/schemas/logs-1.0.0.mapping.json +++ b/server/adaptors/integrations/__data__/repository/nginx/schemas/logs-1.0.0.mapping.json @@ -1,6 +1,6 @@ { "index_patterns": [ - "sso_logs-*-*" + "ss4o_logs-*-*" ], "data_stream": {}, "template": { @@ -215,8 +215,8 @@ } }, "composed_of": [ - "http_template", - "communication_template" + "communication", + "http" ], "version": 1, "_meta": {