1 Star 0 Fork 0

telemetry_devops/告警管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
feishu.go 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
liaopeng495 提交于 2021-10-26 19:06 . fix congig
package user_bot
import (
"errors"
"strings"
"gitee.com/monitor_dev/alerts-management/alerts-notifyer/dropbox"
"gitee.com/monitor_dev/alerts-management/alerts-notifyer/pkg/logger"
"gitee.com/monitor_dev/alerts-management/alerts-notifyer/pkg/utils"
"github.com/spf13/viper"
)
func FeishuSendCommMsg(alert *dropbox.AlertPostCommApi) error {
// 获取联系人信息
emails := strings.FieldsFunc(utils.Get(alert.Labels, "flybook_emails"), utils.Split)
mobiles := strings.FieldsFunc(utils.Get(alert.Labels, "flybook_mobiles"), utils.Split)
if len(mobiles) == 0 && len(emails) == 0 {
logger.Info("mobile and email is all nil ,skip")
return nil
}
contactMap := map[string][]string{"emails": emails, "mobiles": mobiles}
contactList := feishuBot.GetUserId(contactMap)
if len(contactList) == 0 {
logger.Error("use mobile and email to get userid is nil ,mobiles:", mobiles, " emails", emails)
return errors.New("use mobile and email to get userid is nil ,sent msg failed")
}
err := feishuBot.FeishuMsgBatchSendWithPost(*alert, contactList)
if err != nil {
logger.Error("feishuBot.FeishuMsgBatchSendWithPost failed by: ", err.Error())
return err
}
return nil
}
func FeishuSendCommMsgV2(alert *dropbox.CommonAlert, groups []interface{}) error {
content := dropbox.CommAlertToFeishuPostTemplateV1(alert)
var ChatIds []string
for _, group := range groups {
chatID := viper.GetString(strings.Join([]string{"feishu.group", group.(string), "chatid"}, "."))
if chatID != "" {
ChatIds = append(ChatIds, chatID)
}
}
if len(ChatIds) == 0 {
logger.Error("len(ChatIds) == 0")
}
logger.Info("chaids : %v", ChatIds)
return feishuBot.FeishuMsgCardBatchSend(content, ChatIds)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/monitor_dev/alerts-management.git
git@gitee.com:monitor_dev/alerts-management.git
monitor_dev
alerts-management
告警管理系统
efd361bf1003

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385