Skip to content

Commit 92d0144

Browse files
committed
{{kvs}} -> {{msg}}
1 parent be052d0 commit 92d0144

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

doc/CONFIG.jsonc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
// body_regex: regex to match the response body
7979
// code: response code to match
8080
//
81-
// {{kvs}} will be replaced with the key and value of the check
81+
// Format args:
82+
// "{{msg}}" will be replaced with the message of the check result
8283
"pushes": [
8384
{
8485
// This is a example for QQ Group message
@@ -100,7 +101,7 @@
100101
"action": "send_group_msg",
101102
"params": {
102103
"group_id": 123456789,
103-
"message": "ServerBox Notification\n{{kvs}}"
104+
"message": "Server name\n{{msg}}"
104105
}
105106
},
106107
// Check push is successful or not:
@@ -118,8 +119,8 @@
118119
"name": "ServerBox iOS App",
119120
// You can get it from settings page of ServerBox iOS app
120121
"token": "YOUR_TOKEN",
121-
"title": "Server Notification",
122-
"content": "{{kvs}}",
122+
"title": "Server name",
123+
"content": "{{msg}}",
123124
"body_regex": ".*",
124125
"code": 200
125126
}
@@ -131,7 +132,7 @@
131132
// Details please refer to https://sct.ftqq.com/
132133
"sckey": "YOUR_SCKEY",
133134
"title": "Server Notification",
134-
"desp": "{{kvs}}",
135+
"desp": "{{msg}}",
135136
"body_regex": ".*",
136137
"code": 200
137138
}

doc/CONFIG_zh.jsonc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
// 接口 iface: 推送类型的接口
7676
// body_regex: 正则表达式匹配响应体
7777
// code: 响应码匹配
78+
//
79+
// 格式化参数:
80+
// "{{msg}}" 将被替换为监测结果的消息
7881
"pushes": [
7982
{
8083
// 这是一个推送到QQ群的例子
@@ -96,7 +99,7 @@
9699
"action": "send_group_msg",
97100
"params": {
98101
"group_id": 123456789,
99-
"message": "ServerBox Notification\n{{key}}: {{value}}"
102+
"message": "服务器1 提示\n{{msg}}"
100103
}
101104
},
102105
// 推送校验:
@@ -114,8 +117,8 @@
114117
"name": "ServerBox iOS App",
115118
// 你可以从 ServerBox iOS app 的 设置 中获取 token
116119
"token": "YOUR_TOKEN",
117-
"title": "Server Notification",
118-
"content": "{{key}}: {{value}}",
120+
"title": "服务器1 提示",
121+
"content": "{{msg}}",
119122
"body_regex": ".*",
120123
"code": 200
121124
}
@@ -126,8 +129,8 @@
126129
"name": "Server酱",
127130
// 具体配置请参考 https://sct.ftqq.com/
128131
"sckey": "YOUR_SCKEY",
129-
"title": "Server Notification",
130-
"desp": "{{key}}: {{value}}",
132+
"title": "服务器1 提示",
133+
"desp": "{{msg}}",
131134
"body_regex": ".*",
132135
"code": 200
133136
}

model/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ReadAppConfig() error {
3434
defer initInterval()
3535
defer initRateLimiter()
3636
if !sys.Exist(res.AppConfigPath) {
37-
configBytes, err := json.MarshalIndent(DefaultappConfig, "", "\t")
37+
configBytes, err := json.MarshalIndent(DefaultAppConfig, "", "\t")
3838
if err != nil {
3939
log.Err("[CONFIG] marshal default app config failed: %v", err)
4040
return err
@@ -44,7 +44,7 @@ func ReadAppConfig() error {
4444
log.Err("[CONFIG] write default app config failed: %v", err)
4545
return err
4646
}
47-
Config = DefaultappConfig
47+
Config = DefaultAppConfig
4848
return nil
4949
}
5050

@@ -56,7 +56,7 @@ func ReadAppConfig() error {
5656
err = json.Unmarshal(configBytes, Config)
5757
if err != nil {
5858
log.Err("[CONFIG] unmarshal app config failed: %v", err)
59-
} else if Config.Version < DefaultappConfig.Version {
59+
} else if Config.Version < DefaultAppConfig.Version {
6060
log.Warn("[CONFIG] app config version is too old, new config will be generated")
6161
// Backup old config
6262
err = os.WriteFile(res.AppConfigPath+".bak", configBytes, 0644)
@@ -65,7 +65,7 @@ func ReadAppConfig() error {
6565
return err
6666
}
6767
// Generate new config
68-
configBytes, err := json.MarshalIndent(DefaultappConfig, "", "\t")
68+
configBytes, err := json.MarshalIndent(DefaultAppConfig, "", "\t")
6969
if err != nil {
7070
panic(err)
7171
}
@@ -121,7 +121,7 @@ var (
121121
"action": "send_group_msg",
122122
"params": map[string]interface{}{
123123
"group_id": 123456789,
124-
"message": "ServerBox Notification\n{{kvs}}",
124+
"message": "Server1\n"+res.PushFormatLocator,
125125
},
126126
}
127127
defaultWekhookBodyBytes, _ = json.Marshal(defaultWebhookBody)
@@ -138,7 +138,7 @@ var (
138138
}
139139
defaultWebhookIfaceBytes, _ = json.Marshal(defaultWebhookIface)
140140

141-
DefaultappConfig = &AppConfig{
141+
DefaultAppConfig = &AppConfig{
142142
Version: 2,
143143
Interval: "7s",
144144
Rate: "1/1m",

model/push.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/lollipopkit/gommon/http"
12+
"github.com/lollipopkit/server_box_monitor/res"
1213
)
1314

1415
type Push struct {
@@ -74,7 +75,10 @@ func (pf PushFormat) Format(args []*PushPair) string {
7475
kv := fmt.Sprintf(`%s\n%s: %s`, arg.time, arg.key, arg.value)
7576
ss = append(ss, kv)
7677
}
77-
return strings.Replace(string(pf), "{{kvs}}", strings.Join(ss, `\n`), 1)
78+
return strings.Replace(
79+
string(pf),
80+
res.PushFormatLocator,
81+
strings.Join(ss, `\n`), 1)
7882
}
7983

8084
type PushType string

model/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Rule struct {
3131
}
3232

3333
func (r *Rule) Id() string {
34-
return fmt.Sprintf("[%s %s %s]", r.MonitorType, r.Threshold, r.Matcher)
34+
return fmt.Sprintf("Rule(%s %s %s)", r.MonitorType, r.Threshold, r.Matcher)
3535
}
3636
func (r *Rule) ShouldNotify(s *serverStatus) (bool, *PushPair, error) {
3737
t, err := ParseToThreshold(r.Threshold)

res/res.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
const (
3636
DefaultInterval = time.Second * 7
3737
MaxInterval = time.Second * 10
38+
39+
PushFormatLocator = "{{msg}}"
3840
)
3941

4042
func init() {

0 commit comments

Comments
 (0)