feat(climc): add notify-event-send

This commit is contained in:
rainzm
2022-04-01 19:00:59 +08:00
parent 53ec0d052e
commit b38148c2d6
+28
View File
@@ -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
})
}