-
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.
First pass at a Security Diagnostics task
- Loading branch information
Showing
3 changed files
with
94 additions
and
5 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
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/security_solution/server/lib/telemetry/task.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,70 @@ | ||
/* | ||
* 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 { Logger } from 'src/core/server'; | ||
import { | ||
ConcreteTaskInstance, | ||
TaskManagerSetupContract, | ||
TaskManagerStartContract, | ||
} from '../../../../task_manager/server'; | ||
import { TelemetryEventsSender } from './sender'; | ||
|
||
export const TelemetryDiagTaskConstants = { | ||
TIMEOUT: '1m', | ||
TYPE: 'security:telemetry-diagnostics', | ||
INTERVAL: '10s', // TODO: update to 5m | ||
VERSION: '1.0.0', | ||
}; | ||
|
||
export class TelemetryDiagTask { | ||
private readonly logger: Logger; | ||
private readonly sender: TelemetryEventsSender; | ||
|
||
constructor( | ||
logger: Logger, | ||
taskManager: TaskManagerSetupContract, | ||
sender: TelemetryEventsSender | ||
) { | ||
this.logger = logger; | ||
this.sender = sender; | ||
|
||
taskManager.registerTaskDefinitions({ | ||
[TelemetryDiagTaskConstants.TYPE]: { | ||
title: 'Security Solution Telemetry Diagnostics task', | ||
timeout: TelemetryDiagTaskConstants.TIMEOUT, | ||
createTaskRunner: ({ taskInstance }: { taskInstance: ConcreteTaskInstance }) => { | ||
return { | ||
run: async () => { | ||
this.logger.debug('Telemetry Diagnostic task is running'); | ||
this.logger.debug(`Sender pointer: ${this.sender}`); | ||
}, | ||
cancel: async () => {}, | ||
}; | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
public start = async (taskManager: TaskManagerStartContract) => { | ||
try { | ||
await taskManager.ensureScheduled({ | ||
id: this.getTaskId(), | ||
taskType: TelemetryDiagTaskConstants.TYPE, | ||
scope: ['securitySolution'], | ||
schedule: { | ||
interval: TelemetryDiagTaskConstants.INTERVAL, | ||
}, | ||
state: {}, | ||
params: { version: TelemetryDiagTaskConstants.VERSION }, | ||
}); | ||
} catch (e) { | ||
this.logger.error(`Error scheduling task, received ${e.message}`); | ||
} | ||
}; | ||
|
||
private getTaskId = (): string => { | ||
return `${TelemetryDiagTaskConstants.TYPE}:${TelemetryDiagTaskConstants.VERSION}`; | ||
}; | ||
} |
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