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

Adds index action as built-in action #41592

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions x-pack/legacy/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Kibana ships with a set of built-in action types:
- server log: logs messages to the Kibana log using `server.log()`
- email: send an email
- slack: post a message to a slack channel
- index: index document(s) into elasticsearch

## server log, action id: `.log`

Expand Down Expand Up @@ -247,6 +248,27 @@ This action type interfaces with the [Slack Incoming Webhooks feature](https://a
|---|---|---|
|message|the message text|string|


## index, action id: `.index`

The config and params properties are modelled after the [Watcher Index Action](https://www.elastic.co/guide/en/elastic-stack-overview/master/actions-index.html). The index can be set in the config or params, and if set in config, then the index set in the params will be ignored.

#### config properties

|Property|Description|Type|
|---|---|---|
|index|The Elasticsearch index to index into.|string _(optional)_|

#### params properties

|Property|Description|Type|
|---|---|---|
|index|The Elasticsearch index to index into.|string _(optional)_|
|doc_id|The optional _id of the document.|string _(optional)_|
|execution_time_field|The field that will store/index the action execution time.|string _(optional)_|
pmuellr marked this conversation as resolved.
Show resolved Hide resolved
|refresh|Setting of the refresh policy for the write request|boolean _(optional)_|
|body|The documument body/bodies to index.|object or object[]|

# Command Line Utility

The [`kbn-action`](https://github.com/pmuellr/kbn-action) tool can be used to send HTTP requests to the Actions plugin. For instance, to create a Slack action from the `.slack` Action Type, use the following command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ describe('execute()', () => {
message: 'a message to you',
};

const executorOptions: ActionTypeExecutorOptions = { config, params, services };
const id = 'some-id';
const executorOptions: ActionTypeExecutorOptions = { id, config, params, services };
sendEmailMock.mockReset();
await actionType.executor(executorOptions);
expect(sendEmailMock.mock.calls[0][1]).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { schema, TypeOf, Type } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';
import nodemailerServices from 'nodemailer/lib/well-known/services.json';

import { sendEmail, JSON_TRANSPORT_SERVICE } from './lib/send_email';
import { nullableType } from './lib/nullable';
import { ActionType, ActionTypeExecutorOptions, ActionTypeExecutorResult } from '../types';

const PORT_MAX = 256 * 256 - 1;

function nullableType<V>(type: Type<V>) {
return schema.oneOf([type, schema.literal(null)], { defaultValue: () => null });
}

// config definition

const unencryptedConfigProperties = ['service', 'host', 'port', 'secure', 'from'];
Expand Down Expand Up @@ -108,6 +105,7 @@ export const actionType: ActionType = {
// action executor

async function executor(execOptions: ActionTypeExecutorOptions): Promise<ActionTypeExecutorResult> {
const id = execOptions.id;
const config = execOptions.config as ActionTypeConfigType;
const params = execOptions.params as ActionParamsType;
const services = execOptions.services;
Expand Down Expand Up @@ -146,7 +144,7 @@ async function executor(execOptions: ActionTypeExecutorOptions): Promise<ActionT
} catch (err) {
return {
status: 'error',
message: `error sending email: ${err.message}`,
message: `error in action ${id} sending email: ${err.message}`,
};
}

Expand Down
Loading