github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cloudeyeservice/v2/alarmrule/requests.go (about) 1 package alarmrule 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 type DimensionOpts struct { 8 Name string `json:"name" required:"true"` 9 Value string `json:"value,omitempty"` 10 } 11 12 type PolicyOpts struct { 13 MetricName string `json:"metric_name" required:"true"` 14 // The value can be 0 15 Period int `json:"period"` 16 Filter string `json:"filter" required:"true"` 17 ComparisonOperator string `json:"comparison_operator" required:"true"` 18 // The Value ranges from 0 to MAX_VALUE 19 Value float64 `json:"value"` 20 Unit string `json:"unit,omitempty"` 21 Count int `json:"count" required:"true"` 22 // The value can be 0 23 SuppressDuration int `json:"suppress_duration"` 24 Level int `json:"level,omitempty"` 25 } 26 27 type NotificationOpts struct { 28 Type string `json:"type" required:"true"` 29 NotificationList []string `json:"notification_list" required:"true"` 30 } 31 32 type CreateOpts struct { 33 Name string `json:"name" required:"true"` 34 Description string `json:"description,omitempty"` 35 Namespace string `json:"namespace" required:"true"` 36 ResourceGroupID string `json:"resource_group_id,omitempty"` 37 Resources [][]DimensionOpts `json:"resources" required:"true"` 38 Policies []PolicyOpts `json:"policies" required:"true"` 39 Type string `json:"type" required:"true"` 40 AlarmNotifications []NotificationOpts `json:"alarm_notifications,omitempty"` 41 OkNotifications []NotificationOpts `json:"ok_notifications,omitempty"` 42 NotificationBeginTime string `json:"notification_begin_time,omitempty"` 43 NotificationEndTime string `json:"notification_end_time,omitempty"` 44 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 45 Enabled bool `json:"enabled"` 46 NotificationEnabled bool `json:"notification_enabled"` 47 AlarmTemplateID string `json:"alarm_template_id,omitempty"` 48 } 49 50 func Create(c *golangsdk.ServiceClient, opts CreateOpts) (r CreateResult) { 51 b, err := golangsdk.BuildRequestBody(opts, "") 52 if err != nil { 53 r.Err = err 54 return 55 } 56 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{201}} 57 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 58 return 59 } 60 61 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 62 _, r.Err = c.Get(listURL(c, id), &r.Body, &golangsdk.RequestOpts{ 63 MoreHeaders: map[string]string{ 64 "Content-Type": "application/json; charset=UTF-8", 65 }, 66 }) 67 return 68 } 69 70 type ActionOpts struct { 71 AlarmIDs []string `json:"alarm_ids" required:"true"` 72 AlarmEnabled bool `json:"alarm_enabled"` 73 } 74 75 func Action(c *golangsdk.ServiceClient, id string, opts ActionOpts) (r ActionResult) { 76 b, err := golangsdk.BuildRequestBody(opts, "") 77 if err != nil { 78 r.Err = err 79 return 80 } 81 _, r.Err = c.Post(actionURL(c), b, nil, &golangsdk.RequestOpts{ 82 OkCodes: []int{200}, 83 }) 84 return 85 } 86 87 type UpdateResourcesOpts struct { 88 Resources [][]DimensionOpts `json:"resources" required:"true"` 89 } 90 91 func BatchResources(c *golangsdk.ServiceClient, id, operation string, opts UpdateResourcesOpts) (r BatchResourcesResult) { 92 b, err := golangsdk.BuildRequestBody(opts, "") 93 if err != nil { 94 r.Err = err 95 return 96 } 97 _, r.Err = c.Post(batchResourcesURL(c, id, operation), b, nil, &golangsdk.RequestOpts{ 98 OkCodes: []int{200}, 99 }) 100 return 101 } 102 103 type UpdatePoliciesOpts struct { 104 Policies []PolicyOpts `json:"policies" required:"true"` 105 } 106 107 func PoliciesModify(c *golangsdk.ServiceClient, id string, opts UpdatePoliciesOpts) (r PoliciesResult) { 108 b, err := golangsdk.BuildRequestBody(opts, "") 109 if err != nil { 110 r.Err = err 111 return 112 } 113 _, r.Err = c.Put(policiesURL(c, id), b, nil, &golangsdk.RequestOpts{ 114 OkCodes: []int{200}, 115 }) 116 return 117 } 118 119 func GetResources(c *golangsdk.ServiceClient, id string) (r GetResourcesResult) { 120 _, r.Err = c.Get(resourcesURL(c, id), &r.Body, &golangsdk.RequestOpts{ 121 MoreHeaders: map[string]string{ 122 "Content-Type": "application/json; charset=UTF-8", 123 }, 124 }) 125 return 126 } 127 128 type DeleteOpts struct { 129 AlarmIDs []string `json:"alarm_ids"` 130 } 131 132 func Delete(c *golangsdk.ServiceClient, opts DeleteOpts) (r DeleteResult) { 133 b, err := golangsdk.BuildRequestBody(opts, "") 134 if err != nil { 135 r.Err = err 136 return 137 } 138 _, r.Err = c.Post(deleteURL(c), b, nil, &golangsdk.RequestOpts{ 139 OkCodes: []int{200}, 140 }) 141 return 142 }