mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-24 02:15:50 +08:00
1. Config Verify 和 Contact 的 InitalizeData 写得过于直接了。 会导致正常的数据被覆盖。实际上,数据的Init只需要更换数据 库的时候更新,如何判断数据库要被更新了,就是判断新出现的 column 有没有非零值的,如果有,就说明数据库不是第一次更新。 2. 前端的请求经过yunionapi,最终会调用climc里面注册的ResourceManager, 所以这个地方一定要和后端的参数处理统一。之前因为添加 uname 的支持破坏了这个地方的统一,虽然climc可以调用成功但是前端接口调用会失败。 3. Resend 的bug,会导致任务的阻塞。 4. 为了兼容kapacitor对climc notify的调用,分成了notify和notify-batch两个命令。
91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
// Copyright 2019 Yunion
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License 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 shell
|
|
|
|
import (
|
|
"yunion.io/x/jsonutils"
|
|
|
|
"yunion.io/x/onecloud/pkg/mcclient"
|
|
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
|
"yunion.io/x/onecloud/pkg/mcclient/options"
|
|
)
|
|
|
|
func init() {
|
|
type NotifyTemplateUpdateOptions struct {
|
|
CONTACTTYPE string `help:"the contanct type, such as 'email', 'mobile'"`
|
|
TOPIC string `help:"the topic of temlate, such as 'VERIFY', 'ALARM'"`
|
|
TEMPLATETYPE string `help:"the type of template" choices:"content|title|remote"`
|
|
CONTENT string `help:"the content of template"`
|
|
}
|
|
R(&NotifyTemplateUpdateOptions{}, "notify-template-update", "Create, update contact for user", func(s *mcclient.ClientSession,
|
|
args *NotifyTemplateUpdateOptions) error {
|
|
arr := jsonutils.NewArray()
|
|
tmpObj := jsonutils.NewDict()
|
|
tmpObj.Add(jsonutils.NewString(args.TOPIC), "topic")
|
|
tmpObj.Add(jsonutils.NewString(args.TEMPLATETYPE), "template_type")
|
|
tmpObj.Add(jsonutils.NewString(args.CONTENT), "content")
|
|
arr.Add(tmpObj)
|
|
|
|
params := jsonutils.NewDict()
|
|
params.Add(arr, "notifytemplates")
|
|
|
|
contact, err := modules.NotifyTemplates.PerformAction(s, args.CONTACTTYPE, "update-template", params)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
printObject(contact)
|
|
return nil
|
|
})
|
|
|
|
type NotifyTemplateDeleteOptions struct {
|
|
CONTACTTYPE string `help:"the contanct type, such as 'email', 'mobile'"`
|
|
Topic string `help:"the topic of temlate, such as 'VERIFY', 'ALARM'"`
|
|
}
|
|
|
|
R(&NotifyTemplateDeleteOptions{}, "notify-template-delete", "delete notify template",
|
|
func(s *mcclient.ClientSession, args *NotifyTemplateDeleteOptions) error {
|
|
|
|
tmpObj := jsonutils.NewDict()
|
|
tmpObj.Add(jsonutils.NewString(args.CONTACTTYPE), "contact_type")
|
|
tmpObj.Add(jsonutils.NewString(args.Topic), "topic")
|
|
_, err := modules.NotifyTemplates.DeleteContents(s, tmpObj)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
})
|
|
|
|
type NotifyTemplateListOptions struct {
|
|
options.BaseListOptions
|
|
}
|
|
|
|
R(&NotifyTemplateListOptions{}, "notify-template-list", "List all notify template",
|
|
func(s *mcclient.ClientSession, args *NotifyTemplateListOptions) error {
|
|
|
|
params, err := args.BaseListOptions.Params()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
result, err := modules.NotifyTemplates.List(s, params)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
printList(result, modules.NotifyTemplates.GetColumns(s))
|
|
return nil
|
|
})
|
|
}
|