Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions acceptance/openstack/ces/v2/alarms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ces/v2/alarms"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
Expand Down Expand Up @@ -83,3 +84,67 @@ func TestAlarmsCRUD(t *testing.T) {
})
th.AssertNoErr(t, err)
}

func TestAlarmsCreateEventSysWithEmptyResources(t *testing.T) {
client, err := clients.NewCesV2Client()
th.AssertNoErr(t, err)

alarmName := tools.RandomString("test-alarm-event-sys-", 4)

t.Log("Attempting to create EVENT.SYS alarm rule with empty resources")
createOpts := alarms.CreateOpts{
Name: alarmName,
Namespace: "SYS.ECS",
Type: "EVENT.SYS",
Resources: [][]alarms.Dimension{},
Policies: []alarms.Policy{
{
MetricName: "stopServer",
Period: 0,
Filter: "average",
ComparisonOperator: ">=",
Value: 1,
Unit: "count",
Count: 1,
SuppressDuration: 0,
Level: 2,
},
},
NotificationEnabled: pointerto.Bool(false),
Enabled: pointerto.Bool(true),
}

alarmId, err := alarms.Create(client, createOpts)
th.AssertNoErr(t, err)

t.Cleanup(func() {
t.Log("Attempting to delete EVENT.SYS alarm rule")
_, err := alarms.Delete(client, alarms.DeleteOpts{
AlarmIds: []string{alarmId},
})
th.AssertNoErr(t, err)
})

t.Log("Attempting to verify EVENT.SYS alarm rule")
listResp, err := alarms.List(client, alarms.ListOpts{
AlarmId: alarmId,
})
th.AssertNoErr(t, err)
th.AssertEquals(t, listResp.Count, 1)
th.AssertEquals(t, listResp.Alarms[0].Name, alarmName)
th.AssertEquals(t, listResp.Alarms[0].Namespace, "SYS.ECS")
th.AssertEquals(t, listResp.Alarms[0].Type, "EVENT.SYS")
th.AssertEquals(t, listResp.Alarms[0].Enabled, true)
th.AssertEquals(t, listResp.Alarms[0].NotificationEnabled, false)
th.AssertEquals(t, len(listResp.Alarms[0].Resources), 1)
th.AssertEquals(t, len(listResp.Alarms[0].Policies), 1)
th.AssertEquals(t, listResp.Alarms[0].Policies[0].MetricName, "stopServer")
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Period, 0)
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Filter, "average")
th.AssertEquals(t, listResp.Alarms[0].Policies[0].ComparisonOperator, ">=")
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Value, float64(1))
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Unit, "count")
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Count, 1)
th.AssertEquals(t, listResp.Alarms[0].Policies[0].SuppressDuration, 0)
th.AssertEquals(t, listResp.Alarms[0].Policies[0].Level, 2)
}
2 changes: 1 addition & 1 deletion openstack/ces/v2/alarms/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type CreateOpts struct {
ResourceGroupId string `json:"resource_group_id,omitempty"`
// Specifies the resource list. This parameter is mandatory when type is set to MULTI_INSTANCE.
// A maximum of 1000 resources are supported.
Resources [][]Dimension `json:"resources,omitempty"`
Resources [][]Dimension `json:"resources"`
// Specifies the alarm policies.
// Either policies or alarm_template_id must be configured.
Policies []Policy `json:"policies,omitempty"`
Expand Down
Loading