2016-04-26 23:36:50 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-11-29 17:18:01 +08:00
|
|
|
"net/http"
|
2025-08-29 02:46:30 +08:00
|
|
|
"slices"
|
2025-09-17 21:25:56 +08:00
|
|
|
"strings"
|
2016-07-21 16:29:11 +08:00
|
|
|
|
2021-01-15 21:43:20 +08:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
2023-01-27 15:50:36 +08:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2022-07-21 01:58:36 +08:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config"
|
2016-04-26 23:36:50 +08:00
|
|
|
)
|
|
|
|
|
2024-01-05 07:01:57 +08:00
|
|
|
func (hs *HTTPServer) GetAlertNotifiers() func(*contextmodel.ReqContext) response.Response {
|
2025-08-29 02:46:30 +08:00
|
|
|
return func(r *contextmodel.ReqContext) response.Response {
|
|
|
|
if r.Query("version") == "2" {
|
2025-09-17 21:25:56 +08:00
|
|
|
v2 := slices.SortedFunc(channels_config.GetAvailableNotifiersV2(), func(a, b *channels_config.VersionedNotifierPlugin) int {
|
|
|
|
return strings.Compare(a.Type, b.Type)
|
|
|
|
})
|
|
|
|
return response.JSON(http.StatusOK, v2)
|
2025-08-29 02:46:30 +08:00
|
|
|
}
|
2024-01-05 07:01:57 +08:00
|
|
|
return response.JSON(http.StatusOK, channels_config.GetAvailableNotifiers())
|
|
|
|
}
|
|
|
|
}
|