From b38148c2d6b2df41e949a36a8e130c2f1b719d74 Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 1 Apr 2022 18:49:49 +0800 Subject: [PATCH] feat(climc): add notify-event-send --- cmd/climc/shell/notifyv2/notification.go | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmd/climc/shell/notifyv2/notification.go b/cmd/climc/shell/notifyv2/notification.go index 9ded117fa9..1638d25b22 100644 --- a/cmd/climc/shell/notifyv2/notification.go +++ b/cmd/climc/shell/notifyv2/notification.go @@ -15,6 +15,8 @@ package notifyv2 import ( + "fmt" + "yunion.io/x/jsonutils" api "yunion.io/x/onecloud/pkg/apis/notify" @@ -100,4 +102,30 @@ func init() { printList(ret, modules.Notification.GetColumns(s)) return nil }) + type NotificationEventInput struct { + Event string + Priority string + MsgBody string + } + R(&NotificationEventInput{}, "notify-event-send", "Send notify event message", func(s *mcclient.ClientSession, args *NotificationEventInput) error { + body, err := jsonutils.ParseString(args.MsgBody) + if err != nil { + return err + } + dict, ok := body.(*jsonutils.JSONDict) + if !ok { + return fmt.Errorf("msg_body should be a json string, like '{'name': 'hello'}'") + } + params := api.NotificationManagerEventNotifyInput{ + ReceiverIds: []string{}, + ResourceDetails: dict, + Event: args.Event, + Priority: args.Priority, + } + _, err = modules.Notification.PerformClassAction(s, "event-notify", jsonutils.Marshal(params)) + if err != nil { + return fmt.Errorf("unable to EventNotify: %s", err) + } + return nil + }) }