Merge pull request #149 from yunify/add-alarm-notification-api

add-alarm-notification-api
This commit is contained in:
roger 2020-02-05 16:41:13 +08:00 committed by GitHub
commit bdce532d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 0 deletions

122
service/notification.go Normal file
View File

@ -0,0 +1,122 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"fmt"
"time"
"github.com/yunify/qingcloud-sdk-go/config"
"github.com/yunify/qingcloud-sdk-go/request"
"github.com/yunify/qingcloud-sdk-go/request/data"
"github.com/yunify/qingcloud-sdk-go/request/errors"
)
var _ fmt.State
var _ time.Time
type NotificationService struct {
Config *config.Config
Properties *NotificationServiceProperties
}
type NotificationServiceProperties struct {
// QingCloud Zone ID
Zone *string `json:"zone" name:"zone"` // Required
}
func (s *QingCloudService) Notification(zone string) (*NotificationService, error) {
properties := &NotificationServiceProperties{
Zone: &zone,
}
return &NotificationService{Config: s.Config, Properties: properties}, nil
}
func (s *NotificationService) SendAlarmNotification(i *SendAlarmNotificationInput) (*SendAlarmNotificationOutput, error) {
if i == nil {
i = &SendAlarmNotificationInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "SendAlarmNotification",
RequestMethod: "GET",
}
x := &SendAlarmNotificationOutput{}
r, err := request.New(o, i, x)
if err != nil {
return nil, err
}
err = r.Send()
if err != nil {
return nil, err
}
return x, err
}
type SendAlarmNotificationInput struct {
NotificationData []*NotificationData `json:"notification_data" name:"notification_data" location:"params"` // Required
NotificationListID *string `json:"notification_list_id" name:"notification_list_id" location:"params"` // Required
ResourceID *string `json:"resource_id" name:"resource_id" location:"params"`
ResourceName *string `json:"resource_name" name:"resource_name" location:"params"`
ResourceType *string `json:"resource_type" name:"resource_type" location:"params"`
UserID *string `json:"user_id" name:"user_id" location:"params"` // Required
}
func (v *SendAlarmNotificationInput) Validate() error {
if len(v.NotificationData) == 0 {
return errors.ParameterRequiredError{
ParameterName: "NotificationData",
ParentName: "SendAlarmNotificationInput",
}
}
if len(v.NotificationData) > 0 {
for _, property := range v.NotificationData {
if err := property.Validate(); err != nil {
return err
}
}
}
if v.NotificationListID == nil {
return errors.ParameterRequiredError{
ParameterName: "NotificationListID",
ParentName: "SendAlarmNotificationInput",
}
}
if v.UserID == nil {
return errors.ParameterRequiredError{
ParameterName: "UserID",
ParentName: "SendAlarmNotificationInput",
}
}
return nil
}
type SendAlarmNotificationOutput struct {
Message *string `json:"message" name:"message"`
Action *string `json:"action" name:"action" location:"elements"`
RetCode *int `json:"ret_code" name:"ret_code" location:"elements"`
}

View File

@ -1850,6 +1850,19 @@ func (v *NICVxNet) Validate() error {
return nil
}
type NotificationData struct {
AlarmPolicy *string `json:"alarm_policy" name:"alarm_policy"`
PrevStatus *string `json:"prev_status" name:"prev_status"`
Rules *string `json:"rules" name:"rules"`
TriggerStatus *string `json:"trigger_status" name:"trigger_status"`
UserID *string `json:"user_id" name:"user_id"`
}
func (v *NotificationData) Validate() error {
return nil
}
type Project struct {
ConsoleID *string `json:"console_id" name:"console_id"`
CreateTime *string `json:"create_time" name:"create_time"`