Skip to content

Commit

Permalink
feat(notifications/teams): add UI to manage teams endpoints and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sranka committed Jul 25, 2020
1 parent 9228c3e commit 3c1f2c0
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 3 deletions.
1 change: 1 addition & 0 deletions ui/src/alerting/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const DEFAULT_ENDPOINT_URLS = {
slack: 'https://hooks.slack.com/services/X/X/X',
pagerduty: 'https://events.pagerduty.com/v2/enqueue',
http: 'https://www.example.com/endpoint',
teams: 'https://office.outlook.com/hook/XXXX',
}

export const NEW_ENDPOINT_DRAFT: NotificationEndpoint = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const EmptyEndpointList: FC<{searchTerm: string}> = ({searchTerm}) => {
<EmptyState.Text>
Want to send notifications to Slack,
<br />
PagerDuty, Telegram or an HTTP server?
PagerDuty, Telegram, Teams or an HTTP server?
<br />
<br />
Try creating a <b>Notification Endpoint</b>
Expand Down
13 changes: 13 additions & 0 deletions ui/src/notifications/endpoints/components/EndpointOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EndpointOptionsSlack from './EndpointOptionsSlack'
import EndpointOptionsPagerDuty from './EndpointOptionsPagerDuty'
import EndpointOptionsHTTP from './EndpointOptionsHTTP'
import EndpointOptionsTelegram from './EndpointOptionsTelegram'
import EndpointOptionsTeams from './EndpointOptionsTeams'

// Types
import {
Expand All @@ -14,6 +15,7 @@ import {
PagerDutyNotificationEndpoint,
HTTPNotificationEndpoint,
TelegramNotificationEndpoint,
TeamsNotificationEndpoint,
} from 'src/types'

interface Props {
Expand Down Expand Up @@ -77,6 +79,17 @@ const EndpointOptions: FC<Props> = ({
)
}

case 'teams': {
const {url, secretURLSuffix} = endpoint as TeamsNotificationEndpoint
return (
<EndpointOptionsTeams
url={url}
secretURLSuffix={secretURLSuffix}
onChange={onChange}
/>
)
}

default:
throw new Error(
`Unknown endpoint type for endpoint: ${JSON.stringify(
Expand Down
57 changes: 57 additions & 0 deletions ui/src/notifications/endpoints/components/EndpointOptionsTeams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Libraries
import React, {FC, ChangeEvent} from 'react'

// Components
import {
Input,
FormElement,
Panel,
Grid,
Columns,
InputType,
} from '@influxdata/clockface'

interface Props {
url: string
secretURLSuffix: string
onChange: (e: ChangeEvent<HTMLInputElement>) => void
}

const EndpointOptionsTeams: FC<Props> = ({url, secretURLSuffix, onChange}) => {
return (
<Panel>
<Panel.Header>
<h4>Teams Options</h4>
</Panel.Header>
<Panel.Body>
<Grid>
<Grid.Row>
<Grid.Column widthXS={Columns.Twelve}>
<FormElement label="Incoming Webhook URL">
<Input
name="url"
value={url}
testID="teams-url"
onChange={onChange}
/>
</FormElement>
</Grid.Column>
<Grid.Column widthXS={Columns.Twelve}>
<FormElement label="Webhook URL Secret Suffix">
<Input
name="secretURLSuffix"
value={secretURLSuffix}
testID="teams-secretURLSuffix"
onChange={onChange}
type={InputType.Password}
/>
</FormElement>
</Grid.Column>
</Grid.Row>
</Grid>
</Panel.Body>
</Panel>
)
}

export default EndpointOptionsTeams
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const reducer = (
'headers',
'clientURL',
'routingKey',
'channel',
'secretURLSuffix',
])

switch (endpoint.type) {
Expand Down Expand Up @@ -66,6 +68,13 @@ export const reducer = (
token: '',
channel: '',
}
case 'teams':
return {
...baseProps,
type: 'teams',
url: DEFAULT_ENDPOINT_URLS.teams,
token: '',
}
}
}
return state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const types: EndpointType[] = [
{name: 'Slack', type: 'slack', id: 'slack'},
{name: 'Pagerduty', type: 'pagerduty', id: 'pagerduty'},
{name: 'Telegram', type: 'telegram', id: 'telegram'},
{name: 'Teams', type: 'teams', id: 'teams'},
]

const EndpointTypeDropdown: FC<Props> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const EndpointsColumn: FC<Props> = ({history, match, endpoints}) => {
<br />
to a third party service that can receive notifications
<br />
like Slack, PagerDuty, Telegram, or an HTTP server
like Slack, PagerDuty, Telegram, Teams or an HTTP server
<br />
<br />
<a
Expand Down
13 changes: 13 additions & 0 deletions ui/src/notifications/rules/components/RuleMessageContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SlackMessage from './SlackMessage'
import SMTPMessage from './SMTPMessage'
import PagerDutyMessage from './PagerDutyMessage'
import TelegramMessage from './TelegramMessage'
import TeamsMessage from './TeamsMessage'

// Utils
import {useRuleDispatch} from './RuleOverlayProvider'
Expand Down Expand Up @@ -71,6 +72,18 @@ const RuleMessageContents: FC<Props> = ({rule}) => {
/>
)
}

case 'teams': {
const {title, messageTemplate} = rule
return (
<TeamsMessage
messageTemplate={messageTemplate}
title={title}
onChange={onChange}
/>
)
}

case 'http': {
return <></>
}
Expand Down
32 changes: 32 additions & 0 deletions ui/src/notifications/rules/components/TeamsMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Libraries
import React, {FC, ChangeEvent} from 'react'

// Components
import {Form, Input, TextArea} from '@influxdata/clockface'

interface Props {
title: string
messageTemplate: string
onChange: (e: ChangeEvent) => void
}

const TeamsMessage: FC<Props> = ({title, messageTemplate, onChange}) => {
return (
<>
<Form.Element label="Title">
<Input value={title} name="title" onChange={onChange} />
</Form.Element>
<Form.Element label="Message Template">
<TextArea
name="messageTemplate"
testID="teams-message-template--textarea"
value={messageTemplate}
onChange={onChange}
rows={3}
/>
</Form.Element>
</>
)
}

export default TeamsMessage
10 changes: 10 additions & 0 deletions ui/src/notifications/rules/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
RuleStatusLevel,
PostNotificationRule,
GenRule,
TeamsNotificationRuleBase,
} from 'src/types'
import {RemoteDataState} from '@influxdata/clockface'

Expand All @@ -24,6 +25,7 @@ type RuleVariantFields =
| PagerDutyNotificationRuleBase
| HTTPNotificationRuleBase
| TelegramNotificationRuleBase
| TeamsNotificationRuleBase

const defaultMessage =
'Notification Rule: ${ r._notification_rule_name } triggered by check: ${ r._check_name }: ${ r._message }'
Expand Down Expand Up @@ -60,6 +62,14 @@ export const getRuleVariantDefaults = (
type: 'telegram',
}
}

case 'teams': {
return {
messageTemplate: defaultMessage,
title: '${ r._notification_rule_name }',
type: 'teams',
}
}

default: {
throw new Error(`Could not find NotificationEndpoint with id "${id}"`)
Expand Down
12 changes: 11 additions & 1 deletion ui/src/types/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
NotificationEndpointBase as GenEndpointBase,
TelegramNotificationRuleBase,
TelegramNotificationEndpoint,
TeamsNotificationEndpoint,
TeamsNotificationRuleBase,
} from 'src/client'
import {RemoteDataState} from 'src/types'

Expand All @@ -47,6 +49,7 @@ export type NotificationEndpoint =
| (Omit<HTTPNotificationEndpoint, 'status' | 'labels'> & EndpointOverrides)
| (Omit<TelegramNotificationEndpoint, 'status' | 'labels'> &
EndpointOverrides)
| (Omit<TeamsNotificationEndpoint, 'status' | 'labels'> & EndpointOverrides)
export type NotificationEndpointBase = Omit<GenEndpointBase, 'labels'> &
EndpointOverrides

Expand All @@ -73,7 +76,7 @@ export type NotificationRuleBaseDraft = Overwrite<
}
>

type RuleDraft = SlackRule | SMTPRule | PagerDutyRule | HTTPRule | TelegramRule
type RuleDraft = SlackRule | SMTPRule | PagerDutyRule | HTTPRule | TelegramRule | TeamsRule

export type NotificationRuleDraft = RuleDraft

Expand All @@ -97,6 +100,10 @@ type TelegramRule = NotificationRuleBaseDraft &
TelegramNotificationRuleBase &
RuleOverrides

type TeamsRule = NotificationRuleBaseDraft &
TeamsNotificationRuleBase &
RuleOverrides

export type LowercaseCheckStatusLevel =
| 'crit'
| 'warn'
Expand Down Expand Up @@ -193,4 +200,7 @@ export {
TelegramNotificationEndpoint,
TelegramNotificationRuleBase,
TelegramNotificationRule,
TeamsNotificationRuleBase,
TeamsNotificationRule,
TeamsNotificationEndpoint,
} from '../client'

0 comments on commit 3c1f2c0

Please sign in to comment.