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 23, 2020
1 parent 19c08e1 commit 581fea8
Show file tree
Hide file tree
Showing 11 changed files with 148 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 or an HTTP server?
PagerDuty, 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 @@ -5,13 +5,15 @@ import React, {FC, ChangeEvent} from 'react'
import EndpointOptionsSlack from './EndpointOptionsSlack'
import EndpointOptionsPagerDuty from './EndpointOptionsPagerDuty'
import EndpointOptionsHTTP from './EndpointOptionsHTTP'
import EndpointOptionsTeams from './EndpointOptionsTeams'

// Types
import {
NotificationEndpoint,
SlackNotificationEndpoint,
PagerDutyNotificationEndpoint,
HTTPNotificationEndpoint,
TeamsNotificationEndpoint,
} from 'src/types'

interface Props {
Expand Down Expand Up @@ -65,6 +67,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,7 @@ export const reducer = (
'headers',
'clientURL',
'routingKey',
'secretURLSuffix',
])

switch (endpoint.type) {
Expand All @@ -59,6 +60,13 @@ export const reducer = (
url: DEFAULT_ENDPOINT_URLS.slack,
token: '',
}
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 @@ -32,6 +32,7 @@ const types: EndpointType[] = [
{name: 'HTTP', type: 'http', id: 'http'},
{name: 'Slack', type: 'slack', id: 'slack'},
{name: 'Pagerduty', type: 'pagerduty', id: 'pagerduty'},
{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, or an HTTP server
like Slack, PagerDuty, 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 @@ -5,6 +5,7 @@ import React, {FC} from 'react'
import SlackMessage from './SlackMessage'
import SMTPMessage from './SMTPMessage'
import PagerDutyMessage from './PagerDutyMessage'
import TeamsMessage from './TeamsMessage'

// Utils
import {useRuleDispatch} from './RuleOverlayProvider'
Expand Down Expand Up @@ -61,6 +62,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 @@ -14,6 +14,7 @@ import {
RuleStatusLevel,
PostNotificationRule,
GenRule,
TeamsNotificationRuleBase,
} from 'src/types'
import {RemoteDataState} from '@influxdata/clockface'

Expand All @@ -22,6 +23,7 @@ type RuleVariantFields =
| SMTPNotificationRuleBase
| PagerDutyNotificationRuleBase
| HTTPNotificationRuleBase
| TeamsNotificationRuleBase

const defaultMessage =
'Notification Rule: ${ r._notification_rule_name } triggered by check: ${ r._check_name }: ${ r._message }'
Expand All @@ -45,6 +47,14 @@ export const getRuleVariantDefaults = (
return {type: 'http', url: ''}
}

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 @@ -19,6 +19,8 @@ import {
Threshold,
CheckBase as GenCheckBase,
NotificationEndpointBase as GenEndpointBase,
TeamsNotificationEndpoint,
TeamsNotificationRuleBase,
} from 'src/client'
import {RemoteDataState} from 'src/types'

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

Expand All @@ -69,7 +72,7 @@ export type NotificationRuleBaseDraft = Overwrite<
}
>

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

export type NotificationRuleDraft = RuleDraft

Expand All @@ -89,6 +92,10 @@ type HTTPRule = NotificationRuleBaseDraft &
HTTPNotificationRuleBase &
RuleOverrides

type TeamsRule = NotificationRuleBaseDraft &
TeamsNotificationRuleBase &
RuleOverrides

export type LowercaseCheckStatusLevel =
| 'crit'
| 'warn'
Expand Down Expand Up @@ -182,4 +189,7 @@ export {
PostNotificationRule,
CheckPatch,
TaskStatusType,
TeamsNotificationRuleBase,
TeamsNotificationRule,
TeamsNotificationEndpoint,
} from '../client'

0 comments on commit 581fea8

Please sign in to comment.