From c3fe92f4ef4943aca8243da99a76c8a72c49c5aa Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 3 Sep 2024 10:26:07 +0545 Subject: [PATCH] docs: use gomplate style for notification template functions --- .../notifications/template_functions.mdx | 286 +++++++++++++----- 1 file changed, 202 insertions(+), 84 deletions(-) diff --git a/mission-control/docs/reference/notifications/template_functions.mdx b/mission-control/docs/reference/notifications/template_functions.mdx index e867a7d..203ef2b 100644 --- a/mission-control/docs/reference/notifications/template_functions.mdx +++ b/mission-control/docs/reference/notifications/template_functions.mdx @@ -2,100 +2,218 @@ title: Template Functions --- -Special Slack template functions are made available on notifications to complex block formation easier. +Special template functions are made available on notifications to complex block formation easier. -**slackHealthEmoji:** - +## labelsFormat +Formats the given set of labels into a markdown string -**labelsFormat:** - +Syntax: -**slackSectionLabels:** - +```js +labelsFormat(map[string]any): string +``` -**slackSectionTextFieldPlain:** - +Example: -**slackSectionTextFieldMD:** - +```js +labelsFormat(map[string]any{ + "namespace": "default", + "cluster": "staging", +}) +``` -**slackSectionTextMD:** - +```md +### Labels -**slackSectionTextPlain:** - +**namespace**: default +**cluster**: staging +``` -**SlackURLAction:** - +## Slack -export function SlackHealthEmoji() { - return <> -
-			slackHealthEmoji(health): string
-		
-

Returns a slack emoji based on the supplied health

- +These slack helper functions will return a json string suitable for use in slack blocks/messages. + +### slackHealthEmoji +Returns a slack emoji based on the supplied health + +Syntax: + +```js +slackHealthEmoji(health): string +``` + +**Returns:** + +- `:large_green_circle:` for `healthy` health status +- `:red_circle:` for `unhealthy` health status +- `:large_orange_circle:` for `warning` health status +- `:white_circle:` for any other health status + +### slackSectionLabels + +Formats the given set of labels into fields of a slack section block + +Syntax: + +```js +slackSectionLabels(map[string]any): SlackSection +``` + +Example: + +```js +slackSectionLabels(map[string]any{ + "namespace": "default", + "cluster": "staging", +}) +``` + +```json +{ + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Labels*" + }, + "fields": [ + { + "type": "mrkdwn", + "text": "*namespace*: default", + "verbatim": true + }, + { + "type": "mrkdwn", + "text": "*cluster*: staging", + "verbatim": true + } + ] } +``` + +### slackSectionTextFieldPlain + +Creates a plain text field for a Slack section block + +Syntax: -export function LabelsFormat() { - return <> -
-			labelsFormat(map[string]any): string
-		
-

Formats the given set of labels

- +```js +slackSectionTextFieldPlain(text: string): string +``` + +Example: + +```js +slackSectionTextFieldPlain("alert-manager") +``` + +```json +{ + "type": "plain_text", + "text": "alert-manager" } +``` + +### slackSectionTextFieldMD +Creates a markdown text field for a Slack section block + +Syntax: -export const SlackSectionLabels = () => ( - <> -
-			slackSectionLabels(map[string]any): SlackSection
-		
-

Formats the given set of labels into fields of a slack section block

- -) - -export const SlackSectionTextFieldPlain = () => ( - <> -
-			slackSectionTextFieldPlain(text: string): string
-		
-

Creates a plain text field for a Slack section block

- -) - -export const SlackSectionTextFieldMD = () => ( - <> -
-			slackSectionTextFieldMD(text: string): string
-		
-

Creates a markdown text field for a Slack section block

- -) - -export const SlackSectionTextMD = () => ( - <> -
-			slackSectionTextMD(text: string): string
-		
-

Creates a Slack section block with markdown text

- -) - -export const SlackSectionTextPlain = () => ( - <> -
-			slackSectionTextPlain(text: string): string
-		
-

Creates a Slack section block with plain text

- -) - -export const SlackURLAction = () => ( - <> -
-			slackURLAction(name: string, url: string): string
-		
-

Creates a Slack action block with a URL button

- -) +```js +slackSectionTextFieldMD(text: string): string +``` + +Example: + +```js +slackSectionTextFieldPlain("alert-manager") +``` + +```json +{ + "type": "mrkdwn", + "text": "alert-manager" +} +``` + +### slackSectionTextMD +Creates a Slack section block with markdown text + +Syntax: + +```js +slackSectionTextMD(text: string): string +``` + +Example: + +```js +slackSectionTextMD("alert-manager") +``` + +```json +{ + "type": "section", + "text": { + "type": "mrkdwn", + "text": "alert-manager" + } +} +``` + +### slackSectionTextPlain +Creates a Slack section block with plain text + +Syntax: + +```js +slackSectionTextPlain(text: string): string +``` + +Example: + +```js +slackSectionTextMD("alert-manager") +``` + +```json +{ + "type": "section", + "text": { + "type": "plain_text", + "text": "alert-manager" + } +} +``` + +### SlackURLAction +Creates a Slack action block with a URL button + +Syntax: + +```js +slackURLAction(name: string, url: string): string +``` + +Example: + +```js +slackURLAction("Grafana", "https://grafana.com") +``` + +```json +{ + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Grafana", + "emoji": true + }, + "url": "https://grafana.com", + "action_id": "Grafana" + } + ] +} +``` \ No newline at end of file