Skip to content

Commit

Permalink
Merge branch 'main' into implement/generate-package-build-file
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Mar 10, 2022
2 parents 74268ab + 62f8e58 commit 3e8f9bf
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipelines/flaky_tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ steps.push({
label: 'Build Kibana Distribution and Plugins',
agents: { queue: 'c2-8' },
key: 'build',
if: "build.env('BUILD_ID_FOR_ARTIFACTS') == null || build.env('BUILD_ID_FOR_ARTIFACTS') == ''",
if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''",
});

for (const testSuite of testSuites) {
Expand Down
56 changes: 56 additions & 0 deletions docs/management/cases/add-connectors.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[[add-case-connectors]]
== Add connectors

preview::[]

You can add connectors to cases to push information to these external incident
management systems:

* IBM Resilient
* Jira
* ServiceNow ITSM
* ServiceNow SecOps
* {swimlane}

NOTE: To create connectors and send cases to external systems, you must have the
appropriate {kib} feature privileges. Refer to <<setup-cases>>.

[discrete]
[[create-case-connectors]]
== Create connectors

You can create connectors in *Management > {stack-manage-app} > {rules-ui}*, as
described in <<action-types>>. Alternatively, you can create them in
*Management > {stack-manage-app} > Cases*:

. Click *Edit external connection*.
+
[role="screenshot"]
image::images/cases-connectors.png[]

. From the *Incident management system* list, select *Add new connector*.

. Select an external incident management system.

. Enter your required settings. Refer to <<resilient-action-type>>,
<<jira-action-type>>, <<servicenow-action-type>>, <<servicenow-sir-action-type>>,
or <<swimlane-action-type>> for connector configuration details.

. Click *Save*.

[discrete]
[[edit-case-connector-settings]]
== Edit connector settings

You can create additional connectors, update existing connectors, change
the default connector, and change case closure options.

. Go to *Management > {stack-manage-app} > Cases*, click *Edit external connection*.

. To change whether cases are automatically closed after they are sent to an
external system, update the case closure options.

. To change the default connector for new cases, select the connector from the
*Incident management system* list.

. To update a connector, click *Update <connector name>* and edit the connector fields as required.
6 changes: 4 additions & 2 deletions docs/management/cases/cases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ preview::[]

Cases are used to open and track issues directly in {kib}. All cases list
the original reporter and all the users who contribute to a case (_participants_).
You can also send cases to third party systems by configuring external connectors.
You can also send cases to external incident management systems by configuring
connectors.

[role="screenshot"]
image::images/cases.png[Cases page]
Expand All @@ -17,4 +18,5 @@ You also cannot attach alerts from the {observability} or {security-app} to
cases in *{stack-manage-app}*.

* <<setup-cases>>
* <<manage-cases>>
* <<manage-cases>>
* <<add-case-connectors>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/management/cases/index.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include::cases.asciidoc[]
include::setup-cases.asciidoc[leveloffset=+1]
include::manage-cases.asciidoc[leveloffset=+1]
//=== Configure external connectors
include::add-connectors.asciidoc[leveloffset=+1]
5 changes: 2 additions & 3 deletions docs/management/cases/manage-cases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ TIP: In the `Description` area, you can use
https://www.markdownguide.org/cheat-sheet[Markdown] syntax to create formatted
text.

. For *External incident management system*, select a connector. If you've
previously added one, that connector displays as the default selection.
Otherwise, the default setting is `No connector selected`.
. For *External incident management system*, select a connector. For more
information, refer to <<add-case-connectors>>.

. After you've completed all of the required fields, click *Create case*.

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,9 @@
},
"description": {
"type": "string"
},
"force": {
"type": "boolean"
}
},
"required": [
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,8 @@ components:
type: string
description:
type: string
force:
type: boolean
required:
- name
- namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ properties:
type: string
description:
type: string
force:
type: boolean
required:
- name
- namespace
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/routes/package_policy/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const updatePackagePolicyHandler: RequestHandler<
throw Boom.notFound('Package policy not found');
}

const body = { ...request.body };
const { force, ...body } = request.body;
// removed fields not recognized by schema
const packagePolicyInputs = packagePolicy.inputs.map((input) => {
const newInput = {
Expand Down Expand Up @@ -180,7 +180,7 @@ export const updatePackagePolicyHandler: RequestHandler<
esClient,
request.params.packagePolicyId,
newData,
{ user },
{ user, force },
packagePolicy.package?.version
);
return response.ok({
Expand Down
135 changes: 128 additions & 7 deletions x-pack/plugins/fleet/server/services/package_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ describe('Package policy service', () => {
).rejects.toThrow('Saved object [abc/123] conflict');
});

it('should only update input vars that are not frozen', async () => {
it('should throw if the user try to update input vars that are frozen', async () => {
const savedObjectsClient = savedObjectsClientMock.create();
const mockPackagePolicy = createPackagePolicyMock();
const mockInputs = [
Expand Down Expand Up @@ -743,22 +743,143 @@ describe('Package policy service', () => {
);
const elasticsearchClient = elasticsearchServiceMock.createClusterClient().asInternalUser;

const result = await packagePolicyService.update(
const res = packagePolicyService.update(
savedObjectsClient,
elasticsearchClient,
'the-package-policy-id',
{ ...mockPackagePolicy, inputs: inputsUpdate }
);

await expect(res).rejects.toThrow('cat is a frozen variable and cannot be modified');
});

it('should allow to update input vars that are frozen with the force flag', async () => {
const savedObjectsClient = savedObjectsClientMock.create();
const mockPackagePolicy = createPackagePolicyMock();
const mockInputs = [
{
config: {},
enabled: true,
keep_enabled: true,
type: 'endpoint',
vars: {
dog: {
type: 'text',
value: 'dalmatian',
},
cat: {
type: 'text',
value: 'siamese',
frozen: true,
},
},
streams: [
{
data_stream: {
type: 'birds',
dataset: 'migratory.patterns',
},
enabled: false,
id: `endpoint-migratory.patterns-${mockPackagePolicy.id}`,
vars: {
paths: {
value: ['north', 'south'],
type: 'text',
frozen: true,
},
period: {
value: '6mo',
type: 'text',
},
},
},
],
},
];
const inputsUpdate = [
{
config: {},
enabled: false,
type: 'endpoint',
vars: {
dog: {
type: 'text',
value: 'labrador',
},
cat: {
type: 'text',
value: 'tabby',
},
},
streams: [
{
data_stream: {
type: 'birds',
dataset: 'migratory.patterns',
},
enabled: false,
id: `endpoint-migratory.patterns-${mockPackagePolicy.id}`,
vars: {
paths: {
value: ['east', 'west'],
type: 'text',
},
period: {
value: '12mo',
type: 'text',
},
},
},
],
},
];
const attributes = {
...mockPackagePolicy,
inputs: mockInputs,
};

savedObjectsClient.get.mockResolvedValue({
id: 'test',
type: 'abcd',
references: [],
version: 'test',
attributes,
});

savedObjectsClient.update.mockImplementation(
async (
type: string,
id: string,
attrs: any
): Promise<SavedObjectsUpdateResponse<PackagePolicySOAttributes>> => {
savedObjectsClient.get.mockResolvedValue({
id: 'test',
type: 'abcd',
references: [],
version: 'test',
attributes: attrs,
});
return attrs;
}
);
const elasticsearchClient = elasticsearchServiceMock.createClusterClient().asInternalUser;

const result = await packagePolicyService.update(
savedObjectsClient,
elasticsearchClient,
'the-package-policy-id',
{ ...mockPackagePolicy, inputs: inputsUpdate },
{ force: true }
);

const [modifiedInput] = result.inputs;
expect(modifiedInput.enabled).toEqual(true);
expect(modifiedInput.vars!.dog.value).toEqual('labrador');
expect(modifiedInput.vars!.cat.value).toEqual('siamese');
expect(modifiedInput.vars!.cat.value).toEqual('tabby');
const [modifiedStream] = modifiedInput.streams;
expect(modifiedStream.vars!.paths.value).toEqual(expect.arrayContaining(['north', 'south']));
expect(modifiedStream.vars!.paths.value).toEqual(expect.arrayContaining(['east', 'west']));
expect(modifiedStream.vars!.period.value).toEqual('12mo');
});

it('should add new input vars when updating', async () => {
const savedObjectsClient = savedObjectsClientMock.create();
const mockPackagePolicy = createPackagePolicyMock();
Expand Down Expand Up @@ -810,7 +931,7 @@ describe('Package policy service', () => {
},
cat: {
type: 'text',
value: 'tabby',
value: 'siamese',
},
},
streams: [
Expand All @@ -823,7 +944,7 @@ describe('Package policy service', () => {
id: `endpoint-migratory.patterns-${mockPackagePolicy.id}`,
vars: {
paths: {
value: ['east', 'west'],
value: ['north', 'south'],
type: 'text',
},
period: {
Expand Down
Loading

0 comments on commit 3e8f9bf

Please sign in to comment.