-
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.
Fixed due to comments, moved getHealth to a plugin level
- Loading branch information
1 parent
41e338a
commit 397a622
Showing
14 changed files
with
205 additions
and
216 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
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { ISavedObjectsRepository, SavedObjectsFindResult } from 'src/core/server'; | ||
import { AlertsHealth, HealthStatus, RawAlert, AlertExecutionStatusErrorReasons } from '../types'; | ||
|
||
export const getHealth = async ( | ||
internalSavedObjectsRepository: ISavedObjectsRepository | ||
): Promise<AlertsHealth> => { | ||
const { saved_objects: data } = await internalSavedObjectsRepository.find<RawAlert>({ | ||
filter: 'alert.attributes.executionStatus.status:error', | ||
fields: ['executionStatus'], | ||
type: 'alert', | ||
}); | ||
|
||
const healthStatuses = data.reduce( | ||
(prevItem: AlertsHealth, item: SavedObjectsFindResult<RawAlert>) => { | ||
switch (item.attributes.executionStatus.error?.reason) { | ||
case AlertExecutionStatusErrorReasons.Decrypt: | ||
prevItem.decryptionHealth = { | ||
status: HealthStatus.Warning, | ||
timestamp: item.attributes.executionStatus.lastExecutionDate, | ||
}; | ||
break; | ||
case AlertExecutionStatusErrorReasons.Execute: | ||
prevItem.executionHealth = { | ||
status: HealthStatus.Warning, | ||
timestamp: item.attributes.executionStatus.lastExecutionDate, | ||
}; | ||
break; | ||
case AlertExecutionStatusErrorReasons.Read: | ||
prevItem.readHealth = { | ||
status: HealthStatus.Warning, | ||
timestamp: item.attributes.executionStatus.lastExecutionDate, | ||
}; | ||
break; | ||
} | ||
return prevItem; | ||
}, | ||
{ | ||
decryptionHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: '', | ||
}, | ||
executionHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: '', | ||
}, | ||
readHealth: { | ||
status: HealthStatus.OK, | ||
timestamp: '', | ||
}, | ||
} | ||
); | ||
|
||
const { saved_objects: noErrorData } = await internalSavedObjectsRepository.find<RawAlert>({ | ||
filter: 'not alert.attributes.executionStatus.status:error', | ||
fields: ['executionStatus'], | ||
type: 'alert', | ||
}); | ||
const lastExecutionDate = noErrorData.reduce( | ||
(prev: Date, item) => | ||
prev > new Date(item.attributes.executionStatus.lastExecutionDate) | ||
? prev | ||
: new Date(item.attributes.executionStatus.lastExecutionDate), | ||
new Date('0001/01/01') | ||
); | ||
|
||
for (const [, statusItem] of Object.entries(healthStatuses)) { | ||
if (statusItem.status === HealthStatus.OK) { | ||
statusItem.timestamp = lastExecutionDate.toISOString(); | ||
} | ||
} | ||
|
||
return healthStatuses; | ||
}; |
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
Oops, something went wrong.