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