Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Actions] System actions MVP #166267

Merged
merged 147 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
29973e2
[Actions] Connector Adapters MVP (#166101)
cnasikas Sep 12, 2023
10e2a56
Merge branch 'main' into system_actions_mvp
cnasikas Sep 13, 2023
1bb0eb5
Merge branch 'main' into system_actions_mvp
cnasikas Sep 16, 2023
dac21c2
Merge branch 'main' into system_actions_mvp
cnasikas Oct 2, 2023
d5f1791
[Actions] Expose `getAllSystemActions` from the actions client (#167783)
cnasikas Oct 3, 2023
d465407
Merge branch 'main' into system_actions_mvp
cnasikas Oct 3, 2023
a6d9da4
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
cnasikas Oct 3, 2023
b064eba
Merge branch 'main' into system_actions_mvp
cnasikas Oct 6, 2023
6923ae2
[Alerting] System action types and helpers (#167871)
cnasikas Oct 19, 2023
a291f7a
Merge branch 'main' into system_actions_mvp
cnasikas Oct 24, 2023
8dedac8
[Alerting] Enable creating system actions through the Create Rule API…
cnasikas Oct 26, 2023
861697c
Merge branch 'main' into system_actions_mvp
guskovaue Oct 26, 2023
645e45c
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
guskovaue Oct 26, 2023
a271f50
[Alerting] Enable updating system actions through the Bulk Edit Rule …
cnasikas Oct 27, 2023
bb0ad08
Merge branch 'main' into system_actions_mvp
guskovaue Oct 30, 2023
f7ecb3b
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
guskovaue Oct 30, 2023
62ba292
[RAM] System action in bulk disable api (#170229)
guskovaue Nov 6, 2023
c0b2feb
Merge branch 'main' into system_actions_mvp
guskovaue Nov 6, 2023
aadd675
[RAM] System action in bulk enable api (#170476)
guskovaue Nov 14, 2023
825bcc6
Merge branch 'main' into system_actions_mvp
guskovaue Nov 14, 2023
6105ee6
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
guskovaue Nov 14, 2023
d8a7569
[RAM] System action in bulk delete (#170741)
guskovaue Nov 14, 2023
f2f6f7d
[RAM] System actions update rule api (#171099)
guskovaue Nov 28, 2023
f8a1a73
Merge remote-tracking branch 'upstream/main' into system_actions_mvp
Zacqary Dec 7, 2023
21f0a78
[System Actions] Complete API audit and update APIs to comply with Sy…
Zacqary Jan 3, 2024
299142c
[RAM] Add example log system action type (#175057)
Zacqary Jan 30, 2024
72fa37e
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Jan 31, 2024
18f0b14
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Jan 31, 2024
e8a817e
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Jan 31, 2024
9777b7f
Merge branch 'main' into system_actions_mvp
kibanamachine Feb 1, 2024
00fdb26
fix multiple identifier
XavierM Feb 1, 2024
83bcec5
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Feb 1, 2024
b093407
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 1, 2024
80efe3f
First round of type fixes for triggers_actions_ui
Zacqary Feb 2, 2024
1077624
Merge branch 'system_actions_mvp' of https://github.com/elastic/kiban…
Zacqary Feb 2, 2024
c93530e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 2, 2024
3211810
fix some types
XavierM Feb 2, 2024
43e5601
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Feb 2, 2024
084c6c0
Fix test typechecks in triggers_actions_ui
Zacqary Feb 2, 2024
c6ea491
Fix hook linting issues
Zacqary Feb 2, 2024
942a32e
Merge branch 'system_actions_mvp' of https://github.com/elastic/kiban…
Zacqary Feb 2, 2024
9e125c0
Fix alerting plugin typecheck
Zacqary Feb 2, 2024
98f79c8
Fix linting
Zacqary Feb 5, 2024
b34fa44
Merge remote-tracking branch 'upstream/main' into system_actions_mvp
Zacqary Feb 5, 2024
f474d40
Fix create_rule bad merge
Zacqary Feb 5, 2024
87dd315
Fix jest snapshots
Zacqary Feb 5, 2024
62855f0
Fix Jest
Zacqary Feb 5, 2024
011bd79
fix more types
XavierM Feb 5, 2024
4508ad8
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Feb 5, 2024
e2f3ebc
rmv filterStateStore from alerting plugin to use @kbn/es-query
XavierM Feb 6, 2024
3342d89
Fix create_rule jest and others
Zacqary Feb 6, 2024
e2f2d4a
Fix snapshots
Zacqary Feb 6, 2024
e91c248
Merge branch 'system_actions_mvp' of https://github.com/elastic/kiban…
Zacqary Feb 6, 2024
a755eb3
fix more types
XavierM Feb 6, 2024
b4958aa
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Feb 6, 2024
88e40ab
last types issues
XavierM Feb 7, 2024
f68b6ab
Fix jest and snapshots
Zacqary Feb 7, 2024
3b54609
Fix lint
Zacqary Feb 7, 2024
45801a4
Fix snapshot
Zacqary Feb 8, 2024
eea8f33
Merge remote-tracking branch 'upstream/main' into system_actions_mvp
Zacqary Feb 8, 2024
7ebda8e
fix types in alerting plugin
XavierM Feb 9, 2024
0ec37f9
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Feb 9, 2024
7e5273c
Fix createRule schema validation errors
Zacqary Feb 9, 2024
2ac6f9a
Merge branch 'system_actions_mvp' of https://github.com/elastic/kiban…
Zacqary Feb 9, 2024
b9bbc02
Fix tests and action validation
Zacqary Feb 9, 2024
27d7de9
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Feb 13, 2024
438afbc
add systemActions attribute in alert plugins
XavierM Feb 23, 2024
b1c3105
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Feb 23, 2024
4c1201a
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 4, 2024
a85f319
fix triggers action UI types
XavierM Mar 11, 2024
3f931b0
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 11, 2024
9156355
fix create validation
XavierM Mar 11, 2024
a799f07
fix few broken code whoopsie
XavierM Mar 12, 2024
5c00493
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 12, 2024
529a237
not proud of this
XavierM Mar 12, 2024
68ade8e
part I fixing jest test
XavierM Mar 13, 2024
2c18746
Fix jest tests part 2
cnasikas Mar 13, 2024
8b7315b
Change paths for system connectors
cnasikas Mar 13, 2024
5cd185d
Add integration tests for actions routes
cnasikas Mar 13, 2024
9c624ef
Merge branch 'main' into system_actions_mvp
cnasikas Mar 15, 2024
589cd31
green jest test for alerting plugin
XavierM Mar 15, 2024
cfeb4bf
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Mar 15, 2024
4e8be7c
green jest test for trigers_action_ui plugin
XavierM Mar 15, 2024
efd576b
Merge branch 'main' into system_actions_mvp
XavierM Mar 16, 2024
c13c7c7
no changes in security solution plugin
XavierM Mar 18, 2024
7b8197b
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 18, 2024
43fe179
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Mar 18, 2024
88a4eac
remove systemAction from revision
XavierM Mar 18, 2024
6f2e655
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 18, 2024
b352633
fix few FTR
XavierM Mar 18, 2024
36cf4c5
fix legacy FTR
XavierM Mar 18, 2024
75ac3c7
Fix FTR legacy 2
XavierM Mar 19, 2024
1863c78
christos review
XavierM Mar 19, 2024
ab4289b
fix system action FTR
XavierM Mar 19, 2024
24ef9d7
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 19, 2024
2046bf2
few more FTR tests
XavierM Mar 19, 2024
71d6a9c
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Mar 19, 2024
4ceb9b5
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 19, 2024
3b418e9
left over of use_alert_data_for_template
XavierM Mar 19, 2024
3338150
fix type for isActionExecutable
XavierM Mar 19, 2024
9f9e90a
review + fix synthetic FTR
XavierM Mar 20, 2024
2e3306e
fix jest tests
XavierM Mar 20, 2024
3805a98
fix reducer
XavierM Mar 20, 2024
267e641
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 20, 2024
a6f5742
fix bad merge
XavierM Mar 20, 2024
97399f0
fix last jest test + security solution
XavierM Mar 21, 2024
6dcfb7b
Fix bulk_edit_rules unit test
cnasikas Mar 21, 2024
73a6e40
clean up execution handler
XavierM Mar 21, 2024
8455a28
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
XavierM Mar 21, 2024
c87b180
Add more tests
cnasikas Mar 21, 2024
73f2799
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
cnasikas Mar 21, 2024
6e0e27f
rmv unused components
XavierM Mar 21, 2024
e3a18f3
Merge branch 'main' of github.com:elastic/kibana into system_actions_mvp
XavierM Mar 21, 2024
0501088
Create seperate action form component for system actions
cnasikas Mar 22, 2024
e4328eb
Merge branch 'main' into system_actions_mvp
cnasikas Mar 22, 2024
ea73310
Delete unused test file
cnasikas Mar 22, 2024
2c8d9b9
Fix types
cnasikas Mar 22, 2024
30ac0a4
Rename component
cnasikas Mar 22, 2024
d035b71
Fix merge with main
cnasikas Mar 22, 2024
2ee86d0
Add tests for system action form
cnasikas Mar 22, 2024
ab0302c
Rename routes and improve tests
cnasikas Mar 22, 2024
56fa5d7
PR feedback v1
cnasikas Mar 23, 2024
8d401d2
PR feedback v2
cnasikas Mar 23, 2024
c958f5b
Throw an error if the group is not defined when creating an alert wit…
cnasikas Mar 23, 2024
71662af
Throw an error if the group is not defined when updating an alert wit…
cnasikas Mar 23, 2024
00982d1
Throw an error if the group is not defined when bulk editing an alert…
cnasikas Mar 23, 2024
88ad5eb
Merge branch 'main' into system_actions_mvp
cnasikas Mar 26, 2024
8c90074
Add more unit tests
cnasikas Mar 26, 2024
69e2965
Merge branch 'main' into system_actions_mvp
cnasikas Mar 27, 2024
5e84c05
Add tests for rule clients methods
cnasikas Mar 27, 2024
ec8536a
Add integration tests
cnasikas Mar 28, 2024
38123e9
Merge branch 'main' into system_actions_mvp
cnasikas Mar 28, 2024
f2f9827
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Mar 28, 2024
3685ebc
Fix type error
cnasikas Mar 28, 2024
a2b0cc0
Do not allow the execution of system actions through the execute API
cnasikas Mar 28, 2024
eea2743
Merge branch 'system_actions_mvp' of github.com:elastic/kibana into s…
cnasikas Mar 28, 2024
6c1317b
Throw an error if a system action is used twice
cnasikas Mar 28, 2024
57559e6
Remove rules after the end of tests
cnasikas Mar 28, 2024
91eb80c
Fix integration tests
cnasikas Mar 29, 2024
d1ba533
Merge branch 'main' into system_actions_mvp
cnasikas Mar 29, 2024
c38cebc
Disable system action type if already selected
cnasikas Mar 29, 2024
e59c542
Fix type errors in integration tests
cnasikas Mar 29, 2024
c5c06e9
Type connector adapter params
cnasikas Mar 30, 2024
eb96022
Merge branch 'main' into system_actions_mvp
kibanamachine Apr 1, 2024
763e05f
PR feedback
cnasikas Apr 1, 2024
2cf8246
Merge branch 'main' into system_actions_mvp
cnasikas Apr 2, 2024
bcc2397
PR feedback 2
cnasikas Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions x-pack/examples/triggers_actions_ui_example/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"owner": "@elastic/response-ops",
"plugin": {
"id": "triggersActionsUiExample",
"server": false,
"server": true,
"browser": true,
"requiredPlugins": [
"triggersActionsUi",
"data",
"alerting",
"developerExamples",
"kibanaReact",
"cases"
],
"optionalPlugins": [
"spaces"
"cases",
"actions"
],
"optionalPlugins": ["spaces"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 { lazy } from 'react';
import { i18n } from '@kbn/i18n';
import type {
ActionTypeModel as ConnectorTypeModel,
GenericValidationResult,
} from '@kbn/triggers-actions-ui-plugin/public/types';
import { SystemLogActionParams } from '../types';

export function getConnectorType(): ConnectorTypeModel<unknown, unknown, SystemLogActionParams> {
return {
id: '.system-log-example',
iconClass: 'logsApp',
selectMessage: i18n.translate(
'xpack.stackConnectors.components.systemLogExample.selectMessageText',
{
defaultMessage: 'Example of a system action that sends logs to the Kibana server',
}
),
actionTypeTitle: i18n.translate(
'xpack.stackConnectors.components.serverLog.connectorTypeTitle',
{
defaultMessage: 'Send to System log - Example',
}
),
validateParams: (
actionParams: SystemLogActionParams
): Promise<GenericValidationResult<Pick<SystemLogActionParams, 'message'>>> => {
const errors = {
message: new Array<string>(),
};
const validationResult = { errors };
if (!actionParams.message?.length) {
errors.message.push(
i18n.translate(
'xpack.stackConnectors.components.serverLog.error.requiredServerLogMessageText',
{
defaultMessage: 'Message is required.',
}
)
);
}
return Promise.resolve(validationResult);
},
actionConnectorFields: null,
actionParamsFields: lazy(() => import('./system_log_example_params')),
isSystemActionType: true,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 React, { useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import type { ActionParamsProps } from '@kbn/triggers-actions-ui-plugin/public';
import { TextAreaWithMessageVariables } from '@kbn/triggers-actions-ui-plugin/public';
import { SystemLogActionParams } from '../types';

export const ServerLogParamsFields: React.FunctionComponent<
ActionParamsProps<SystemLogActionParams>
> = ({
actionParams,
editAction,
index,
errors,
messageVariables,
defaultMessage,
useDefaultMessage,
}) => {
const { message } = actionParams;

const [[isUsingDefault, defaultMessageUsed], setDefaultMessageUsage] = useState<
[boolean, string | undefined]
>([false, defaultMessage]);
// This params component is derived primarily from server_log_params.tsx, see that file and its
// corresponding unit tests for details on functionality
useEffect(() => {
if (
useDefaultMessage ||
!actionParams?.message ||
(isUsingDefault &&
actionParams?.message === defaultMessageUsed &&
defaultMessageUsed !== defaultMessage)
) {
setDefaultMessageUsage([true, defaultMessage]);
editAction('message', defaultMessage, index);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultMessage]);

return (
<TextAreaWithMessageVariables
index={index}
editAction={editAction}
messageVariables={messageVariables}
paramsProperty={'message'}
inputTargetValue={message}
label={i18n.translate(
'xpack.stackConnectors.components.systemLogExample.logMessageFieldLabel',
{
defaultMessage: 'Message',
}
)}
errors={errors.message as string[]}
/>
);
};

// eslint-disable-next-line import/no-default-export
export { ServerLogParamsFields as default };
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* 2.0.
*/

export const filterStateStore = {
APP_STATE: 'appState',
GLOBAL_STATE: 'globalState',
} as const;

export type FilterStateStore = typeof filterStateStore[keyof typeof filterStateStore];
export interface SystemLogActionParams {
message: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@kbn/triggers-actions-ui-plugin/public/types';
import { SortCombinations } from '@elastic/elasticsearch/lib/api/types';
import { EuiDataGridColumn } from '@elastic/eui';
import { getConnectorType as getSystemLogExampleConnectorType } from './connector_types/system_log_example/system_log_example';

export interface TriggersActionsUiExamplePublicSetupDeps {
alerting: AlertingSetup;
Expand Down Expand Up @@ -145,6 +146,8 @@ export class TriggersActionsUiExamplePlugin
};

alertsTableConfigurationRegistry.register(config);

triggersActionsUi.actionTypeRegistry.register(getSystemLogExampleConnectorType());
}

public stop() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { schema, TypeOf } from '@kbn/config-schema';

import { LogMeta } from '@kbn/core/server';
import type {
ActionType as ConnectorType,
ActionTypeExecutorOptions as ConnectorTypeExecutorOptions,
ActionTypeExecutorResult as ConnectorTypeExecutorResult,
} from '@kbn/actions-plugin/server/types';
import {
AlertingConnectorFeatureId,
UptimeConnectorFeatureId,
} from '@kbn/actions-plugin/common/connector_feature_config';
import { ConnectorAdapter } from '@kbn/alerting-plugin/server';

// see: https://en.wikipedia.org/wiki/Unicode_control_characters
// but don't include tabs (0x09), they're fine
const CONTROL_CHAR_PATTERN = /[\x00-\x08]|[\x0A-\x1F]|[\x7F-\x9F]|[\u2028-\u2029]/g;

// replaces control characters in string with ;, but leaves tabs
function withoutControlCharacters(s: string): string {
return s.replace(CONTROL_CHAR_PATTERN, ';');
}

export type ServerLogConnectorType = ConnectorType<{}, {}, ActionParamsType>;
export type ServerLogConnectorTypeExecutorOptions = ConnectorTypeExecutorOptions<
{},
{},
ActionParamsType
>;

// params definition

export type ActionParamsType = TypeOf<typeof ParamsSchema>;

const ParamsSchema = schema.object({
message: schema.string(),
});

export const ConnectorTypeId = '.system-log-example';
// connector type definition
export function getConnectorType(): ServerLogConnectorType {
return {
id: ConnectorTypeId,
isSystemActionType: true,
minimumLicenseRequired: 'gold', // Third party action types require at least gold
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this is just an example, but is this intentionally set to gold? it's not a 3rd party action.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When registering the action type the ensureSufficientLicense in x-pack/plugins/actions/server/lib/ensure_sufficient_license.ts will be thrown an error because only the .server-log and the .index are allowed to be on the basic license. What about leaving it as it is from now on and checking with @shanisagiv1 the minimum required license for system actions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

name: i18n.translate('xpack.stackConnectors.systemLogExample.title', {
defaultMessage: 'System log - example',
}),
supportedFeatureIds: [AlertingConnectorFeatureId, UptimeConnectorFeatureId],
validate: {
config: { schema: schema.object({}, { defaultValue: {} }) },
secrets: { schema: schema.object({}, { defaultValue: {} }) },
params: {
schema: ParamsSchema,
},
},
executor,
};
}

export const connectorAdapter: ConnectorAdapter = {
connectorTypeId: ConnectorTypeId,
ruleActionParamsSchema: ParamsSchema,
buildActionParams: ({ alerts, rule, params, spaceId, ruleUrl }) => {
return { ...params };
},
};

// action executor

async function executor(
execOptions: ServerLogConnectorTypeExecutorOptions
): Promise<ConnectorTypeExecutorResult<void>> {
const { actionId, params, logger } = execOptions;
const sanitizedMessage = withoutControlCharacters(params.message);
try {
logger.info<LogMeta>(`SYSTEM ACTION EXAMPLE Server log: ${sanitizedMessage}`);
} catch (err) {
const message = i18n.translate('xpack.stackConnectors.serverLog.errorLoggingErrorMessage', {
defaultMessage: 'error logging message',
});
return {
status: 'error',
message,
serviceMessage: err.message,
actionId,
};
}

return { status: 'ok', actionId };
}
13 changes: 13 additions & 0 deletions x-pack/examples/triggers_actions_ui_example/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { PluginInitializer } from '@kbn/core/server';

export const plugin: PluginInitializer<void, void> = async () => {
const { TriggersActionsUiExamplePlugin } = await import('./plugin');
return new TriggersActionsUiExamplePlugin();
};
33 changes: 33 additions & 0 deletions x-pack/examples/triggers_actions_ui_example/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { Plugin, CoreSetup } from '@kbn/core/server';

import { PluginSetupContract as ActionsSetup } from '@kbn/actions-plugin/server';
import { PluginSetupContract as AlertingSetup } from '@kbn/alerting-plugin/server';

import {
getConnectorType as getSystemLogExampleConnectorType,
connectorAdapter as systemLogConnectorAdapter,
} from './connector_types/system_log_example';

// this plugin's dependencies
export interface TriggersActionsUiExampleDeps {
alerting: AlertingSetup;
actions: ActionsSetup;
}
export class TriggersActionsUiExamplePlugin
implements Plugin<void, void, TriggersActionsUiExampleDeps>
{
public setup(core: CoreSetup, { actions, alerting }: TriggersActionsUiExampleDeps) {
actions.registerType(getSystemLogExampleConnectorType());
alerting.registerConnectorAdapter(systemLogConnectorAdapter);
}

public start() {}
public stop() {}
}
3 changes: 3 additions & 0 deletions x-pack/examples/triggers_actions_ui_example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"@kbn/data-plugin",
"@kbn/i18n-react",
"@kbn/shared-ux-router",
"@kbn/i18n",
"@kbn/actions-plugin",
"@kbn/config-schema",
]
}
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ describe('actionTypeRegistry', () => {
expect(actionTypeRegistry.isActionExecutable('my-slack1', 'foo')).toEqual(true);
});

test('should return false when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
test('should return true when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(false);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });

Expand All @@ -504,7 +504,7 @@ describe('actionTypeRegistry', () => {
'system-connector-test.system-action',
'system-action-type'
)
).toEqual(false);
).toEqual(true);
});

test('should call isLicenseValidForActionType of the license state with notifyUsage false by default', async () => {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export class ActionTypeRegistry {
(connector) => connector.id === actionId
);

return actionTypeEnabled || (!actionTypeEnabled && inMemoryConnector?.isPreconfigured === true);
return (
actionTypeEnabled ||
(!actionTypeEnabled &&
(inMemoryConnector?.isPreconfigured === true || inMemoryConnector?.isSystemAction === true))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const createActionsClientMock = () => {
delete: jest.fn(),
update: jest.fn(),
getAll: jest.fn(),
getAllSystemConnectors: jest.fn(),
getBulk: jest.fn(),
getOAuthAccessToken: jest.fn(),
execute: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ describe('execute()', () => {
});

expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
actionTypeId: 'my-action-type',
actionTypeId: '.cases',
operation: 'execute',
additionalPrivileges: ['test/create'],
});
Expand Down Expand Up @@ -2930,7 +2930,7 @@ describe('execute()', () => {
});

expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
actionTypeId: 'my-action-type',
actionTypeId: '.cases',
operation: 'execute',
additionalPrivileges: ['test/create'],
});
Expand Down
Loading