github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/ces/v1/alarms/create_alarm.go (about)

     1  package alarms
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateAlarmOpts struct {
    10  	// Specifies the alarm rule name.
    11  	// Enter 1 to 128 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.
    12  	AlarmName string `json:"alarm_name"`
    13  	// Provides supplementary information about the alarm rule. Enter 0 to 256 characters.
    14  	AlarmDescription string `json:"alarm_description,omitempty"`
    15  	// Specifies the alarm metric.
    16  	Metric MetricForAlarm `json:"metric"`
    17  	// Specifies the alarm triggering condition.
    18  	Condition Condition `json:"condition"`
    19  	// Specifies whether to enable the alarm.
    20  	AlarmEnabled *bool `json:"alarm_enabled,omitempty"`
    21  	// Specifies whether to enable the action to be triggered by an alarm. The default value is true.
    22  	AlarmActionEnabled *bool `json:"alarm_action_enabled,omitempty"`
    23  	// Specifies the alarm severity. Possible values are 1, 2 (default), 3 and 4,
    24  	// indicating critical, major, minor, and informational, respectively.
    25  	AlarmLevel int `json:"alarm_level,omitempty"`
    26  	// Specifies the action to be triggered by an alarm.
    27  	AlarmType string `json:"alarm_type,omitempty"`
    28  	// Specifies the action to be triggered by an alarm.
    29  	AlarmActions []AlarmActions `json:"alarm_actions,omitempty"`
    30  	// Specifies the action to be triggered after the alarm is cleared.
    31  	OkActions []AlarmActions `json:"ok_actions,omitempty"`
    32  }
    33  
    34  type MetricForAlarm struct {
    35  	// Specifies the namespace of a service.
    36  	// The value must be in the service.item format and can contain 3 to 32 characters.
    37  	// service and item each must start with a letter and contain only letters, digits, and underscores (_).
    38  	Namespace string `json:"namespace"`
    39  	// Specifies the metric name.
    40  	// Start with a letter. Enter 1 to 64 characters. Only letters, digits, and underscores (_) are allowed.
    41  	MetricName string `json:"metric_name"`
    42  	// Specifies the list of metric dimensions.
    43  	Dimensions []MetricsDimension `json:"dimensions,omitempty"`
    44  	// Specifies the resource group ID selected during the alarm rule creation.
    45  	ResourceGroupId string `json:"resource_group_id,omitempty"`
    46  }
    47  
    48  func CreateAlarm(client *golangsdk.ServiceClient, opts CreateAlarmOpts) (string, error) {
    49  	b, err := build.RequestBody(opts, "")
    50  	if err != nil {
    51  		return "", err
    52  	}
    53  
    54  	// POST /V1.0/{project_id}/alarms
    55  	raw, err := client.Post(client.ServiceURL("alarms"), b, nil, nil)
    56  	if err != nil {
    57  		return "", err
    58  	}
    59  
    60  	var s struct {
    61  		AlarmId string `json:"alarm_id"`
    62  	}
    63  	err = extract.Into(raw.Body, &s)
    64  	return s.AlarmId, err
    65  }