Skip to content

Commit

Permalink
fix IM rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliidm committed Sep 24, 2024
1 parent 8336940 commit 2ad72b5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const createIndicatorMatchAlertType = (
secondaryTimestamp,
exceptionFilter,
unprocessedExceptions,
inputIndexFields,
},
services,
spaceId,
Expand Down Expand Up @@ -119,7 +118,6 @@ export const createIndicatorMatchAlertType = (
secondaryTimestamp,
exceptionFilter,
unprocessedExceptions,
inputIndexFields,
wrapSuppressedHits,
runOpts,
licensing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
RuleExecutorServices,
} from '@kbn/alerting-plugin/server';
import type { ListClient } from '@kbn/lists-plugin/server';
import type { Filter, DataViewFieldBase } from '@kbn/es-query';
import type { Filter } from '@kbn/es-query';
import type { RuleRangeTuple, BulkCreate, WrapHits, WrapSuppressedHits, RunOpts } from '../types';
import type { ITelemetryEventsSender } from '../../../telemetry/sender';
import { createThreatSignals } from './threat_mapping/create_threat_signals';
Expand Down Expand Up @@ -43,7 +43,6 @@ export const indicatorMatchExecutor = async ({
secondaryTimestamp,
exceptionFilter,
unprocessedExceptions,
inputIndexFields,
wrapSuppressedHits,
runOpts,
licensing,
Expand All @@ -65,7 +64,6 @@ export const indicatorMatchExecutor = async ({
secondaryTimestamp?: string;
exceptionFilter: Filter | undefined;
unprocessedExceptions: ExceptionListItemSchema[];
inputIndexFields: DataViewFieldBase[];
wrapSuppressedHits: WrapSuppressedHits;
runOpts: RunOpts<ThreatRuleParams>;
licensing: LicensingPluginSetup;
Expand Down Expand Up @@ -106,7 +104,6 @@ export const indicatorMatchExecutor = async ({
secondaryTimestamp,
exceptionFilter,
unprocessedExceptions,
inputIndexFields,
runOpts,
licensing,
experimentalFeatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { firstValueFrom } from 'rxjs';
import type { OpenPointInTimeResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import { uniq, chunk } from 'lodash/fp';
import { queryToFields } from '@kbn/data-plugin/common';

import { TelemetryChannel } from '../../../../telemetry/types';
import { getThreatList, getThreatListCount } from './get_threat_list';
Expand All @@ -36,7 +37,6 @@ import { getEventCount, getEventList } from './get_event_count';
import { getMappingFilters } from './get_mapping_filters';
import { THREAT_PIT_KEEP_ALIVE } from '../../../../../../common/cti/constants';
import { getMaxSignalsWarning, getSafeSortIds } from '../../utils/utils';
import { getFieldsForWildcard } from '../../utils/get_fields_for_wildcard';
import { getDataTierFilter } from '../../utils/get_data_tier_filter';

export const createThreatSignals = async ({
Expand Down Expand Up @@ -72,7 +72,6 @@ export const createThreatSignals = async ({
secondaryTimestamp,
exceptionFilter,
unprocessedExceptions,
inputIndexFields,
licensing,
experimentalFeatures,
}: CreateThreatSignalsOptions): Promise<SearchAfterAndBulkCreateReturnType> => {
Expand Down Expand Up @@ -115,6 +114,17 @@ export const createThreatSignals = async ({
const allEventFilters = [...filters, eventMappingFilter, ...dataTiersFilters];
const allThreatFilters = [...threatFilters, indicatorMappingFilter, ...dataTiersFilters];

const dataViews = await services.getDataViews();
const inputIndexDataViewLazy = await dataViews.createDataViewLazy({
title: inputIndex.join(),
});
const inputIndexFields = Object.values(
await queryToFields({
dataView: inputIndexDataViewLazy,
request: { query: [{ query, language: language || 'kuery' }] },
})
);

const eventCount = await getEventCount({
esClient: services.scopedClusterClient.asCurrentUser,
index: inputIndex,
Expand All @@ -140,14 +150,15 @@ export const createThreatSignals = async ({
if (newPitId) threatPitId = newPitId;
};

const dataViews = await services.getDataViews();
// const threatIndexFields = await getFieldsForWildcard({
// index: threatIndex,
// language: threatLanguage ?? 'kuery',
// dataViews,
// ruleExecutionLogger,
// });
const threatIndexFields = [];
const threatIndexDataViewLazy = await dataViews.createDataViewLazy({
title: threatIndex.join(),
});
const threatIndexFields = Object.values(
await queryToFields({
dataView: threatIndexDataViewLazy,
request: { query: [{ query: threatQuery, language: threatLanguage || 'kuery' }] },
})
);

const threatListCount = await getThreatListCount({
esClient: services.scopedClusterClient.asCurrentUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export interface CreateThreatSignalsOptions {
secondaryTimestamp?: string;
exceptionFilter: Filter | undefined;
unprocessedExceptions: ExceptionListItemSchema[];
inputIndexFields: DataViewFieldBase[];
runOpts: RunOpts<ThreatRuleParams>;
licensing: LicensingPluginSetup;
experimentalFeatures: ExperimentalFeatures;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
RuleExecutorServices,
} from '@kbn/alerting-plugin/server';
import type { IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import type { Filter, DataViewFieldBase } from '@kbn/es-query';
import type { Filter } from '@kbn/es-query';
import type { CompleteRule, ThresholdRuleParams } from '../../rule_schema';
import { getFilter } from '../utils/get_filter';
import { bulkCreateThresholdSignals } from './bulk_create_threshold_signals';
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 2ad72b5

Please sign in to comment.