-
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.
[Ingest] Allow aggent to send metadata compliant with ECS
- Loading branch information
Showing
16 changed files
with
91 additions
and
34 deletions.
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
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
47 changes: 47 additions & 0 deletions
47
...public/applications/ingest_manager/sections/fleet/agent_details_page/components/helper.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,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AgentMetadata } from '../../../../types'; | ||
|
||
export function flattenMetadata(metadata: AgentMetadata) { | ||
return Object.entries(metadata).reduce((acc, [key, value]) => { | ||
if (typeof value === 'string') { | ||
acc[key] = value; | ||
|
||
return acc; | ||
} | ||
|
||
Object.entries(flattenMetadata(value)).forEach(([flattenedKey, flattenedValue]) => { | ||
acc[`${key}.${flattenedKey}`] = flattenedValue; | ||
}); | ||
|
||
return acc; | ||
}, {} as { [k: string]: string }); | ||
} | ||
export function unflattenMetadata(flattened: { [k: string]: string }) { | ||
const metadata: AgentMetadata = {}; | ||
|
||
Object.entries(flattened).forEach(([flattenedKey, flattenedValue]) => { | ||
const keyParts = flattenedKey.split('.'); | ||
const lastKey = keyParts.pop(); | ||
|
||
if (!lastKey) { | ||
throw new Error('Invalid metadata'); | ||
} | ||
|
||
let metadataPart = metadata; | ||
keyParts.forEach(keyPart => { | ||
if (!metadataPart[keyPart]) { | ||
metadataPart[keyPart] = {}; | ||
} | ||
|
||
metadataPart = metadataPart[keyPart] as AgentMetadata; | ||
}); | ||
metadataPart[lastKey] = flattenedValue; | ||
}); | ||
|
||
return metadata; | ||
} |
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
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
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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ export { | |
entries, | ||
// Object types | ||
Agent, | ||
AgentMetadata, | ||
AgentConfig, | ||
NewAgentConfig, | ||
AgentEvent, | ||
|
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
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
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
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
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
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
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
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
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