cms

package
v0.0.0-...-b2f09ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEADER_SEPERATER = "\n"
	ACS_PREFIX       = "x-acs"
)
View Source
const (
	//TODO 旧的API,暂时保留
	DefaultEndpoint = "http://alert.aliyuncs.com"
	APIVersion      = "2015-08-15"
	METHOD_GET      = "GET"
	METHOD_POST     = "POST"
	METHOD_PUT      = "PUT"
	METHOD_DELETE   = "DELETE"

	CMSDefaultEndpoint = "http://metrics.cn-hangzhou.aliyuncs.com"
	CMSAPIVersion      = "2017-03-01"
	CMSServiceCode     = "cms"
)

Variables

This section is empty.

Functions

func BodyMd5

func BodyMd5(jsonstring string) string

*

  • 对json进行md5 base64

func GetRequestPath

func GetRequestPath(entity string, project string, id string) string

*

  • 取得上下文请求路径

func InitBaseHeader

func InitBaseHeader(v *http.Request)

*

  • 取得公共的头部参数,初始化的时候先将Content

Types

type ActionGroup

type ActionGroup struct {
	ContactGroups []string `json:"contactGroups"`
	Id            string   `json:"id"`
}

type ActionsModel

type ActionsModel struct {
	AlertActions []AlertActionsModel `json:"alertActions"`
	Effective    string              `json:"effective"`
	Failure      ActionGroup         `json:"failure"`
}

type AlarmHistoryItem

type AlarmHistoryItem struct {
	Id              string //报警规则id
	Name            string //报警规则名称
	Namespace       string //产品名称,参考各产品对应的project,例如acs_ecs_dashboard, acs_rds_dashboard等
	MetricName      string //相应产品对应的监控项名称,参考各产品metric定义
	Dimension       string //报警规则对应实例列表,为json array对应的string,例如[{“instanceId”:”name1”},{“iinstance”:”name2”}]
	EvaluationCount int    //连续探测几次都满足阈值条件时报警,默认3次
	Value           string //报警的当前值
	AlarmTime       int64  //发生报警的时间
	LastTime        int64  //报警持续时间,单位为毫秒
	State           string //报警规则状态,有OK,ALARM,INSUFFICIENT_DATA三种状态
	Status          int    //通知发送状态,0为已通知用户,1为不在生效期未通知,2为处于报警沉默期未通知
	ContactGroups   string //发出的报警通知的通知对象,json array对应的字符串,例如[“联系组1”:”联系组2”],只有通知状态为0才有该字段
}

type AlarmItem

type AlarmItem struct {
	Id     string //报警规则id
	Enable bool   //该规则是否启用,true为启动
	State  string //报警规则的状态,有一个实例报警就是ALARM,所有都没数据是INSUFFICIENT_DATA,其它情况为OK

	CommonAlarmItem
}

type AlertActionsModel

type AlertActionsModel struct {
	ContactGroups []string `json:"contactGroups"`
	Id            string   `json:"id"`
	Level         int      `json:"level"`
}

type AlertRequest

type AlertRequest struct {
	Name        string             `json:"name"`
	Status      int                `json:"status"`
	Actions     ActionsModel       `json:"actions"`
	Condition   ConditionModel     `json:"condition"`
	Enable      bool               `json:"enable"`
	Escalations []EscalationsModel `json:"escalations"`
}

alert请求结构

type CMSClient

type CMSClient struct {
	common.Client
}

func NewCMSClient

func NewCMSClient(accessKeyId, accessKeySecret string) *CMSClient

NewClient creates a new instance of CMS client

func NewCMSRegionClient

func NewCMSRegionClient(accessKeyId, accessKeySecret string, regionID common.Region) *CMSClient

func NewClientWithEndpoint

func NewClientWithEndpoint(endpoint string, accessKeyId, accessKeySecret string) *CMSClient

func NewClientWithRegion

func NewClientWithRegion(endpoint string, accessKeyId, accessKeySecret string, regionID common.Region) *CMSClient

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(accessKeyId, accessKeySecret string) *Client

TODO 旧的API NewClient creates a new instance of ECS client

func (*Client) CreateAlert

func (c *Client) CreateAlert(projectName string, alertRequest AlertRequest) (result ResultModel, err error)

*

  • 创建一个Alert
  • @params
  • projectName
  • AlertRequest 创建模块的模型
  • @return
  • result 创建返回的模型
  • error 错误,如果一切Ok,error为 nil

func (*Client) CreateAlert4Json

func (c *Client) CreateAlert4Json(projectName string, request string) (result ResultModel, err error)

func (*Client) CreateAlertDimension

func (c *Client) CreateAlertDimension(projectName string, request DimensionRequest) (result ResultModel, err error)

func (*Client) CreateProject

func (c *Client) CreateProject(projectName string, projectDesc string, projectOwner string) (result ResultModel, err error)

*

  • 创建一个Project
  • @params
  • ProjectModel 创建模块的模型
  • @return
  • result 创建返回的模型
  • error 错误,如果一切Ok,error为 nil

func (*Client) DeleteAlert

func (c *Client) DeleteAlert(projectName string, alertName string) (result ResultModel, err error)

*

*

func (*Client) DeleteAlertDimension

func (c *Client) DeleteAlertDimension(projectName string, alertName string, dimensionId string) (result ResultModel, err error)

func (*Client) DeleteProject

func (c *Client) DeleteProject(projectName string) (result ResultModel, err error)

*

  • 删除一个Project
  • @params
  • projectName 创建模块的模型
  • @return
  • result 返回的模型
  • error 错误,如果一切Ok,error为 nil

func (*Client) GetAccessKey

func (client *Client) GetAccessKey() string

func (*Client) GetAccessSecret

func (client *Client) GetAccessSecret() string

func (*Client) GetAlert

func (c *Client) GetAlert(projectName string, alertName string) (result GetProjectResult, err error)

* 取得一个alert

func (*Client) GetAlertList

func (c *Client) GetAlertList(page string, pageSize string, projectName string, alertName string) (result GetProjectResult, err error)

*

  • 取得alertl列表

func (*Client) GetApiUri

func (client *Client) GetApiUri() string

func (*Client) GetDimensions

func (c *Client) GetDimensions(projectName string, alertName string) (result GetDimenstionResult, err error)

func (*Client) GetProject

func (c *Client) GetProject(projectName string) (result GetProjectResult, err error)

*

  • 取得一个Project
  • @params
  • projectName projectName不能为空
  • @return
  • result 返回的模型
  • error 错误,如果一切Ok,error为 nil

func (*Client) GetProjectList

func (c *Client) GetProjectList(page string, pageSize string, projectOwner string) (result ProjectListResultModel, err error)

*

  • 取得一个多个Project
  • @params
  • page: 页码
  • pageSize: 每夜记录条数
  • projectOwner 所属用户
  • @return
  • result 返回的模型
  • error 错误,如果一切Ok,error为 nil

func (*Client) GetResponseJson

func (c *Client) GetResponseJson(method string, requestUrl string, requestPath string, body string) (responseBody string, err error)

*

  • 发送http请求,去的响应字符串

func (*Client) GetUrl

func (client *Client) GetUrl(entity string, project string, id string) string

*

  • 去的要请求的url

func (*Client) PutMetrics

func (c *Client) PutMetrics(projectName string, request string) (result ResultModel, err error)

func (*Client) SetDebug

func (client *Client) SetDebug(debug bool)

func (*Client) SetSecurityToken

func (client *Client) SetSecurityToken(securityToken string)

func (*Client) SetTransport

func (client *Client) SetTransport(transport http.RoundTripper)

SetTransport sets transport to the http client

func (*Client) Sign

func (client *Client) Sign(method string, url string, req *http.Request, querys string)

*

  • 这个方法是先POP签名,并写入到协议头中
  • @params
  • method http方法,GET POST DELETE PUT 等
  • url 请求的url
  • header http请求头
  • querys GET请求参数,则需要设置querys参数
  • POP签名

func (*Client) UpdateAlert

func (c *Client) UpdateAlert(projectName string, alertName string, alertRequest AlertRequest) (result ResultModel, err error)

*

  • 更新Alert

func (*Client) UpdateProject

func (c *Client) UpdateProject(projectName string, project *ProjectModel) (result ResultModel, err error)

*

  • 更新一个Project
  • @params
  • projectName 创建模块的模型
  • project 修改的模型,这个只能修改projectDesc和ProjectOwer
  • @return
  • result 返回的模型
  • error 错误,如果一切Ok,error为 nil

type CommonAlarmItem

type CommonAlarmItem struct {
	Name               string //报警规则名称
	Namespace          string //产品名称,参考各产品对应的project,例如acs_ecs_dashboard, acs_rds_dashboard等
	MetricName         string //相应产品对应的监控项名称,参考各产品metric定义
	Dimensions         string //报警规则对应实例列表,为json array对应的string,例如[{“instanceId”:”name1”},{“iinstance”:”name2”}]
	Period             int    //查询指标的周期,必须与定义的metric一致,默认300,单位为秒
	Statistics         string //统计方法,必须与定义的metric一致,例如Average
	ComparisonOperator string //报警比较符,只能为以下几种<=,<,>,>=,==,!=
	Threshold          string //报警阈值,目前只开放数值类型功能
	EvaluationCount    int    //连续探测几次都满足阈值条件时报警,默认3次
	ContactGroups      string //报警规则通知的联系组,必须在控制台上已创建,为json array对应的string,例如 [“联系组1”,”联系组2”]
	StartTime          int    //报警生效时间的开始时间,默认0,代表0点
	EndTime            int    //报警生效时间的结束时间,默认24,代表24点
	SilenceTime        int    //一直处于报警状态的通知沉默周期,默认86400,单位s,最小1小时
	NotifyType         int    //通知类型,为0是旺旺+邮件,为1是旺旺+邮件+短信
}

type CommonAlarmResponse

type CommonAlarmResponse struct {
	RequestId string
	Success   bool
	Code      string
	Message   string
}

type ConditionModel

type ConditionModel struct {
	DimensionKeys    []string `json:"dimensionKeys"`
	Interval         int      `json:"interval"`
	MetricColumnName string   `json:"metricColumnName"`
	MetricName       string   `json:"metricName"`
	SourceType       string   `json:"sourceType"`
}

type CreateAlarmArgs

type CreateAlarmArgs struct {
	CommonAlarmItem
}

type CreateAlarmResponse

type CreateAlarmResponse struct {
	CommonAlarmResponse
	Data string
}

type DeleteAlarmArgs

type DeleteAlarmArgs struct {
	Id string
}

type DeleteAlarmResponse

type DeleteAlarmResponse struct {
	CommonAlarmResponse
	Data string
}

type DimensionDataPoint

type DimensionDataPoint struct {
	Id         string `json:"id"`
	Project    string `json:"project,omitempty"`
	AlertUuid  string `json:"alertUuid,omitempty"`
	Status     int    `json:"status,omitempty"`
	Dimensions string `json:"dimensions,omitempty"`
	AlertName  string `json:"alertName,omitempty"`
}

type DimensionRequest

type DimensionRequest struct {
	//ProjectName string `json:"projectName"`
	AlertName  string `json:"alertName"`
	Dimensions string `json:"dimensions"`
	UserId     string `json:"userId"`
}

type DisableAlarmArgs

type DisableAlarmArgs struct {
	Id string
}

type DisableAlarmResponse

type DisableAlarmResponse struct {
	CommonAlarmResponse
}

type EnableAlarmArgss

type EnableAlarmArgss struct {
	Id string
}

type EnableAlarmResponse

type EnableAlarmResponse struct {
	CommonAlarmResponse
}

type EscalationsModel

type EscalationsModel struct {
	Expression string `json:"expression"`
	Level      int    `json:"level"`
	Times      int    `json:"times"`
}

type Failure

type Failure struct {
	ContactGroups []string `json:"contactGroups"`
	Id            string   `json:"id"`
}

type GetDimenstionResult

type GetDimenstionResult struct {
	Code       string                `json:"code"`
	Success    bool                  `json:"success"`
	Message    string                `json:"comessagede,omitempty"`
	TraceId    string                `json:"traceId"`
	DataPoints []*DimensionDataPoint `json:"datapoints,omitempty"`
}

type GetProjectResult

type GetProjectResult struct {
	Result  ProjectResultModel `json:"result"`
	Code    string             `json:"code"`
	Success bool               `json:"success"`
}

返回的实体类型

type ListAlarmArgs

type ListAlarmArgs struct {
	Id         string //报警规则的id
	Name       string //报警规则名称,支持模糊查询
	Namespace  string //产品名称,参考各产品对应的project,例如 acs_ecs_dashboard, acs_rds_dashboard等
	Dimensions string //规则关联的实例信息,为json object对应的字符串,例如{“instacnce”:”name1”}。可以查询用于查询关联该实例的所有规则,应用该字段时必须指定Namespace
	State      string //报警规则状态, ALARM, INSUFFICIENT_DATA,OK
	IsEnable   bool   //true为启用,false为禁用
	common.Pagination
}

type ListAlarmHistoryArgs

type ListAlarmHistoryArgs struct {
	Id        string //报警规则的id
	Size      int    //每页记录数,默认值:100
	StartTime string //查询数据开始时间,默认24小时前,可以输入long型时间,也可以输入yyyy-MM-dd HH:mm:ss类型时间
	EndTime   string //查询数据结束时间,默认当前时间,可以输入long型时间,也可以输入yyyy-MM-dd HH:mm:ss类型时间
	Cursor    string //查询数据的起始位置,为空则按时间查询前100条
}

type ListAlarmHistoryResponse

type ListAlarmHistoryResponse struct {
	CommonAlarmResponse
	Cursor           string //查询数据的起始位置,为空则按时间查询前100条
	AlarmHistoryList struct {
		AlarmHistory []AlarmHistoryItem //报警历史详情列表
	}
}

type ListAlarmResponse

type ListAlarmResponse struct {
	CommonAlarmResponse
	NextToken int //下一页,为空代表没有下一页
	Total     int //符合条件数据总数
	AlarmList struct {
		Alarm []AlarmItem //报警规则详情列表
	}
}

type ListContactGroupArgs

type ListContactGroupArgs struct {
	common.Pagination
}

type ListContactGroupResponse

type ListContactGroupResponse struct {
	CommonAlarmResponse
	NextToken  string   //下一页,为空代表没有下一页
	Datapoints []string //联系组名称列表
	Total      int      //符合条件数据总数
}

type ListProjectRequestModel

type ListProjectRequestModel struct {
	Page     string `json:"page"`
	PageSize string `json:"pageSize"`
}

列表批量取得Project的请求参数

type ProjectListResultModel

type ProjectListResultModel struct {
	Total      int                  `json:"total"`
	Datapoints []ProjectResultModel `json:"datapoints"`
}

取得多个project的结构

type ProjectModel

type ProjectModel struct {
	ProjectName  string `json:"projectName"`
	ProjectDesc  string `json:"projectDesc"`
	ProjectOwner string `json:"projectOwner"`
}

project的实体类,主要用于发送请求,更新或者添加Project

type ProjectResultModel

type ProjectResultModel struct {
	ProjectModel
	Id          int64  `json:"id"`
	GmtModified int64  `json:"gmtModified"`
	GmtCreate   int64  `json:"gmtCreate"`
	Status      int    `json:"status"`
	Creator     string `json:"creator"`
}

project返回实体,继承于ProjectModel

type ResultModel

type ResultModel struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Success bool   `json:"success"`
}

调用接口返回的实体 新增加的结构首字母一定要大写,否则json编码或者解析编码会出现问题

type UpdateAlarmArgs

type UpdateAlarmArgs struct {
	Id                 string //报警规则的id
	Name               string //报警规则名称
	Period             int    //查询指标的周期,必须与定义的metric一致,默认300,单位为秒
	Statistics         string //统计方法,必须与定义的metric一致,例如Average
	ComparisonOperator string //报警比较符,只能为以下几种<=,<,>,>=,==,!=
	Threshold          string //报警阈值,目前只开放数值类型功能
	EvaluationCount    int    //连续探测几次都满足阈值条件时报警,默认3次
	ContactGroups      string //报警规则通知的联系组,必须在控制台上已创建,为json array对应的string,例如 [“联系组1”,”联系组2”]
	StartTime          int    //报警生效时间的开始时间,默认0,代表0点
	EndTime            int    //报警生效时间的结束时间,默认24,代表24点
	SilenceTime        int    //一直处于报警状态的通知沉默周期,默认86400,单位s,最小1小时
	NotifyType         int    //通知类型,为0是旺旺+邮件,为1是旺旺+邮件+短信
}

type UpdateAlarmResponse

type UpdateAlarmResponse struct {
	CommonAlarmResponse
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL