kibana/x-pack/plugins/actions/server/lib/related_saved_objects.ts
Patrick Mueller 86fb2cc90e
[actions] add rule saved object reference to action execution event log doc (#101526)
resolves https://github.com/elastic/kibana/issues/99225

Prior to this PR, when an alerting connection action was executed, the event 
log document generated did not contain a reference to the originating rule. 
This makes it difficult to diagnose problems with connector errors, since 
the error is often in the parameters specified in the actions in the alert.

In this PR, a reference to the alerting rule is added to the saved_objects 
field in the event document for these events.
2021-06-22 15:18:35 -04:00

31 lines
1.1 KiB
TypeScript

/*
* 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 { schema, TypeOf } from '@kbn/config-schema';
import { Logger } from '../../../../../src/core/server';
export type RelatedSavedObjects = TypeOf<typeof RelatedSavedObjectsSchema>;
const RelatedSavedObjectsSchema = schema.arrayOf(
schema.object({
namespace: schema.maybe(schema.string({ minLength: 1 })),
id: schema.string({ minLength: 1 }),
type: schema.string({ minLength: 1 }),
// optional; for SO types like action/alert that have type id's
typeId: schema.maybe(schema.string({ minLength: 1 })),
}),
{ defaultValue: [] }
);
export function validatedRelatedSavedObjects(logger: Logger, data: unknown): RelatedSavedObjects {
try {
return RelatedSavedObjectsSchema.validate(data);
} catch (err) {
logger.warn(`ignoring invalid related saved objects: ${err.message}`);
return [];
}
}