This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 5fb30dc8 [horus] Add alarm framework (#325)
5fb30dc8 is described below
commit 5fb30dc8d3376423cfe104a9a3bdcd450f07c5a9
Author: mfordjody <[email protected]>
AuthorDate: Sat Sep 7 18:19:02 2024 +0800
[horus] Add alarm framework (#325)
Add License Check
---
app/horus/basic/config/file.go | 16 ++++-
app/horus/core/alert/dingtalk.go | 74 ++++++++++++++++++++++
.../{basic/config/file.go => core/alert/slack.go} | 13 +---
deploy/horus/horus.yaml | 13 +++-
4 files changed, 103 insertions(+), 13 deletions(-)
diff --git a/app/horus/basic/config/file.go b/app/horus/basic/config/file.go
index 4cd24a27..5b2767a6 100644
--- a/app/horus/basic/config/file.go
+++ b/app/horus/basic/config/file.go
@@ -16,8 +16,10 @@
package config
type Config struct {
- HttpAddr string `yaml:"HttpAddr"`
- Mysql *MysqlConfiguration `yaml:"Mysql"`
+ Address string `yaml:"address"`
+ Mysql *MysqlConfiguration `yaml:"mysql"`
+ DingTalk *DingTalkConfiguration `yaml:"dingTalk"`
+ Slack *SlackConfiguration `yaml:"slack"`
}
type MysqlConfiguration struct {
@@ -25,3 +27,13 @@ type MysqlConfiguration struct {
Addr string `yaml:"addr"`
Debug bool `yaml:"debug"`
}
+
+type DingTalkConfiguration struct {
+ WebhookUrl string `yaml:"webhookUrl"`
+ Title string `yaml:"title"`
+ AtMobiles []string `yaml:"atMobiles"`
+}
+
+type SlackConfiguration struct {
+ WebhookUrl string `yaml:"webhookUrl"`
+}
diff --git a/app/horus/core/alert/dingtalk.go b/app/horus/core/alert/dingtalk.go
new file mode 100644
index 00000000..75b16e5b
--- /dev/null
+++ b/app/horus/core/alert/dingtalk.go
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You 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 alert
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "github.com/apache/dubbo-kubernetes/app/horus/basic/config"
+ "k8s.io/klog/v2"
+ "net/http"
+)
+
+const Title = "钉钉机器人"
+
+type content struct {
+ Content string `json:"content"`
+}
+
+type at struct {
+ AtMobiles []string `json:"atMobiles"`
+}
+
+type Message struct {
+ MessageType string `json:"messageType"`
+ Text content `json:"text"`
+ At at `json:"at"`
+}
+
+type T struct {
+ At struct {
+ AtMobiles []string `json:"atMobiles"`
+ AtUserIds []string `json:"atUserIds"`
+ IsAtAll bool `json:"isAtAll"`
+ } `json:"at"`
+ Text struct {
+ Content string `json:"content"`
+ } `json:"text"`
+ Msgtype string `json:"msgtype"`
+}
+
+func DingTalkSend(dk *config.DingTalkConfiguration, msg string) {
+ dtm := Message{MessageType: "text"}
+ dtm.Text.Content = fmt.Sprintf("%s\n"+
+ "【日志详细信息:%s】", Title, msg)
+ dtm.At.AtMobiles = dk.AtMobiles
+ bs, err := json.Marshal(dtm)
+ if err != nil {
+ klog.Errorf("dingTalk json marshal err:%v\n msg:%v\n", err, msg)
+ return
+ }
+ res, err := http.Post(dk.WebhookUrl, "application/json",
bytes.NewBuffer(bs))
+ if err != nil {
+ klog.Errorf("push dingTalk err:%v\n msg:%v\n", err, msg)
+ }
+ if res.StatusCode != 200 && res != nil {
+ klog.Errorf("push dingTalk status code err:%v\n code:%v\n
msg:%v\n", err, res.StatusCode, msg)
+ return
+ }
+ klog.Infof("push dingTalk success code:%v\n msg:%v\n", res.StatusCode,
msg)
+}
diff --git a/app/horus/basic/config/file.go b/app/horus/core/alert/slack.go
similarity index 75%
copy from app/horus/basic/config/file.go
copy to app/horus/core/alert/slack.go
index 4cd24a27..867a5cd2 100644
--- a/app/horus/basic/config/file.go
+++ b/app/horus/core/alert/slack.go
@@ -13,15 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package config
+package alert
-type Config struct {
- HttpAddr string `yaml:"HttpAddr"`
- Mysql *MysqlConfiguration `yaml:"Mysql"`
-}
+import "github.com/apache/dubbo-kubernetes/app/horus/basic/config"
-type MysqlConfiguration struct {
- Name string `yaml:"name"`
- Addr string `yaml:"addr"`
- Debug bool `yaml:"debug"`
-}
+func SlackSend(sk *config.SlackConfiguration) {}
diff --git a/deploy/horus/horus.yaml b/deploy/horus/horus.yaml
index 707fff91..12c4ee80 100644
--- a/deploy/horus/horus.yaml
+++ b/deploy/horus/horus.yaml
@@ -18,4 +18,15 @@ address: 0.0.0.0:38089
mysql:
name: horus
addr: "root:root@tcp(127.0.0.1:3306)/horus?charset=utf8&parseTime=True"
- debug: false
\ No newline at end of file
+ debug: false
+
+dingTalk:
+ webhookUrl:
"https://oapi.dingtalk.com/robot/send?access_token=aa2f3f74d7a2504653ca89b7a673707ba1d04b6d9d320c3572e5464d8f81471e"
+ title: "工单通知处理"
+ atMobiles:
+ - 1500000000
+
+slack:
+ webhookUrl: ~
+ proxy: ~
+ payload: ~
\ No newline at end of file