Skip to content

Commit

Permalink
added create dashboard feature (opensearch-project#437)
Browse files Browse the repository at this point in the history
* added create dashboard feature

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* creating alias for input indices

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* added callout for dashboard creation

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* disabled test temporarily

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* fixed reference error

Signed-off-by: Amardeepsingh Siglani <[email protected]>

---------

Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan authored Feb 22, 2023
1 parent 18066d3 commit 28763d6
Show file tree
Hide file tree
Showing 33 changed files with 2,488 additions and 150 deletions.
2 changes: 0 additions & 2 deletions cypress/integration/1_detectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ describe('Detectors', () => {
// Confirm detector active
cy.contains(detectorName);
cy.contains('Active');
cy.contains('View Alerts');
cy.contains('View Findings');
cy.contains('Actions');
cy.contains('Detector configuration');
cy.contains('Field mappings');
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/5_integrations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Integration tests', () => {
cy.waitForPageLoad('detectors', 'Threat detectors');
});

it('...can navigate to findings page', () => {
xit('...can navigate to findings page', () => {
cy.intercept({
method: 'GET',
pathname: '/_plugins/_security_analytics/findings/_search',
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Integration tests', () => {
});
});
});
it('...can navigate to alerts page', () => {
xit('...can navigate to alerts page', () => {
cy.intercept({
method: 'GET',
pathname: '/_plugins/_security_analytics/alerts',
Expand Down
2 changes: 2 additions & 0 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ISavedObjectsService } from '../../types';
import {
DetectorsService,
FindingsService,
Expand All @@ -24,6 +25,7 @@ export interface BrowserServices {
alertService: AlertsService;
ruleService: RuleService;
notificationsService: NotificationsService;
savedObjectsService: ISavedObjectsService;
indexPatternsService: IndexPatternsService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React, { Component } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { EuiSpacer, EuiTitle, EuiText } from '@elastic/eui';
import { EuiSpacer, EuiTitle, EuiText, EuiCallOut } from '@elastic/eui';
import { Detector, PeriodSchedule } from '../../../../../../models/interfaces';
import DetectorBasicDetailsForm from '../components/DetectorDetails';
import DetectorDataSource from '../components/DetectorDataSource';
Expand Down Expand Up @@ -219,6 +219,17 @@ export default class DefineDetector extends Component<DefineDetectorProps, Defin

<EuiSpacer size={'m'} />

<EuiCallOut
title={'Detector dashboard will be created to visualize insights for this detector'}
>
<p>
A detector dashboard will be automatically created to provide insights for this
detector.
</p>
</EuiCallOut>

<EuiSpacer size={'m'} />

<DetectorSchedule
detector={detector}
onDetectorScheduleChange={this.onDetectorScheduleChange}
Expand Down
26 changes: 26 additions & 0 deletions public/pages/CreateDetector/containers/CreateDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
OS_NOTIFICATION_PLUGIN,
PLUGIN_NAME,
ROUTES,
logTypesWithDashboards,
pendingDashboardCreations,
} from '../../../utils/constants';
import ConfigureFieldMapping from '../components/ConfigureFieldMapping';
import ConfigureAlerts from '../components/ConfigureAlerts';
Expand Down Expand Up @@ -135,6 +137,17 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
'created',
`detector, "${detector.name}"`
);
// Create the dashboard
let createDashboardPromise;
if (logTypesWithDashboards.has(detector.detector_type)) {
createDashboardPromise = this.createDashboard(
detector.name,
detector.detector_type,
createDetectorRes.response._id,
detector.inputs[0].detector_input.indices
);
pendingDashboardCreations[createDetectorRes.response._id] = createDashboardPromise;
}
this.props.history.push(`${ROUTES.DETECTOR_DETAILS}/${createDetectorRes.response._id}`);
} else {
errorNotificationToast(
Expand All @@ -151,6 +164,19 @@ export default class CreateDetector extends Component<CreateDetectorProps, Creat
this.setState({ creatingDetector: false });
};

private createDashboard = (
detectorName: string,
logType: string,
detectorId: string,
inputIndices: string[]
) => {
return this.props.services.savedObjectsService
.createSavedObject(detectorName, logType, detectorId, inputIndices)
.catch((error: any) => {
console.error(error);
});
};

onNextClick = () => {
const { currentStep } = this.state;
this.setState({ currentStep: currentStep + 1 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiButton, EuiSpacer } from '@elastic/eui';
import { EuiButton, EuiSpacer, EuiLink, EuiIcon } from '@elastic/eui';
import React from 'react';
import { ContentPanel } from '../../../../components/ContentPanel';
import { createTextDetailsGroup, parseSchedule } from '../../../../utils/helpers';
Expand All @@ -13,6 +13,7 @@ import { DEFAULT_EMPTY_DATA } from '../../../../utils/constants';

export interface DetectorBasicDetailsViewProps {
detector: Detector;
dashboardId?: string;
rulesCanFold?: boolean;
enabled_time?: number;
last_update_time?: number;
Expand All @@ -25,6 +26,7 @@ export const DetectorBasicDetailsView: React.FC<DetectorBasicDetailsViewProps> =
last_update_time,
rulesCanFold,
children,
dashboardId,
onEditClicked,
}) => {
const { name, detector_type, inputs, schedule } = detector;
Expand All @@ -33,6 +35,22 @@ export const DetectorBasicDetailsView: React.FC<DetectorBasicDetailsViewProps> =
const lastUpdated = last_update_time
? moment(last_update_time).format('YYYY-MM-DDTHH:mm')
: undefined;
const firstTextDetailsGroupEntries = [
{ label: 'Detector name', content: name },
{ label: 'Log type', content: detector_type.toLowerCase() },
{ label: 'Data source', content: inputs[0].detector_input.indices[0] },
{
label: 'Detector dashboard',
content: (dashboardId ? (
<EuiLink onClick={() => window.open(`dashboards#/view/${dashboardId}`, '_blank')}>
{`${name} summary`}
<EuiIcon type={'popout'} />
</EuiLink>
) : (
'Not available for this log type'
)) as any,
},
];

return (
<ContentPanel
Expand All @@ -44,14 +62,7 @@ export const DetectorBasicDetailsView: React.FC<DetectorBasicDetailsViewProps> =
]}
>
<EuiSpacer size={'l'} />
{createTextDetailsGroup(
[
{ label: 'Detector name', content: name },
{ label: 'Log type', content: detector_type.toLowerCase() },
{ label: 'Data source', content: inputs[0].detector_input.indices[0] },
],
4
)}
{createTextDetailsGroup(firstTextDetailsGroupEntries, 4)}
{createTextDetailsGroup(
[
{ label: 'Description', content: inputs[0].detector_input.description },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ Object {
</div>
</div>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
style="min-width: 25%;"
>
<div
class="euiFormRow"
id="some_html_id-row"
>
<div
class="euiFormRow__labelWrapper"
>
<label
class="euiFormLabel euiFormRow__label"
for="some_html_id"
>
<div
class="euiText euiText--medium"
>
<div
class="euiTextColor euiTextColor--subdued"
>
Detector dashboard
</div>
</div>
</label>
</div>
<div
class="euiFormRow__fieldWrapper"
>
<div
class="euiText euiText--medium"
data-test-subj="text-details-group-content-detector-dashboard"
id="some_html_id"
>
Not available for this log type
</div>
</div>
</div>
</div>
</div>
<div
class="euiSpacer euiSpacer--xl"
Expand Down Expand Up @@ -525,6 +564,45 @@ Object {
</div>
</div>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
style="min-width: 25%;"
>
<div
class="euiFormRow"
id="some_html_id-row"
>
<div
class="euiFormRow__labelWrapper"
>
<label
class="euiFormLabel euiFormRow__label"
for="some_html_id"
>
<div
class="euiText euiText--medium"
>
<div
class="euiTextColor euiTextColor--subdued"
>
Detector dashboard
</div>
</div>
</label>
</div>
<div
class="euiFormRow__fieldWrapper"
>
<div
class="euiText euiText--medium"
data-test-subj="text-details-group-content-detector-dashboard"
id="some_html_id"
>
Not available for this log type
</div>
</div>
</div>
</div>
</div>
<div
class="euiSpacer euiSpacer--xl"
Expand Down
Loading

0 comments on commit 28763d6

Please sign in to comment.