mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
643f790753
* Add support for Sensu Go notification channel Similar to current support for the older "Core" version of Sensu, this commit add support for the newer version. Closes #19908 Signed-off-by: Todd Campbell <todd@sensu.io> * fix linter errors Signed-off-by: Todd Campbell <todd@sensu.io> * Apply suggestions from code review PR review suggestions Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix no new variables error * Replace convey testing with testify Signed-off-by: Todd Campbell <todd@sensu.io> * Wording suggestions Signed-off-by: Todd Campbell <todd@sensu.io> * Add docker compose environment for testing/maintenance Signed-off-by: Todd Campbell <todd@sensu.io> * Renamed and fixed docker-compose.yaml to work in devenv Signed-off-by: Todd Campbell <todd@sensu.io> * Change sensugo web UI port to 3080 so as not to conflict with grafana Signed-off-by: Todd Campbell <todd@sensu.io> * Apply suggestions from code review Set the API key as a secure value. Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com> * Add Sensu Go information to notifications doc Signed-off-by: Todd Campbell <todd@sensu.io> * Update pkg/services/alerting/notifiers/sensugo.go Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com> * change assert to require for Error/NoError tests Signed-off-by: Todd Campbell <todd@sensu.io> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package notifiers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func TestSensuGoNotifier(t *testing.T) {
|
|
json := `{ }`
|
|
|
|
settingsJSON, err := simplejson.NewJson([]byte(json))
|
|
require.NoError(t, err)
|
|
model := &models.AlertNotification{
|
|
Name: "Sensu Go",
|
|
Type: "sensugo",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
_, err = NewSensuGoNotifier(model)
|
|
require.Error(t, err)
|
|
|
|
json = `
|
|
{
|
|
"url": "http://sensu-api.example.com:8080",
|
|
"entity": "grafana_instance_01",
|
|
"check": "grafana_rule_0",
|
|
"namespace": "default",
|
|
"handler": "myhandler",
|
|
"apikey": "abcdef0123456789abcdef"
|
|
}`
|
|
|
|
settingsJSON, err = simplejson.NewJson([]byte(json))
|
|
require.NoError(t, err)
|
|
model = &models.AlertNotification{
|
|
Name: "Sensu Go",
|
|
Type: "sensugo",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
not, err := NewSensuGoNotifier(model)
|
|
require.NoError(t, err)
|
|
sensuGoNotifier := not.(*SensuGoNotifier)
|
|
|
|
assert.Equal(t, "Sensu Go", sensuGoNotifier.Name)
|
|
assert.Equal(t, "sensugo", sensuGoNotifier.Type)
|
|
assert.Equal(t, "http://sensu-api.example.com:8080", sensuGoNotifier.URL)
|
|
assert.Equal(t, "grafana_instance_01", sensuGoNotifier.Entity)
|
|
assert.Equal(t, "grafana_rule_0", sensuGoNotifier.Check)
|
|
assert.Equal(t, "default", sensuGoNotifier.Namespace)
|
|
assert.Equal(t, "myhandler", sensuGoNotifier.Handler)
|
|
assert.Equal(t, "abcdef0123456789abcdef", sensuGoNotifier.APIKey)
|
|
}
|