diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index 946820e8d51..3df0c8abfef 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -45,6 +45,7 @@ type NotifierOption struct { Required bool `json:"required"` ValidationRule string `json:"validationRule"` Secure bool `json:"secure"` + DependsOn string `json:"dependsOn"` } // InputType is the type of input that can be rendered in the frontend. diff --git a/pkg/services/ngalert/notifier/available_channels.go b/pkg/services/ngalert/notifier/available_channels.go index 521548e53b5..7fb228b1583 100644 --- a/pkg/services/ngalert/notifier/available_channels.go +++ b/pkg/services/ngalert/notifier/available_channels.go @@ -382,6 +382,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin { InputType: alerting.InputTypeText, Description: "Specify channel, private group, or IM channel (can be an encoded ID or a name) - required unless you provide a webhook", PropertyName: "recipient", + Required: true, + DependsOn: "secureSettings.url", }, // Logically, this field should be required when not using a webhook, since the Slack API needs a token. // However, since the UI doesn't allow to say that a field is required or not depending on another field, @@ -394,6 +396,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin { Description: "Provide a Slack API token (starts with \"xoxb\") - required unless you provide a webhook", PropertyName: "token", Secure: true, + Required: true, + DependsOn: "secureSettings.url", }, { Label: "Username", @@ -458,6 +462,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin { Placeholder: "Slack incoming webhook URL", PropertyName: "url", Secure: true, + Required: true, + DependsOn: "secureSettings.token", }, { // New in 8.4. Label: "Endpoint URL", diff --git a/public/app/features/alerting/components/NotificationChannelForm.tsx b/public/app/features/alerting/components/NotificationChannelForm.tsx index a9abc49a523..e05cf8e5bbd 100644 --- a/public/app/features/alerting/components/NotificationChannelForm.tsx +++ b/public/app/features/alerting/components/NotificationChannelForm.tsx @@ -41,7 +41,7 @@ export const NotificationChannelForm: FC = ({ useEffect(() => { /* - Finds fields that have dependencies on other fields and removes duplicates. + Find fields that have dependencies on other fields and removes duplicates. Needs to be prefixed with settings. */ const fieldsToWatch = diff --git a/public/app/features/alerting/state/reducers.test.ts b/public/app/features/alerting/state/reducers.test.ts index 13b9accc730..5fe86af7b9c 100644 --- a/public/app/features/alerting/state/reducers.test.ts +++ b/public/app/features/alerting/state/reducers.test.ts @@ -255,6 +255,7 @@ describe('Notification channel', () => { required: true, validationRule: '', secure: false, + dependsOn: '', }, { element: 'select', @@ -271,6 +272,7 @@ describe('Notification channel', () => { required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -283,6 +285,7 @@ describe('Notification channel', () => { required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -295,6 +298,7 @@ describe('Notification channel', () => { required: false, validationRule: '', secure: true, + dependsOn: '', }, ], }, diff --git a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx index 1af2bf08d06..3d6c6df0329 100644 --- a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx @@ -60,7 +60,7 @@ export const OptionField: FC = ({ option, invalid, pathPrefix, error, def }; const OptionInput: FC = ({ option, invalid, id, pathPrefix = '', readOnly = false }) => { - const { control, register, unregister } = useFormContext(); + const { control, register, unregister, getValues } = useFormContext(); const name = `${pathPrefix}${option.propertyName}`; // workaround for https://github.com/react-hook-form/react-hook-form/issues/4993#issuecomment-829012506 @@ -87,11 +87,11 @@ const OptionInput: FC = ({ option, invalid, id, pathPref return ( (option.validationRule !== '' ? validateOption(v, option.validationRule) : true), })} placeholder={option.placeholder} @@ -157,10 +157,27 @@ const OptionInput: FC = ({ option, invalid, id, pathPref const styles = { checkbox: css` - height: auto; // native chekbox has fixed height which does not take into account description + height: auto; // native checkbox has fixed height which does not take into account description `, }; const validateOption = (value: string, validationRule: string) => { return RegExp(validationRule).test(value) ? true : 'Invalid format'; }; + +const determineRequired = (option: NotificationChannelOption, getValues: any) => { + if (!option.dependsOn) { + return option.required ? 'Required' : false; + } + + const dependentOn = getValues(`items[0].${option.dependsOn}`); + return !dependentOn && option.required ? 'Required' : false; +}; + +const determineReadOnly = (option: NotificationChannelOption, getValues: any) => { + if (!option.dependsOn) { + return false; + } + + return getValues(`items[0].${option.dependsOn}`); +}; diff --git a/public/app/features/alerting/unified/mocks/grafana-notifiers.ts b/public/app/features/alerting/unified/mocks/grafana-notifiers.ts index 3cd3063abe5..eec2843582a 100644 --- a/public/app/features/alerting/unified/mocks/grafana-notifiers.ts +++ b/public/app/features/alerting/unified/mocks/grafana-notifiers.ts @@ -20,79 +20,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, - }, - ], - }, - { - type: 'dingding', - name: 'DingDing', - heading: 'DingDing settings', - description: 'Sends HTTP POST request to DingDing', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Url', - description: '', - placeholder: 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'Message Type', - description: '', - placeholder: '', - propertyName: 'msgType', - selectOptions: [ - { value: 'link', label: 'Link' }, - { value: 'actionCard', label: 'ActionCard' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - ], - }, - { - type: 'googlechat', - name: 'Google Hangouts Chat', - heading: 'Google Hangouts Chat settings', - description: 'Sends notifications to Google Hangouts Chat via webhooks based on the official JSON message format', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Url', - description: '', - placeholder: 'Google Hangouts Chat incoming webhook url', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'textarea', - inputType: '', - label: 'Message', - description: '', - placeholder: '{{ template "default.message" . }}', - propertyName: 'message', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, + dependsOn: '', }, ], }, @@ -115,6 +43,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -128,6 +57,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -141,6 +71,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, ], }, @@ -163,6 +94,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, + dependsOn: '', }, { element: 'select', @@ -179,6 +111,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -192,6 +125,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -205,537 +139,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: true, - }, - ], - }, - { - type: 'kafka', - name: 'Kafka REST Proxy', - heading: 'Kafka settings', - description: 'Sends notifications to Kafka Rest Proxy', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Kafka REST Proxy', - description: '', - placeholder: 'http://localhost:8082', - propertyName: 'kafkaRestProxy', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Topic', - description: '', - placeholder: 'topic1', - propertyName: 'kafkaTopic', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - ], - }, - { - type: 'sensu', - name: 'Sensu', - heading: 'Sensu settings', - description: 'Sends HTTP POST request to a Sensu API', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Url', - description: '', - placeholder: 'http://sensu-api.local:4567/results', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Source', - description: 'If empty rule id will be used', - placeholder: '', - propertyName: 'source', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Handler', - description: '', - placeholder: 'default', - propertyName: 'handler', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Username', - description: '', - placeholder: '', - propertyName: 'username', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'password', - label: 'Password', - description: '', - placeholder: '', - propertyName: 'passsword ', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: true, - }, - ], - }, - { - type: 'threema', - name: 'Threema Gateway', - heading: 'Threema Gateway settings', - description: 'Sends notifications to Threema using Threema Gateway (Basic IDs)', - info: 'Notifications can be configured for any Threema Gateway ID of type "Basic". End-to-End IDs are not currently supported.The Threema Gateway ID can be set up at https://gateway.threema.ch/.', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Gateway ID', - description: 'Your 8 character Threema Gateway Basic ID (starting with a *).', - placeholder: '*3MAGWID', - propertyName: 'gateway_id', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '\\*[0-9A-Z]{7}', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Recipient ID', - description: 'The 8 character Threema ID that should receive the alerts.', - placeholder: 'YOUR3MID', - propertyName: 'recipient_id', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '[0-9A-Z]{8}', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'API Secret', - description: 'Your Threema Gateway API secret.', - placeholder: '', - propertyName: 'api_secret', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - ], - }, - { - type: 'LINE', - name: 'LINE', - heading: 'LINE notify settings', - description: 'Send notifications to LINE notify', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Token', - description: '', - placeholder: 'LINE notify token key', - propertyName: 'token', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - ], - }, - { - type: 'opsgenie', - name: 'OpsGenie', - heading: 'OpsGenie settings', - description: 'Sends notifications to OpsGenie', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'API Key', - description: '', - placeholder: 'OpsGenie API Key', - propertyName: 'apiKey', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - { - element: 'input', - inputType: 'text', - label: 'Alert API Url', - description: '', - placeholder: 'https://api.opsgenie.com/v2/alerts', - propertyName: 'apiUrl', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'checkbox', - inputType: '', - label: 'Auto close incidents', - description: 'Automatically close alerts in OpsGenie once the alert goes back to ok.', - placeholder: '', - propertyName: 'autoClose', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'checkbox', - inputType: '', - label: 'Override priority', - description: 'Allow the alert priority to be set using the og_priority tag', - placeholder: '', - propertyName: 'overridePriority', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'Send notification tags as', - description: 'Send the notification tags to Opsgenie as either Extra Properties, Tags or both', - placeholder: '', - propertyName: 'sendTagsAs', - selectOptions: [ - { value: 'tags', label: 'Tags' }, - { value: 'details', label: 'Extra Properties' }, - { value: 'both', label: 'Tags \u0026 Extra Properties' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - ], - }, - { - type: 'pushover', - name: 'Pushover', - heading: 'Pushover settings', - description: 'Sends HTTP POST request to the Pushover API', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'API Token', - description: '', - placeholder: 'Application token', - propertyName: 'apiToken', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - { - element: 'input', - inputType: 'text', - label: 'User key(s)', - description: '', - placeholder: 'comma-separated list', - propertyName: 'userKey', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - { - element: 'input', - inputType: 'text', - label: 'Device(s) (optional)', - description: '', - placeholder: 'comma-separated list; leave empty to send to all devices', - propertyName: 'device', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'Alerting priority', - description: '', - placeholder: '', - propertyName: 'priority', - selectOptions: [ - { value: '2', label: 'Emergency' }, - { value: '1', label: 'High' }, - { value: '0', label: 'Normal' }, - { value: '-1', label: 'Low' }, - { value: '-2', label: 'Lowest' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'OK priority', - description: '', - placeholder: '', - propertyName: 'okPriority', - selectOptions: [ - { value: '2', label: 'Emergency' }, - { value: '1', label: 'High' }, - { value: '0', label: 'Normal' }, - { value: '-1', label: 'Low' }, - { value: '-2', label: 'Lowest' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Retry (Only used for Emergency Priority)', - description: - 'How often (in seconds) the Pushover servers will send the same alerting or OK notification to the user.', - placeholder: 'minimum 30 seconds', - propertyName: 'retry', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Expire (Only used for Emergency Priority)', - description: 'How many seconds the alerting or OK notification will continue to be retried.', - placeholder: 'maximum 86400 seconds', - propertyName: 'expire', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'Alerting sound', - description: '', - placeholder: '', - propertyName: 'sound', - selectOptions: [ - { value: 'default', label: 'Default' }, - { value: 'pushover', label: 'Pushover' }, - { value: 'bike', label: 'Bike' }, - { value: 'bugle', label: 'Bugle' }, - { value: 'cashregister', label: 'Cashregister' }, - { value: 'classical', label: 'Classical' }, - { value: 'cosmic', label: 'Cosmic' }, - { value: 'falling', label: 'Falling' }, - { value: 'gamelan', label: 'Gamelan' }, - { value: 'incoming', label: 'Incoming' }, - { value: 'intermission', label: 'Intermission' }, - { value: 'magic', label: 'Magic' }, - { value: 'mechanical', label: 'Mechanical' }, - { value: 'pianobar', label: 'Pianobar' }, - { value: 'siren', label: 'Siren' }, - { value: 'spacealarm', label: 'Spacealarm' }, - { value: 'tugboat', label: 'Tugboat' }, - { value: 'alien', label: 'Alien' }, - { value: 'climb', label: 'Climb' }, - { value: 'persistent', label: 'Persistent' }, - { value: 'echo', label: 'Echo' }, - { value: 'updown', label: 'Updown' }, - { value: 'none', label: 'None' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'select', - inputType: '', - label: 'OK sound', - description: '', - placeholder: '', - propertyName: 'okSound', - selectOptions: [ - { value: 'default', label: 'Default' }, - { value: 'pushover', label: 'Pushover' }, - { value: 'bike', label: 'Bike' }, - { value: 'bugle', label: 'Bugle' }, - { value: 'cashregister', label: 'Cashregister' }, - { value: 'classical', label: 'Classical' }, - { value: 'cosmic', label: 'Cosmic' }, - { value: 'falling', label: 'Falling' }, - { value: 'gamelan', label: 'Gamelan' }, - { value: 'incoming', label: 'Incoming' }, - { value: 'intermission', label: 'Intermission' }, - { value: 'magic', label: 'Magic' }, - { value: 'mechanical', label: 'Mechanical' }, - { value: 'pianobar', label: 'Pianobar' }, - { value: 'siren', label: 'Siren' }, - { value: 'spacealarm', label: 'Spacealarm' }, - { value: 'tugboat', label: 'Tugboat' }, - { value: 'alien', label: 'Alien' }, - { value: 'climb', label: 'Climb' }, - { value: 'persistent', label: 'Persistent' }, - { value: 'echo', label: 'Echo' }, - { value: 'updown', label: 'Updown' }, - { value: 'none', label: 'None' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - ], - }, - { - type: 'sensugo', - name: 'Sensu Go', - heading: 'Sensu Go Settings', - description: 'Sends HTTP POST request to a Sensu Go API', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Backend URL', - description: '', - placeholder: 'http://sensu-api.local:8080', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'password', - label: 'API Key', - description: 'API Key to auth to Sensu Go backend', - placeholder: '', - propertyName: 'apikey', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - { - element: 'input', - inputType: 'text', - label: 'Proxy entity name', - description: 'If empty, rule name will be used', - placeholder: '', - propertyName: 'entity', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Check name', - description: 'If empty, rule id will be used', - placeholder: '', - propertyName: 'check', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Handler', - description: '', - placeholder: '', - propertyName: 'handler', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Namespace', - description: '', - placeholder: 'default', - propertyName: 'namespace', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, + dependsOn: '', }, ], }, @@ -759,6 +163,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -772,6 +177,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -785,41 +191,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: true, - }, - ], - }, - { - type: 'discord', - name: 'Discord', - heading: 'Discord settings', - description: 'Sends notifications to Discord', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Message Content', - description: 'Mention a group using @ or a user using \u003c@ID\u003e when notifying in a channel', - placeholder: '', - propertyName: 'content', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'input', - inputType: 'text', - label: 'Webhook URL', - description: '', - placeholder: 'Discord webhook URL', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, + dependsOn: '', }, ], }, @@ -842,6 +214,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'textarea', @@ -855,108 +228,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: true, validationRule: '', secure: false, - }, - ], - }, - { - type: 'victorops', - name: 'VictorOps', - heading: 'VictorOps settings', - description: 'Sends notifications to VictorOps', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Url', - description: '', - placeholder: 'VictorOps url', - propertyName: 'url', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, - }, - { - element: 'checkbox', - inputType: '', - label: 'Auto resolve incidents', - description: 'Resolve incidents in VictorOps once the alert goes back to ok.', - placeholder: '', - propertyName: 'autoResolve', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - ], - }, - { - type: 'pagerduty', - name: 'PagerDuty', - heading: 'PagerDuty settings', - description: 'Sends notifications to PagerDuty', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'Integration Key', - description: '', - placeholder: 'Pagerduty Integration Key', - propertyName: 'integrationKey', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: true, - }, - { - element: 'select', - inputType: '', - label: 'Severity', - description: '', - placeholder: '', - propertyName: 'severity', - selectOptions: [ - { value: 'critical', label: 'Critical' }, - { value: 'error', label: 'Error' }, - { value: 'warning', label: 'Warning' }, - { value: 'info', label: 'Info' }, - ], - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'checkbox', - inputType: '', - label: 'Auto resolve incidents', - description: 'Resolve incidents in pagerduty once the alert goes back to ok.', - placeholder: '', - propertyName: 'autoResolve', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, - }, - { - element: 'checkbox', - inputType: '', - label: 'Include message in details', - description: - 'Move the alert message from the PD summary into the custom details. This changes the custom details object and may break event rules you have configured', - placeholder: '', - propertyName: 'messageInDetails', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: false, + dependsOn: '', }, ], }, @@ -977,9 +249,10 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ propertyName: 'recipient', selectOptions: null, showWhen: { field: '', is: '' }, - required: false, + required: true, validationRule: '', secure: false, + dependsOn: 'secureSettings.url', }, { element: 'input', @@ -990,9 +263,10 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ propertyName: 'token', selectOptions: null, showWhen: { field: '', is: '' }, - required: false, + required: true, validationRule: '', secure: true, + dependsOn: 'secureSettings.url', }, { element: 'input', @@ -1006,6 +280,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -1019,6 +294,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -1032,6 +308,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -1046,6 +323,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -1060,6 +338,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'select', @@ -1077,6 +356,7 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ required: false, validationRule: '', secure: false, + dependsOn: '', }, { element: 'input', @@ -1088,44 +368,10 @@ export const grafanaNotifiersMock: NotifierDTO[] = [ propertyName: 'url', selectOptions: null, showWhen: { field: '', is: '' }, - required: false, - validationRule: '', - secure: true, - }, - ], - }, - { - type: 'telegram', - name: 'Telegram', - heading: 'Telegram API settings', - description: 'Sends notifications to Telegram', - info: '', - options: [ - { - element: 'input', - inputType: 'text', - label: 'BOT API Token', - description: '', - placeholder: 'Telegram BOT API Token', - propertyName: 'bottoken', - selectOptions: null, - showWhen: { field: '', is: '' }, required: true, validationRule: '', secure: true, - }, - { - element: 'input', - inputType: 'text', - label: 'Chat ID', - description: 'Integer Telegram Chat Identifier', - placeholder: '', - propertyName: 'chatid', - selectOptions: null, - showWhen: { field: '', is: '' }, - required: true, - validationRule: '', - secure: false, + dependsOn: 'token', }, ], }, diff --git a/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts b/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts index d1e3bfcfbc6..4dcf2e44fdd 100644 --- a/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts +++ b/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts @@ -17,6 +17,7 @@ function option( placeholder: '', validationRule: '', showWhen: { field: '', is: '' }, + dependsOn: '', ...rest, }; } diff --git a/public/app/types/alerting.ts b/public/app/types/alerting.ts index aff14234045..4501687e77b 100644 --- a/public/app/types/alerting.ts +++ b/public/app/types/alerting.ts @@ -133,6 +133,7 @@ export interface NotificationChannelOption { showWhen: { field: string; is: string }; validationRule: string; subformOptions?: NotificationChannelOption[]; + dependsOn: string; } export interface NotificationChannelState {