github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cloudeyeservice/alarmrule/results.go (about)

     1  package alarmrule
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/huaweicloud/golangsdk"
     7  )
     8  
     9  type CreateResponse struct {
    10  	AlarmID string `json:"alarm_id"`
    11  }
    12  
    13  type CreateResult struct {
    14  	golangsdk.Result
    15  }
    16  
    17  func (c CreateResult) Extract() (*CreateResponse, error) {
    18  	r := &CreateResponse{}
    19  	return r, c.ExtractInto(r)
    20  }
    21  
    22  type DimensionInfo struct {
    23  	Name  string `json:"name"`
    24  	Value string `json:"value"`
    25  }
    26  
    27  type MetricInfo struct {
    28  	Namespace  string          `json:"namespace"`
    29  	MetricName string          `json:"metric_name"`
    30  	Dimensions []DimensionInfo `json:"dimensions"`
    31  }
    32  
    33  type ConditionInfo struct {
    34  	Period             int    `json:"period"`
    35  	Filter             string `json:"filter"`
    36  	ComparisonOperator string `json:"comparison_operator"`
    37  	Value              int    `json:"value"`
    38  	Unit               string `json:"unit"`
    39  	Count              int    `json:"count"`
    40  }
    41  
    42  type ActionInfo struct {
    43  	Type             string   `json:"type"`
    44  	NotificationList []string `json:"notificationList"`
    45  }
    46  
    47  type AlarmRule struct {
    48  	AlarmName               string        `json:"alarm_name"`
    49  	AlarmDescription        string        `json:"alarm_description"`
    50  	AlarmType               string        `json:"alarm_type"`
    51  	AlarmLevel              int           `json:"alarm_level"`
    52  	Metric                  MetricInfo    `json:"metric"`
    53  	Condition               ConditionInfo `json:"condition"`
    54  	AlarmActions            []ActionInfo  `json:"alarm_actions"`
    55  	InsufficientdataActions []ActionInfo  `json:"insufficientdata_actions"`
    56  	OkActions               []ActionInfo  `json:"ok_actions"`
    57  	AlarmEnabled            bool          `json:"alarm_enabled"`
    58  	AlarmActionEnabled      bool          `json:"alarm_action_enabled"`
    59  	UpdateTime              int64         `json:"update_time"`
    60  	AlarmState              string        `json:"alarm_state"`
    61  	EnterpriseProjectID     string        `json:"enterprise_project_id"`
    62  }
    63  
    64  type GetResult struct {
    65  	golangsdk.Result
    66  }
    67  
    68  func (g GetResult) Extract() (*AlarmRule, error) {
    69  	var r struct {
    70  		MetricAlarms []AlarmRule `json:"metric_alarms"`
    71  	}
    72  	err := g.ExtractInto(&r)
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  	if len(r.MetricAlarms) != 1 {
    77  		return nil, fmt.Errorf("get %d alarm rules", len(r.MetricAlarms))
    78  	}
    79  	return &(r.MetricAlarms[0]), nil
    80  }
    81  
    82  type UpdateResult struct {
    83  	golangsdk.ErrResult
    84  }
    85  
    86  type EnableResult struct {
    87  	golangsdk.ErrResult
    88  }
    89  
    90  type DeleteResult struct {
    91  	golangsdk.ErrResult
    92  }