From 0617ac977514e9faf17d8c467e8826b10a1cda2c Mon Sep 17 00:00:00 2001 From: huyujie Date: Wed, 5 Feb 2020 16:27:50 +0800 Subject: [PATCH] add-alarm-notification-api --- service/notification.go | 122 ++++++++++++++++++++++++++++++++++++++++ service/types.go | 13 +++++ 2 files changed, 135 insertions(+) create mode 100644 service/notification.go diff --git a/service/notification.go b/service/notification.go new file mode 100644 index 0000000..12382e8 --- /dev/null +++ b/service/notification.go @@ -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"` +} diff --git a/service/types.go b/service/types.go index 12af3a5..ef53212 100644 --- a/service/types.go +++ b/service/types.go @@ -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"`