aliyungo: github.com/denverdino/aliyungo/cms Index | Files | Directories

package cms

import "github.com/denverdino/aliyungo/cms"

Index

Package Files

alarm.go alerts.go apiproxy.go client.go project.go

Constants

const (
    HEADER_SEPERATER = "\n"
    ACS_PREFIX       = "x-acs"
)
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"
)

func BodyMd5 Uses

func BodyMd5(jsonstring string) string

*

* 对json进行md5 base64

func GetRequestPath Uses

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

*

* 取得上下文请求路径

func InitBaseHeader Uses

func InitBaseHeader(v *http.Request)

*

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

type ActionGroup Uses

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

type ActionsModel Uses

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

type AlarmHistoryItem Uses

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 Uses

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

    CommonAlarmItem
}

type AlertActionsModel Uses

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

type AlertRequest Uses

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 Uses

type CMSClient struct {
    common.Client
}

func NewCMSClient Uses

func NewCMSClient(accessKeyId, accessKeySecret string) *CMSClient

NewClient creates a new instance of CMS client

func NewCMSRegionClient Uses

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

func NewClientWithEndpoint Uses

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

func NewClientWithRegion Uses

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

func (*CMSClient) CreateAlarm Uses

func (client *CMSClient) CreateAlarm(args *CreateAlarmArgs) (*CreateAlarmResponse, error)

see doc at https://help.aliyun.com/document_detail/51910.html?spm=5176.doc51912.6.627.61vKOf

func (*CMSClient) DeleteAlarm Uses

func (client *CMSClient) DeleteAlarm(id string) error

see doc at https://help.aliyun.com/document_detail/51912.html?spm=5176.doc51915.6.628.ozEQet

func (*CMSClient) DisableAlarm Uses

func (client *CMSClient) DisableAlarm(id string) error

see doc at https://help.aliyun.com/document_detail/51914.html?spm=5176.doc51915.6.630.YUybwN

func (*CMSClient) EnableAlarm Uses

func (client *CMSClient) EnableAlarm(id string) error

see doc at https://help.aliyun.com/document_detail/51913.html?spm=5176.doc51910.6.631.3zgHyK

func (*CMSClient) ListAlarm Uses

func (client *CMSClient) ListAlarm(args *ListAlarmArgs) (*ListAlarmResponse, error)

see doc at https://help.aliyun.com/document_detail/51915.html?spm=5176.doc51914.6.629.Yz4ZjF

func (*CMSClient) ListAlarmHistory Uses

func (client *CMSClient) ListAlarmHistory(args *ListAlarmHistoryArgs) (*ListAlarmHistoryResponse, error)

see doc at https://help.aliyun.com/document_detail/51916.html?spm=5176.doc51911.6.633.KPOcwc

func (*CMSClient) ListContactGroup Uses

func (client *CMSClient) ListContactGroup(args *ListContactGroupArgs) (*ListContactGroupResponse, error)

see doc at https://help.aliyun.com/document_detail/52315.html?spm=5176.doc51916.6.634.TDR72G

func (*CMSClient) UpdateAlarm Uses

func (client *CMSClient) UpdateAlarm(args *UpdateAlarmArgs) error

see doc at https://help.aliyun.com/document_detail/51911.html?spm=5176.doc51913.6.632.IgBO9g

type Client Uses

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

func NewClient Uses

func NewClient(accessKeyId, accessKeySecret string) *Client

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

func (*Client) CreateAlert Uses

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 Uses

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

func (*Client) CreateAlertDimension Uses

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

func (*Client) CreateProject Uses

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 Uses

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

*

*

func (*Client) DeleteAlertDimension Uses

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

func (*Client) DeleteProject Uses

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

*

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

func (*Client) GetAccessKey Uses

func (client *Client) GetAccessKey() string

func (*Client) GetAccessSecret Uses

func (client *Client) GetAccessSecret() string

func (*Client) GetAlert Uses

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

* 取得一个alert

func (*Client) GetAlertList Uses

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

*

* 取得alertl列表

func (*Client) GetApiUri Uses

func (client *Client) GetApiUri() string

func (*Client) GetDimensions Uses

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

func (*Client) GetProject Uses

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

*

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

func (*Client) GetProjectList Uses

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 Uses

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

*

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

func (*Client) GetUrl Uses

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

*

* 去的要请求的url

func (*Client) PutMetrics Uses

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

func (*Client) SetDebug Uses

func (client *Client) SetDebug(debug bool)

func (*Client) SetSecurityToken Uses

func (client *Client) SetSecurityToken(securityToken string)

func (*Client) SetTransport Uses

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

SetTransport sets transport to the http client

func (*Client) Sign Uses

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 Uses

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

*

* 更新Alert

func (*Client) UpdateProject Uses

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 Uses

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 Uses

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

type ConditionModel Uses

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 Uses

type CreateAlarmArgs struct {
    CommonAlarmItem
}

type CreateAlarmResponse Uses

type CreateAlarmResponse struct {
    CommonAlarmResponse
    Data string
}

type DeleteAlarmArgs Uses

type DeleteAlarmArgs struct {
    Id string
}

type DeleteAlarmResponse Uses

type DeleteAlarmResponse struct {
    CommonAlarmResponse
    Data string
}

type DimensionDataPoint Uses

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 Uses

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

type DisableAlarmArgs Uses

type DisableAlarmArgs struct {
    Id string
}

type DisableAlarmResponse Uses

type DisableAlarmResponse struct {
    CommonAlarmResponse
}

type EnableAlarmArgss Uses

type EnableAlarmArgss struct {
    Id string
}

type EnableAlarmResponse Uses

type EnableAlarmResponse struct {
    CommonAlarmResponse
}

type EscalationsModel Uses

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

type Failure Uses

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

type GetDimenstionResult Uses

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 Uses

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

返回的实体类型

type ListAlarmArgs Uses

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 Uses

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 Uses

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

type ListAlarmResponse Uses

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

type ListContactGroupArgs Uses

type ListContactGroupArgs struct {
    common.Pagination
}

type ListContactGroupResponse Uses

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

type ListProjectRequestModel Uses

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

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

type ProjectListResultModel Uses

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

取得多个project的结构

type ProjectModel Uses

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

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

type ProjectResultModel Uses

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 Uses

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

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

type UpdateAlarmArgs Uses

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 Uses

type UpdateAlarmResponse struct {
    CommonAlarmResponse
}

Directories

PathSynopsis
bytesbuffer
util

Package cms imports 14 packages (graph) and is imported by 1 packages. Updated 2020-02-05. Refresh now. Tools for package owners.