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

     1  package events
     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 EventItem struct {
    10  	// Specifies the event name.
    11  	// Start with a letter. Enter 1 to 64 characters. Only letters, digits, and underscores (_) are allowed.
    12  	EventName string `json:"event_name" required:"true"`
    13  	// Specifies the event source.
    14  	// The format is service.item. Set this parameter based on the site requirements.
    15  	// service and item each must be a string that starts with a letter and contains 3 to 32 characters, including only letters, digits, and underscores (_).
    16  	EventSource string `json:"event_source" required:"true"`
    17  	// Specifies when the event occurred, which is a UNIX timestamp (ms).
    18  	// NOTE
    19  	// Since there is a latency between the client and the server, the data timestamp to be inserted should be within
    20  	// the period that starts from one hour before the current time plus 20s to 10 minutes after the current time minus 20s.
    21  	// In this way, the timestamp will be inserted to the database without being affected by the latency.
    22  	// For example, if the current time is 2020.01.30 12:00:30, the timestamp inserted must be within the range
    23  	// [2020.01.30 11:00:50, 2020.01.30 12:10:10]. The corresponding UNIX timestamp is [1580353250, 1580357410].
    24  	Time   int64           `json:"time" required:"true"`
    25  	Detail EventItemDetail `json:"detail" required:"true"`
    26  }
    27  
    28  type EventItemDetail struct {
    29  	// Specifies the event content. Enter up to 4096 characters.
    30  	Content string `json:"content,omitempty"`
    31  	// Specifies the resource ID. Enter up to 128 characters, including letters, digits, underscores (_), hyphens (-), and colon (:).
    32  	// Example: 6a69bf28-ee62-49f3-9785-845dacd799ec
    33  	// To query the resource ID, perform the following steps:
    34  	// 1.	Log in to the management console.
    35  	// 2.	Under Computing, select Elastic Cloud Server.
    36  	// On the Resource Overview page, obtain the resource ID.
    37  	ResourceId string `json:"resource_id,omitempty"`
    38  	// Specifies the resource name. Enter up to 128 characters, including letters, digits, underscores (_), and hyphens (-).
    39  	ResourceName string `json:"resource_name,omitempty"`
    40  	// Specifies the event status.
    41  	// Valid value can be normal, warning, or incident.
    42  	EventState string `json:"event_state,omitempty"`
    43  	// Specifies the event severity.
    44  	// Its value can be Critical, Major, Minor, or Info.
    45  	EventLevel string `json:"event_level,omitempty"`
    46  	// Specifies the event user.
    47  	// Enter up to 64 characters, including letters, digits, underscores (_), hyphens (-), slashes (/), and spaces.
    48  	EventUser string `json:"event_user,omitempty"`
    49  
    50  	GroupId   string `json:"group_id,omitempty"`
    51  	EventType string `json:"event_type,omitempty"`
    52  }
    53  
    54  func CreateEvents(client *golangsdk.ServiceClient, opts []EventItem) ([]CreateEventsResponse, error) {
    55  	b, err := build.RequestBody(opts, "")
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	// POST /V1.0/{project_id}/events
    61  	raw, err := client.Post(client.ServiceURL("events"), b, nil, nil)
    62  	if err != nil {
    63  		return nil, err
    64  	}
    65  
    66  	var res []CreateEventsResponse
    67  	err = extract.Into(raw.Body, &res)
    68  	return res, err
    69  }
    70  
    71  type CreateEventsResponse struct {
    72  	// Specifies the event ID.
    73  	EventId string `json:"event_id"`
    74  	// Specifies the event name.
    75  	// Start with a letter. Enter 1 to 64 characters. Only letters, digits, and underscores (_) are allowed.
    76  	EventName string `json:"event_name"`
    77  }