Skip to content

Commit

Permalink
add-alarm-notification-api
Browse files Browse the repository at this point in the history
  • Loading branch information
huyujie committed Feb 5, 2020
1 parent 7342aed commit 0617ac9
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
122 changes: 122 additions & 0 deletions service/notification.go
Original file line number Diff line number Diff line change
@@ -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"`
}
13 changes: 13 additions & 0 deletions service/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 0617ac9

Please sign in to comment.