1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
package cms
import (
"encoding/json"
"testing"
)
func TestClient_CreateAlarm(t *testing.T) {
client := NewTestClientForDebug()
c := []map[string]string{
{
"port": "SLB_PORT",
"userId": "USER_ID",
"instanceId": "SLB_ID",
},
}
b, _ := json.Marshal(c)
alarm := CommonAlarmItem{
Name: "my-test-alarm-rule",
Namespace: "acs_slb_dashboard",
MetricName: "UnhealthyServerCount",
Dimensions: string(b),
Statistics: "Average",
ComparisonOperator: ">",
Threshold: "0",
ContactGroups: "[\"云账号报警联系人\"]",
NotifyType: 1,
}
args := &CreateAlarmArgs{
CommonAlarmItem: alarm,
}
response, err := client.CreateAlarm(args)
if err != nil {
t.Fatalf("Failed to create alarm %++v", err)
} else {
t.Logf("Respose %++v", response)
}
}
func TestClient_DeleteAlarm(t *testing.T) {
client := NewTestClientForDebug()
err := client.DeleteAlarm("c3ed7915-2606-467f-8512-9d83c28929d2")
if err != nil {
t.Fatalf("Failed to delete alarm %++v", err)
} else {
t.Logf("Delete success")
}
}
func TestClient_ListAlarm(t *testing.T) {
client := NewTestClientForDebug()
args := &ListAlarmArgs{
Name: "my-test-alarm-rule",
Namespace: "acs_slb_dashboard",
IsEnable: true,
}
response, err := client.ListAlarm(args)
if err != nil {
t.Fatalf("Failed to list alarm %++v", err)
} else {
t.Logf("Respose %++v", response)
}
}
func TestClient_DisableAlarm(t *testing.T) {
client := NewTestClientForDebug()
err := client.DisableAlarm("778b15ea-53ff-4915-95a8-e63a801a18d4")
if err != nil {
t.Fatalf("Failed to disable alarm %++v", err)
} else {
t.Logf("Disable success")
}
}
func TestClient_EnableAlarm(t *testing.T) {
client := NewTestClientForDebug()
err := client.EnableAlarm("778b15ea-53ff-4915-95a8-e63a801a18d4")
if err != nil {
t.Fatalf("Failed to enable alarm %++v", err)
} else {
t.Logf("Enable success")
}
}
func TestClient_UpdateAlarm(t *testing.T) {
client := NewTestClientForDebug()
args := &UpdateAlarmArgs{
Id: "778b15ea-53ff-4915-95a8-e63a801a18d4",
Name: "my-test-alarm-rule-00002-for-update",
Statistics: "Average",
ComparisonOperator: ">",
Threshold: "0",
ContactGroups: "[\"云账号报警联系人\"]",
NotifyType: 0,
}
err := client.UpdateAlarm(args)
if err != nil {
t.Fatalf("Failed to update alarm %++v", err)
} else {
t.Logf("Update success")
}
}
func TestClient_ListAlarmHistory(t *testing.T) {
client := NewTestClientForDebug()
args := &ListAlarmHistoryArgs{}
response, err := client.ListAlarmHistory(args)
if err != nil {
t.Fatalf("Failed to listAlarm history %++v", err)
} else {
t.Logf("Response is %++v", response)
}
}
func TestClient_ListContactGroup(t *testing.T) {
client := NewTestClientForDebug()
client.SetSecurityToken(TestSecurityToken)
args := &ListContactGroupArgs{}
response, err := client.ListContactGroup(args)
if err != nil {
t.Fatalf("Failed to contact group %++v", err)
} else {
t.Logf("Response is %++v", response)
}
}
|