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

[alerting] add mustache variable for Kibana's publicly exposed base URL #90525

Merged
merged 1 commit into from
Feb 16, 2021

Conversation

pmuellr
Copy link
Member

@pmuellr pmuellr commented Feb 5, 2021

resolves #49392

Adds the top-level mustache variable kibanaBaseUrl for action parameter
mustache templates. The value comes from Kibana config, which, if not set
will result in this variable having the value undefined.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@pmuellr pmuellr requested a review from a team as a code owner February 5, 2021 22:19
@pmuellr pmuellr closed this Feb 5, 2021
@pmuellr pmuellr reopened this Feb 5, 2021
@pmuellr pmuellr marked this pull request as draft February 5, 2021 22:20
@pmuellr
Copy link
Member Author

pmuellr commented Feb 5, 2021

POC at the moment, just wanted to make sure we could do this.

Here's the contents of the message param for Slack - the last three lines are added from the default, and make use of the new variable. The wrapping in {{#...}}...{{/...}} are so that the "View in" line will only be rendered if kibanaBaseUrl is an actual string value. It could be undefined, if this url has not been specifically configured in the kibana.yml file.

alert '{{alertName}}' is active for group '{{context.group}}':

- Value: {{context.value}}
- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}
- Timestamp: {{context.date}}

{{#kibanaBaseUrl}}
View in <{{kibanaBaseUrl}}/app/management/insightsAndAlerting/triggersActions/alert/{{alertId}}|Kibana>
{{/kibanaBaseUrl}}

Here's how it renders in Slack - and it works!

image

@pmuellr
Copy link
Member Author

pmuellr commented Feb 9, 2021

Additional note that being able to display "nice" links in Slack and email can't be done with a single message that would work in both. For email, you'd need to use [link text here]({{kibanaBaseUrl}}/...) and slack <{{kibanaBaseUrl}}/...|link text here>.

So there's no way I know of to create a nice link like this with the defaultActionMessage capability. We'll need to wait for this issue, which will provide a way to generate default messages given different formats, action groups, etc - #66095

Until that issue is resolved, alert implementors should probably just reference the url by itself if used in a defaultActionMessage, like so:

default message here.  view in Kibana: {{kibanaBaseUrl}}/...

Both email and slack will render these as links, but the text will be the complete URL.

@pmuellr pmuellr force-pushed the alerting/kibana-url-action-variable branch 2 times, most recently from 2fd6f27 to 40d5cdf Compare February 15, 2021 23:36
resolves elastic#49392

Adds the top-level mustache variable `kibanaBaseUrl` for action parameter
mustache templates.  The value comes from Kibana config, which, if not set
will result in this variable having the value `undefined`.
@pmuellr pmuellr force-pushed the alerting/kibana-url-action-variable branch from 40d5cdf to f21c638 Compare February 15, 2021 23:37
@pmuellr
Copy link
Member Author

pmuellr commented Feb 16, 2021

jenkins retest this please

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
triggersActionsUi 1.4MB 1.4MB +1.0KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pmuellr pmuellr added Feature:Alerting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.12 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes needs_docs labels Feb 16, 2021
@pmuellr pmuellr marked this pull request as ready for review February 16, 2021 12:25
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

@@ -161,6 +161,7 @@ export class AlertingPlugin {
private eventLogService?: IEventLogService;
private eventLogger?: IEventLogger;
private readonly kibanaIndexConfig: Observable<{ kibana: { index: string } }>;
private kibanaBaseUrl: string | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

new instance variable so we can capture the path in setup and use it in start

@@ -39,6 +39,7 @@ export interface CreateExecutionHandlerOptions<
actions: AlertAction[];
spaceId: string;
apiKey: RawAlert['apiKey'];
kibanaBaseUrl: string | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

there were a couple of paths of threading this new variable into the right place, this required the fewest number of changes

@@ -44,10 +44,18 @@ describe('transformActionVariables', () => {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
},
Object {
Copy link
Member Author

Choose a reason for hiding this comment

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

I double-checked the variables we're making available, alertActionSubgroup should have been here, but was not, so added it.

@@ -97,7 +98,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
...xPackApiIntegrationTestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'),
'--server.publicBaseUrl=https://localhost:5601',
...(options.publicBaseUrl ? ['--server.publicBaseUrl=https://localhost:5601'] : []),
Copy link
Member Author

Choose a reason for hiding this comment

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

changed so security_and_spaces runs WITH the configured url, but spaces_only does not

@@ -0,0 +1,125 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a copy of the spaces_only tests, but only included a test for the new action variable, since it's now different between the two

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

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

LGTM

@pmuellr pmuellr merged commit 20e16bd into elastic:master Feb 16, 2021
@pmuellr pmuellr removed the v7.12 label Feb 16, 2021
pmuellr added a commit to pmuellr/kibana that referenced this pull request Feb 16, 2021
…exposed base URL (elastic#90525)

resolves elastic#49392

Adds the top-level mustache variable `kibanaBaseUrl` for action parameter
mustache templates.  The value comes from Kibana config, which, if not set
will result in this variable having the value `undefined` which will be rendered
as an empty string.
pmuellr added a commit that referenced this pull request Feb 16, 2021
…exposed base URL (#90525) (#91563)

resolves #49392

Adds the top-level mustache variable `kibanaBaseUrl` for action parameter
mustache templates.  The value comes from Kibana config, which, if not set
will result in this variable having the value `undefined` which will be rendered
as an empty string.
@pmuellr pmuellr removed the needs_docs label Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to generate URLs in alert action parameters
5 participants