-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Posture] Create indices for benchmark score and latest findings (
- Loading branch information
Showing
5 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/cloud_security_posture/server/create_indices/benchmark_score_mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const benchmarkScoreMapping: MappingTypeMapping = { | ||
properties: { | ||
'@timestamp': { | ||
type: 'date', | ||
}, | ||
score: { | ||
type: 'float', | ||
}, | ||
total_findings: { | ||
type: 'integer', | ||
}, | ||
'passed.passed_counter': { | ||
type: 'integer', | ||
}, | ||
'failed.failed_counter': { | ||
type: 'integer', | ||
}, | ||
cluster_id: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
'rule.benchmark.name': { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/cloud_security_posture/server/create_indices/create_transforms_indices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { transformError } from '@kbn/securitysolution-es-utils'; | ||
import { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types'; | ||
import type { ElasticsearchClient, Logger } from '../../../../../src/core/server'; | ||
import { benchmarkScoreMapping } from './benchmark_score_mapping'; | ||
import { latestFindingsMapping } from './latest_findings_mapping'; | ||
import { | ||
LATEST_FINDINGS_INDEX_PATTERN, | ||
BENCHMARK_SCORE_INDEX_PATTERN, | ||
} from '../../common/constants'; | ||
|
||
// TODO: Add integration tests | ||
export const initializeCspTransformsIndices = async ( | ||
esClient: ElasticsearchClient, | ||
logger: Logger | ||
) => { | ||
createIndexIfNotExists(esClient, LATEST_FINDINGS_INDEX_PATTERN, latestFindingsMapping, logger); | ||
createIndexIfNotExists(esClient, BENCHMARK_SCORE_INDEX_PATTERN, benchmarkScoreMapping, logger); | ||
}; | ||
|
||
export const createIndexIfNotExists = async ( | ||
esClient: ElasticsearchClient, | ||
index: string, | ||
mapping: MappingTypeMapping, | ||
logger: Logger | ||
) => { | ||
try { | ||
const isLatestIndexExists = await esClient.indices.exists({ | ||
index, | ||
}); | ||
|
||
if (!isLatestIndexExists) { | ||
await esClient.indices.create({ | ||
index, | ||
mappings: mapping, | ||
}); | ||
} | ||
} catch (err) { | ||
const error = transformError(err); | ||
logger.error(`Failed to create ${LATEST_FINDINGS_INDEX_PATTERN}`); | ||
logger.error(error.message); | ||
} | ||
}; |
109 changes: 109 additions & 0 deletions
109
x-pack/plugins/cloud_security_posture/server/create_indices/latest_findings_mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const latestFindingsMapping: MappingTypeMapping = { | ||
properties: { | ||
result: { | ||
properties: { | ||
evaluation: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
agent: { | ||
properties: { | ||
id: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'@timestamp': { | ||
type: 'date', | ||
}, | ||
cycle_id: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
resource: { | ||
properties: { | ||
filename: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
type: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
resource_id: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
rule: { | ||
properties: { | ||
name: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
benchmark: { | ||
properties: { | ||
name: { | ||
type: 'text', | ||
fields: { | ||
keyword: { | ||
ignore_above: 1024, | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters