Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions openstack/aom/v2/log/ListLogItems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package log

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListLogItemsOpts struct {
// Log type:
//
// app_log: application log
//
// node_log: host log
//
// custom_log: log in a custom path
Category string `json:"category" required:"true"`
// Log filter criteria, which vary according to log sources.
SearchKey SearchKey `json:"searchKey" required:"true"`
// Cloud Container Engine (CCE) cluster ID.
ClusterId string `json:"clusterId" required:"true"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace,omitempty"`
// Service name.
AppName string `json:"appName,omitempty"`
// Container pod name.
PodName string `json:"podName,omitempty"`
// Log file name.
PathFile string `json:"pathFile,omitempty"`
// IP address of the VM where logs are located.
HostIP string `json:"hostIP,omitempty"`
// Enter a keyword between two adjacent delimiters for exact search.
//
// Enter a keyword for fuzzy search. Example: RROR, ERRO?, *ROR*, ERR*, or ER*OR.
//
// Enter a phrase for exact search. Example: Start to refresh alm Statistic.
//
// Enter contents containing AND (&&) or OR (||) for search. Example: query&&logs or query||logs.
//
// Default delimiters:
//
// , '";=()[]{}@&<>/:\n\t\r
KeyWord string `json:"keyWord,omitempty"`
// Start time of the query (UTC, in ms).
StartTime *int64 `json:"startTime" required:"true"`
// End time of the query (UTC, in ms).
EndTime *int64 `json:"endTime" required:"true"`
// Whether to hide the system log (icagent\kubectl) during the query. 0 (default): Hide. 1: Not hide.
//
// Value Range
//
// 0 or 1
HideSyslog *int `json:"hideSyslog,omitempty"`
}

type SearchKey struct {
// CCE cluster ID.
ClusterId string `json:"clusterId" required:"true"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace,omitempty"`
// Application name.
AppName string `json:"appName,omitempty"`
// Container instance name.
PodName string `json:"podName,omitempty"`
// Log file name.
PathFile string `json:"pathFile,omitempty"`
// IP address of the VM where logs are located.
HostIP string `json:"hostIP,omitempty"`
}

func ListLogItems(client *golangsdk.ServiceClient, opts ListLogItemsOpts) (*ListLogItemsResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/als/action
raw, err := client.Post(client.ServiceURL("als", "action")+"?type=querylogs", b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res ListLogItemsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListLogItemsResponse struct {
// Response code. Example: AOM.0200, which indicates a success response.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Metadata, including total number of returned records and results.
Result ItemsResult `json:"result"`
}

type ItemsResult struct {
// Number of returned records.
Total *int `json:"total"`
// Data array.
Data []ItemData `json:"data"`
}

type ItemData struct {
// Log type.
Category string `json:"category"`
// Hash value of the log source.
LogHash string `json:"loghash"`
// Cloud Container Engine (CCE) cluster ID.
ClusterId string `json:"clusterId"`
// CCE cluster name.
ClusterName string `json:"clusterName"`
// CCE cluster namespace.
NameSpace string `json:"nameSpace"`
// CCE container pod name.
PodName string `json:"podName"`
// Service name.
AppName string `json:"appName"`
// Service ID of an AOM resource.
ServiceID string `json:"serviceID"`
// CCE container name.
ContainerName string `json:"containerName"`
// Source log data.
LogContent string `json:"logContent"`
// Absolute path of a log file.
PathFile string `json:"pathFile"`
// IP address of the VM where log files are located.
HostIP string `json:"hostIP"`
// ID of a host in a cluster.
HostId string `json:"hostId"`
// Name of the VM where log files are located.
HostName string `json:"hostName"`
// Log collection time (UTC time, in ms).
CollectTime string `json:"collectTime"`
// Sequence number of a log line.
LineNum string `json:"lineNum"`
// Size of a single-line log.
LogContentSize string `json:"logContentSize"`
}
35 changes: 35 additions & 0 deletions openstack/aom/v2/monitor/AddAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

func AddAlarmRule(client *golangsdk.ServiceClient, opts Threshold) (*AddAlarmRuleResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/alarms
raw, err := client.Post(client.ServiceURL("ams", "alarms"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res AddAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type AddAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Threshold rule code.
AlarmId *int64 `json:"alarmId"`
}
86 changes: 86 additions & 0 deletions openstack/aom/v2/monitor/AddMetricData.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type AddMetricDataOpts struct {
// Metric data.
Metric MetricAdd `json:"metric" required:"true"`
//
Values []Value `json:"values" required:"true"`
// Data collection time, which must meet the following requirement:
//
// Current UTC time - Data collection time <= 24 hours, or Data collection time - Current UTC time <= 30 minutes
//
// Value Range
//
// UNIX timestamp, in ms.
CollectTime *int64 `json:"collect_time" required:"true"`
}

type MetricAdd struct {
// Metric namespace.
//
// Value Range
//
// Namespace, which must be in the format of service.item. The value must be 3 to 32 characters starting with a letter. Only letters, digits, and underscores (_) are allowed. In addition, service cannot start with PAAS or SYS.
Namespace string `json:"namespace" required:"true"`
// List of metric dimensions.
//
// Value Range
//
// Each dimension is a JSON object, and its structure is as follows:
//
// dimension.name: 1-32 characters.
//
// dimension.value: 1-64 characters.
Dimensions []Dimension `json:"dimensions" required:"true"`
}

type Value struct {
// Data unit.
Unit string `json:"unit,omitempty"`
// Metric name.
MetricName string `json:"metric_name" required:"true"`
// Data type.
//
// Value Range
//
// "int" or "float"
Type string `json:"type,omitempty"`
// Metric value.
//
// Value Range
//
// Valid numeral type.
Value *float32 `json:"value" required:"true"`
}

func AddMetricData(client *golangsdk.ServiceClient, opts AddMetricDataOpts) (*AddMetricDataResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}

// POST /v2/{project_id}/ams/report/metricdata
raw, err := client.Post(client.ServiceURL("ams", "report", "metricdata"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
if err != nil {
return nil, err
}

var res AddMetricDataResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type AddMetricDataResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
}
13 changes: 13 additions & 0 deletions openstack/aom/v2/monitor/DeleteAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package monitor

import (
"strconv"

"github.com/opentelekomcloud/gophertelekomcloud"
)

func DeleteAlarmRule(client *golangsdk.ServiceClient, alarmId int64) (err error) {
// DELETE /v2/{project_id}/ams/alarms/{alarm_id}
_, err = client.Delete(client.ServiceURL("ams", "alarms", strconv.FormatInt(alarmId, 10)), nil)
return
}
60 changes: 60 additions & 0 deletions openstack/aom/v2/monitor/ListAlarmRule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package monitor

import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)

type ListAlarmRuleOpts struct {
// Value range: 1-1000. Default value: 1000.
//
// Maximum number of returned records.
//
// Value Range
//
// (0,1000]
Limit *int `q:"limit"`
// Pagination information.
//
// Value Range
//
// [0, (Maximum value of the int type - 1000)]
Start *int `q:"start"`
}

func ListAlarmRule(client *golangsdk.ServiceClient, opts ListAlarmRuleOpts) (*ListAlarmRuleResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v2/{project_id}/ams/alarms
raw, err := client.Get(client.ServiceURL("ams", "alarms")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListAlarmRuleResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListAlarmRuleResponse struct {
// Response code.
ErrorCode string `json:"errorCode"`
// Response message.
ErrorMessage string `json:"errorMessage"`
// Metadata, including pagination information.
MetaData MetaData `json:"metaData"`
// Threshold rule list.
Thresholds []Threshold `json:"thresholds"`
}

type MetaData struct {
// Number of returned records.
Count *int `json:"count"`
// Total number of records.
Start string `json:"start"`
// Start of the next page, which is used for pagination.
Total *int `json:"total"`
}
Loading