opendistro-for-elasticsearch / alerting-kibana-plugin

📟 Open Distro Kibana Alerting Plugin
https://opendistro.github.io/
Apache License 2.0
140 stars 62 forks source link

impossible to allow only one destination #277

Closed ronansalmon closed 3 years ago

ronansalmon commented 3 years ago

Hi,

If you only allow one destination, you end up with the following error when adding a new destination: "Destination type [slack] is disallowed" OK :

PUT '/_cluster/settings' -d '
{ 
  "persistent" : {
    "opendistro.alerting.destination.allow_list" : "chime,email"
  }
}

NOK :

PUT '/_cluster/settings' -d '
{ 
  "persistent" : {
    "opendistro.alerting.destination.allow_list" : "email"
  }
}

NOK :

PUT '/_cluster/settings' -d '
{ 
  "persistent" : {
    "opendistro.alerting.destination.allow_list" : "chime"
  }
}

image

ronansalmon commented 3 years ago

We are using opendistroAlertingKibana 1.13.0.0

qreshi commented 3 years ago

Hey @ronansalmon,

I just took a look at this and I believe this is a bug that has occurred because the initial form value that is being used to populate the default selected Destination type is Slack. So I'd assume this error is actually popping up every time if Slack is disallowed but if you only have one option to select, even if it isn't Slack, you won't be able to get the UI to re-evaluate the validity of the form value by selecting something else.

For reference, here is where the initial values of the form are being set: https://github.com/opendistro-for-elasticsearch/alerting-kibana-plugin/blob/09f93ce32116f46456d839473e459eb563533d95/public/pages/Destinations/containers/CreateDestination/CreateDestination.js#L49-L56

And here is the snippet of the initial values being used: https://github.com/opendistro-for-elasticsearch/alerting-kibana-plugin/blob/09f93ce32116f46456d839473e459eb563533d95/public/pages/Destinations/containers/CreateDestination/utils/constants.js#L27-L30

I think a possible fix here could be to update the componentDidMount function of the CreateDestination component and after retrieving the allowList values, we can amend the initialValues so that it's something from the allowList (or disable the Destination type selection dropdown entirely if there are no allowed Destination types).

Here is where I would expect this change to go: https://github.com/opendistro-for-elasticsearch/alerting-kibana-plugin/blob/09f93ce32116f46456d839473e459eb563533d95/public/pages/Destinations/containers/CreateDestination/CreateDestination.js#L58-L62

I can create an issue to track this but it'll be in the OpenSearch repo as we don't actively develop new changes in the ODFE repo now.

ronansalmon commented 3 years ago

Hi @qreshi , It makes sense to me, so please go ahead and add an issue on the new repo.

Ronan

qreshi commented 3 years ago

@ronansalmon I've created this issue on the OpenSearch Dashboards repo. I'll be closing this issue in favor of that one, please continue any discussions there if needed and thanks for reporting this.