add zh_TW locale, rename ssl to tls

This commit is contained in:
uubulb 2024-11-01 14:07:05 +08:00
parent 5114fc2854
commit ca997cc994
17 changed files with 455 additions and 62 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@
*.test *.test
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*~
*.out *.out
*.pprof *.pprof
.idea .idea

View File

@ -299,8 +299,8 @@ func (ma *memberAPI) addOrEditNotification(c *gin.Context) {
n.RequestHeader = nf.RequestHeader n.RequestHeader = nf.RequestHeader
n.RequestBody = nf.RequestBody n.RequestBody = nf.RequestBody
n.URL = nf.URL n.URL = nf.URL
verifySSL := nf.VerifySSL == "on" //verifySSL := nf.VerifySSL == "on"
n.VerifySSL = &verifySSL //n.VerifySSL = &verifySSL
n.ID = nf.ID n.ID = nf.ID
ns := model.NotificationServerBundle{ ns := model.NotificationServerBundle{
Notification: &n, Notification: &n,

View File

@ -54,8 +54,8 @@ func createNotification(c *gin.Context) (uint64, error) {
n.RequestHeader = nf.RequestHeader n.RequestHeader = nf.RequestHeader
n.RequestBody = nf.RequestBody n.RequestBody = nf.RequestBody
n.URL = nf.URL n.URL = nf.URL
verifySSL := nf.VerifySSL verifyTLS := nf.VerifyTLS
n.VerifySSL = &verifySSL n.VerifyTLS = &verifyTLS
ns := model.NotificationServerBundle{ ns := model.NotificationServerBundle{
Notification: &n, Notification: &n,
@ -112,8 +112,8 @@ func updateNotification(c *gin.Context) (any, error) {
n.RequestHeader = nf.RequestHeader n.RequestHeader = nf.RequestHeader
n.RequestBody = nf.RequestBody n.RequestBody = nf.RequestBody
n.URL = nf.URL n.URL = nf.URL
verifySSL := nf.VerifySSL verifyTLS := nf.VerifyTLS
n.VerifySSL = &verifySSL n.VerifyTLS = &verifyTLS
ns := model.NotificationServerBundle{ ns := model.NotificationServerBundle{
Notification: &n, Notification: &n,

View File

@ -38,7 +38,7 @@ type Notification struct {
RequestType int `json:"request_type,omitempty"` RequestType int `json:"request_type,omitempty"`
RequestHeader string `json:"request_header,omitempty" gorm:"type:longtext"` RequestHeader string `json:"request_header,omitempty" gorm:"type:longtext"`
RequestBody string `json:"request_body,omitempty" gorm:"type:longtext"` RequestBody string `json:"request_body,omitempty" gorm:"type:longtext"`
VerifySSL *bool `json:"verify_ssl,omitempty"` VerifyTLS *bool `json:"verify_tls,omitempty"`
} }
func (ns *NotificationServerBundle) reqURL(message string) string { func (ns *NotificationServerBundle) reqURL(message string) string {
@ -111,7 +111,7 @@ func (n *Notification) setRequestHeader(req *http.Request) error {
func (ns *NotificationServerBundle) Send(message string) error { func (ns *NotificationServerBundle) Send(message string) error {
var client *http.Client var client *http.Client
n := ns.Notification n := ns.Notification
if n.VerifySSL != nil && *n.VerifySSL { if n.VerifyTLS != nil && *n.VerifyTLS {
client = utils.HttpClient client = utils.HttpClient
} else { } else {
client = utils.HttpClientSkipTlsVerify client = utils.HttpClientSkipTlsVerify

View File

@ -7,6 +7,6 @@ type NotificationForm struct {
RequestType int `json:"request_type,omitempty"` RequestType int `json:"request_type,omitempty"`
RequestHeader string `json:"request_header,omitempty"` RequestHeader string `json:"request_header,omitempty"`
RequestBody string `json:"request_body,omitempty"` RequestBody string `json:"request_body,omitempty"`
VerifySSL bool `json:"verify_ssl,omitempty"` VerifyTLS bool `json:"verify_tls,omitempty"`
SkipCheck bool `json:"skip_check,omitempty"` SkipCheck bool `json:"skip_check,omitempty"`
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-01 05:06+0800\n" "POT-Creation-Date: 2024-11-01 13:32+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -188,18 +188,18 @@ msgstr ""
#: service/singleton/servicesentinel.go:515 #: service/singleton/servicesentinel.go:515
#, c-format #, c-format
msgid "[SSL] Fetch cert info failed, %s %s" msgid "[TLS] Fetch cert info failed, Reporter: %s, Error: %s"
msgstr "" msgstr ""
#: service/singleton/servicesentinel.go:555 #: service/singleton/servicesentinel.go:555
#, c-format #, c-format
msgid "The SSL certificate will expire within seven days. Expiration time: %s" msgid "The TLS certificate will expire within seven days. Expiration time: %s"
msgstr "" msgstr ""
#: service/singleton/servicesentinel.go:568 #: service/singleton/servicesentinel.go:568
#, c-format #, c-format
msgid "" msgid ""
"SSL certificate changed, old: issuer %s, expires at %s; new: issuer %s, " "TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, "
"expires at %s" "expires at %s"
msgstr "" msgstr ""

View File

@ -8,8 +8,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-01 04:58+0800\n" "POT-Creation-Date: 2024-11-01 13:14+0800\n"
"PO-Revision-Date: 2024-11-01 05:05+0800\n" "PO-Revision-Date: 2024-11-01 13:20+0800\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: en_US\n" "Language: en_US\n"
@ -190,22 +190,21 @@ msgstr "[%s] %s Reporter: %s, Error: %s"
#: service/singleton/servicesentinel.go:515 #: service/singleton/servicesentinel.go:515
#, c-format #, c-format
msgid "[SSL] Fetch cert info failed, %s %s" msgid "[TLS] Fetch cert info failed, Reporter: %s, Error: %s"
msgstr "[SSL] Fetch cert info failed, %s %s" msgstr "[TLS] Fetch cert info failed, Reporter: %s, Error: %s"
#: service/singleton/servicesentinel.go:555 #: service/singleton/servicesentinel.go:555
#, c-format #, c-format
msgid "The SSL certificate will expire within seven days. Expiration time: %s" msgid "The TLS certificate will expire within seven days. Expiration time: %s"
msgstr "The SSL certificate will expire within seven days. Expiration time: %s" msgstr "The TLS certificate will expire within seven days. Expiration time: %s"
#: service/singleton/servicesentinel.go:568 #: service/singleton/servicesentinel.go:568
#, c-format #, c-format
#| msgid "SSL certificate changed, old: %s, %s expired; new: %s, %s expired."
msgid "" msgid ""
"SSL certificate changed, old: issuer %s, expires at %s; new: issuer %s, " "TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, "
"expires at %s" "expires at %s"
msgstr "" msgstr ""
"SSL certificate changed, old: issuer %s, expires at %s; new: issuer %s, " "TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, "
"expires at %s" "expires at %s"
#: service/singleton/servicesentinel.go:604 #: service/singleton/servicesentinel.go:604

View File

@ -8,8 +8,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-01 04:58+0800\n" "POT-Creation-Date: 2024-11-01 13:14+0800\n"
"PO-Revision-Date: 2024-11-01 05:05+0800\n" "PO-Revision-Date: 2024-11-01 13:20+0800\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: zh_CN\n" "Language: zh_CN\n"
@ -120,7 +120,7 @@ msgstr "服务 id %d 不存在"
#: cmd/dashboard/controller/user.go:45 #: cmd/dashboard/controller/user.go:45
msgid "password length must be greater than 6" msgid "password length must be greater than 6"
msgstr "密码长度必须大于6" msgstr "密码长度必须大于 6"
#: cmd/dashboard/controller/user.go:48 #: cmd/dashboard/controller/user.go:48
msgid "username can't be empty" msgid "username can't be empty"
@ -148,7 +148,7 @@ msgstr "计划任务执行失败"
#: service/rpc/nezha.go:156 #: service/rpc/nezha.go:156
msgid "IP Changed" msgid "IP Changed"
msgstr "IP变更" msgstr "IP 变更"
#: service/singleton/alertsentinel.go:159 #: service/singleton/alertsentinel.go:159
msgid "Incident" msgid "Incident"
@ -165,7 +165,7 @@ msgstr "注册失败的任务:["
#: service/singleton/crontask.go:59 #: service/singleton/crontask.go:59
msgid "" msgid ""
"] These tasks will not execute properly. Fix them in the admin dashboard." "] These tasks will not execute properly. Fix them in the admin dashboard."
msgstr "这些任务将无法正常执行,请进入后重新修改保存。" msgstr "这些任务将无法正常执行,请进入后重新修改保存。"
#: service/singleton/crontask.go:150 service/singleton/crontask.go:175 #: service/singleton/crontask.go:150 service/singleton/crontask.go:175
#, c-format #, c-format
@ -175,35 +175,35 @@ msgstr "[任务失败] %s服务器 %s 离线,无法执行"
#: service/singleton/servicesentinel.go:439 #: service/singleton/servicesentinel.go:439
#, c-format #, c-format
msgid "[Latency] %s %2f > %2f, Reporter: %s" msgid "[Latency] %s %2f > %2f, Reporter: %s"
msgstr "[延迟告警] %s %2f > %2f, 报告服务: %s" msgstr "[延迟告警] %s %2f > %2f报告服务: %s"
#: service/singleton/servicesentinel.go:446 #: service/singleton/servicesentinel.go:446
#, c-format #, c-format
msgid "[Latency] %s %2f < %2f, Reporter: %s" msgid "[Latency] %s %2f < %2f, Reporter: %s"
msgstr "[延迟告警] %s %2f < %2f, 报告服务: %s" msgstr "[延迟告警] %s %2f < %2f报告服务: %s"
#: service/singleton/servicesentinel.go:472 #: service/singleton/servicesentinel.go:472
#, c-format #, c-format
msgid "[%s] %s Reporter: %s, Error: %s" msgid "[%s] %s Reporter: %s, Error: %s"
msgstr "[%s] %s 报告服务: %s, 错误信息: %s" msgstr "[%s] %s 报告服务%s错误信息%s"
#: service/singleton/servicesentinel.go:515 #: service/singleton/servicesentinel.go:515
#, c-format #, c-format
msgid "[SSL] Fetch cert info failed, %s %s" msgid "[TLS] Fetch cert info failed, Reporter: %s, Error: %s"
msgstr "[SSL] 获取证书信息失败, %s %s" msgstr "[TLS] 获取证书信息失败,报告服务:%s错误信息%s"
#: service/singleton/servicesentinel.go:555 #: service/singleton/servicesentinel.go:555
#, c-format #, c-format
msgid "The SSL certificate will expire within seven days. Expiration time: %s" msgid "The TLS certificate will expire within seven days. Expiration time: %s"
msgstr "SSL 证书将在 7 天内过期。过期时间为:%s" msgstr "TLS 证书将在 7 天内过期。过期时间为:%s"
#: service/singleton/servicesentinel.go:568 #: service/singleton/servicesentinel.go:568
#, c-format #, c-format
msgid "" msgid ""
"SSL certificate changed, old: issuer %s, expires at %s; new: issuer %s, " "TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, "
"expires at %s" "expires at %s"
msgstr "" msgstr ""
"SSL 证书发生更改,旧值:颁发者 %s过期日 %s新值颁发者 %s过期日 %s" "TLS 证书发生更改,旧值:颁发者 %s过期日 %s新值颁发者 %s过期日 %s"
#: service/singleton/servicesentinel.go:604 #: service/singleton/servicesentinel.go:604
msgid "No Data" msgid "No Data"

Binary file not shown.

View File

@ -0,0 +1,222 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-01 13:14+0800\n"
"PO-Revision-Date: 2024-11-01 13:19+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.5\n"
#: cmd/dashboard/controller/alertrule.go:100
#, c-format
msgid "alert id %d does not exist"
msgstr "告警 ID %d 不存在"
#: cmd/dashboard/controller/alertrule.go:155
msgid "duration need to be at least 3"
msgstr "duration 至少為 3"
#: cmd/dashboard/controller/alertrule.go:159
msgid "cycle_interval need to be at least 1"
msgstr "cycle_interval 至少為 1"
#: cmd/dashboard/controller/alertrule.go:162
msgid "cycle_start is not set"
msgstr "cycle_start 未設定"
#: cmd/dashboard/controller/alertrule.go:165
msgid "cycle_start is a future value"
msgstr "cycle_start 是未來值"
#: cmd/dashboard/controller/alertrule.go:170
msgid "need to configure at least a single rule"
msgstr "需要至少定義一條規則"
#: cmd/dashboard/controller/controller.go:188
msgid "database error"
msgstr "資料庫錯誤"
#: cmd/dashboard/controller/cron.go:63 cmd/dashboard/controller/cron.go:122
msgid "scheduled tasks cannot be triggered by alarms"
msgstr "排程任務不能被告警觸發"
#: cmd/dashboard/controller/cron.go:161
#, c-format
msgid "task id %d does not exist"
msgstr "任務 id %d 不存在"
#: cmd/dashboard/controller/ddns.go:56 cmd/dashboard/controller/ddns.go:120
msgid "the retry count must be an integer between 1 and 10"
msgstr "重試次數必須為大於 1 且不超過 10 的整數"
#: cmd/dashboard/controller/ddns.go:79 cmd/dashboard/controller/ddns.go:148
msgid "error parsing %s: %v"
msgstr "解析 %s 時發生錯誤:%v"
#: cmd/dashboard/controller/ddns.go:125 cmd/dashboard/controller/nat.go:95
#, c-format
msgid "profile id %d does not exist"
msgstr "配置 id %d 不存在"
#: cmd/dashboard/controller/fm.go:45 cmd/dashboard/controller/terminal.go:43
msgid "server not found or not connected"
msgstr "伺服器未找到或仍未連線"
#: cmd/dashboard/controller/notification.go:67
#: cmd/dashboard/controller/notification.go:125
msgid "a test message"
msgstr "一條測試資訊"
#: cmd/dashboard/controller/notification.go:106
#, c-format
msgid "notification id %d does not exist"
msgstr "通知方式 id %d 不存在"
#: cmd/dashboard/controller/notification_group.go:80
#: cmd/dashboard/controller/notification_group.go:142
msgid "have invalid notification id"
msgstr "通知方式 id 無效"
#: cmd/dashboard/controller/notification_group.go:131
#: cmd/dashboard/controller/server_group.go:130
#, c-format
msgid "group id %d does not exist"
msgstr "組 id %d 不存在"
#: cmd/dashboard/controller/server.go:59
#, c-format
msgid "server id %d does not exist"
msgstr "伺服器 id %d 不存在"
#: cmd/dashboard/controller/server_group.go:78
#: cmd/dashboard/controller/server_group.go:139
msgid "have invalid server id"
msgstr "伺服器 id 無效"
#: cmd/dashboard/controller/service.go:79
#: cmd/dashboard/controller/service.go:155
msgid "server not found"
msgstr "未找到伺服器"
#: cmd/dashboard/controller/service.go:86
msgid "unauthorized"
msgstr "未授權"
#: cmd/dashboard/controller/service.go:247
#, c-format
msgid "service id %d does not exist"
msgstr "服務 id %d 不存在"
#: cmd/dashboard/controller/user.go:45
msgid "password length must be greater than 6"
msgstr "密碼長度必須大於 6"
#: cmd/dashboard/controller/user.go:48
msgid "username can't be empty"
msgstr "使用者名稱不能為空"
#: service/rpc/io_stream.go:122
msgid "timeout: no connection established"
msgstr "超時:無連線建立"
#: service/rpc/io_stream.go:125
msgid "timeout: user connection not established"
msgstr "超時:使用者連線未建立"
#: service/rpc/io_stream.go:128
msgid "timeout: agent connection not established"
msgstr "超時agent 連線未建立"
#: service/rpc/nezha.go:57
msgid "Scheduled Task Executed Successfully"
msgstr "排程任務執行成功"
#: service/rpc/nezha.go:61
msgid "Scheduled Task Executed Failed"
msgstr "排程任務執行失敗"
#: service/rpc/nezha.go:156
msgid "IP Changed"
msgstr "IP 變更"
#: service/singleton/alertsentinel.go:159
msgid "Incident"
msgstr "事件"
#: service/singleton/alertsentinel.go:169
msgid "Resolved"
msgstr "恢復"
#: service/singleton/crontask.go:52
msgid "Tasks failed to register: ["
msgstr "註冊失敗的任務:["
#: service/singleton/crontask.go:59
msgid ""
"] These tasks will not execute properly. Fix them in the admin dashboard."
msgstr "這些任務將無法正常執行,請進入後台重新修改儲存。"
#: service/singleton/crontask.go:150 service/singleton/crontask.go:175
#, c-format
msgid "[Task failed] %s: server %s is offline and cannot execute the task"
msgstr "[任務失敗] %s伺服器 %s 離線,無法執行"
#: service/singleton/servicesentinel.go:439
#, c-format
msgid "[Latency] %s %2f > %2f, Reporter: %s"
msgstr "[延遲告警] %s %2f > %2f報告服務: %s"
#: service/singleton/servicesentinel.go:446
#, c-format
msgid "[Latency] %s %2f < %2f, Reporter: %s"
msgstr "[延遲告警] %s %2f < %2f報告服務: %s"
#: service/singleton/servicesentinel.go:472
#, c-format
msgid "[%s] %s Reporter: %s, Error: %s"
msgstr "[%s] %s 報告服務:%s錯誤資訊%s"
#: service/singleton/servicesentinel.go:515
#, c-format
msgid "[TLS] Fetch cert info failed, Reporter: %s, Error: %s"
msgstr "[TLS] 獲取證書資訊失敗,報告服務:%s錯誤資訊%s"
#: service/singleton/servicesentinel.go:555
#, c-format
msgid "The TLS certificate will expire within seven days. Expiration time: %s"
msgstr "TLS 證書將在 7 天內過期。過期時間為:%s"
#: service/singleton/servicesentinel.go:568
#, c-format
msgid ""
"TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, "
"expires at %s"
msgstr ""
"TLS 證書發生更改,舊值:頒發者 %s過期日 %s新值頒發者 %s過期日 %s"
#: service/singleton/servicesentinel.go:604
msgid "No Data"
msgstr "無資料"
#: service/singleton/servicesentinel.go:606
msgid "Good"
msgstr "正常"
#: service/singleton/servicesentinel.go:608
msgid "Low Availability"
msgstr "低可用"
#: service/singleton/servicesentinel.go:610
msgid "Down"
msgstr "故障"

View File

@ -14,12 +14,12 @@ var (
func init() { func init() {
HttpClientSkipTlsVerify = httpClient(_httpClient{ HttpClientSkipTlsVerify = httpClient(_httpClient{
Transport: httpTransport(_httpTransport{ Transport: httpTransport(_httpTransport{
SkipVerifySSL: true, SkipVerifyTLS: true,
}), }),
}) })
HttpClient = httpClient(_httpClient{ HttpClient = httpClient(_httpClient{
Transport: httpTransport(_httpTransport{ Transport: httpTransport(_httpTransport{
SkipVerifySSL: false, SkipVerifyTLS: false,
}), }),
}) })
@ -27,12 +27,12 @@ func init() {
} }
type _httpTransport struct { type _httpTransport struct {
SkipVerifySSL bool SkipVerifyTLS bool
} }
func httpTransport(conf _httpTransport) *http.Transport { func httpTransport(conf _httpTransport) *http.Transport {
return &http.Transport{ return &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipVerifySSL}, TLSClientConfig: &tls.Config{InsecureSkipVerify: conf.SkipVerifyTLS},
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
} }
} }

View File

@ -19,10 +19,6 @@ var (
DNSServers = []string{"1.1.1.1:53", "223.5.5.5:53"} DNSServers = []string{"1.1.1.1:53", "223.5.5.5:53"}
) )
func IsWindows() bool {
return os.PathSeparator == '\\' && os.PathListSeparator == ';'
}
var ipv4Re = regexp.MustCompile(`(\d*\.).*(\.\d*)`) var ipv4Re = regexp.MustCompile(`(\d*\.).*(\.\d*)`)
func ipv4Desensitize(ipv4Addr string) string { func ipv4Desensitize(ipv4Addr string) string {

175
script/i18n.sh Executable file
View File

@ -0,0 +1,175 @@
#!/bin/bash
LANG=()
while IFS='' read -r line; do LANG+=("$line"); done < <(ls pkg/i18n/translations)
TEMPLATE="pkg/i18n/template.pot"
PODIR="pkg/i18n/translations/%s/LC_MESSAGES"
GIT_ROOT=$(git rev-parse --show-toplevel)
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
err() {
printf "${red}%s${plain}\n" "$*" >&2
}
success() {
printf "${green}%s${plain}\n" "$*"
}
info() {
printf "${yellow}%s${plain}\n" "$*"
}
generate() {
case $1 in
"template")
generate_template
;;
"en")
generate_en
;;
*)
err "invalid argument"
;;
esac
}
generate_template() {
read -ra src < <(find . -name "*.go" | sort)
xgettext -C --add-comments=TRANSLATORS: -kErrorT -kT -kTf -kN:1,2 --from-code=UTF-8 -o $TEMPLATE "${src[@]}"
}
generate_en() {
local po_file
po_file=$(printf "$PODIR/nezha.po" "en_US")
local mo_file
mo_file=$(printf "$PODIR/nezha.mo" "en_US")
msginit --input=$TEMPLATE --locale=en_US.UTF-8 --output-file="$po_file" --no-translator
msgfmt "$po_file" -o "$mo_file"
}
compile() {
if [[ $# != 0 ]]; then
compile_single "$1"
else
compile_all
fi
}
compile_single() {
local param="$1"
local found=0
for lang in "${LANG[@]}"; do
if [[ "$lang" == "$param" ]]; then
found=1
break
fi
done
if [[ $found == 0 ]]; then
err "the language does not exist."
return
fi
local po_file
po_file=$(printf "$PODIR/nezha.po" "$param")
local mo_file
mo_file=$(printf "$PODIR/nezha.mo" "$param")
msgfmt "$po_file" -o "$mo_file"
}
compile_all() {
local po_file
local mo_file
for lang in "${LANG[@]}"; do
po_file=$(printf "$PODIR/nezha.po" "$lang")
mo_file=$(printf "$PODIR/nezha.mo" "$lang")
msgfmt "$po_file" -o "$mo_file"
done
}
update() {
if [[ $# != 0 ]]; then
update_single "$1"
else
update_all
fi
}
update_single() {
local param="$1"
local found=0
for lang in "${LANG[@]}"; do
if [[ "$lang" == "$param" ]]; then
found=1
break
fi
done
if [[ $found == 0 ]]; then
err "the language does not exist."
return
fi
local po_file
po_file=$(printf "$PODIR/nezha.po" "$param")
msgmerge -U "$po_file" $TEMPLATE
}
update_all() {
for lang in "${LANG[@]}"; do
local po_file
po_file=$(printf "$PODIR/nezha.po" "$lang")
msgmerge -U "$po_file" $TEMPLATE
done
}
show_help() {
echo "Usage: $0 [command] args"
echo ""
echo "Available commands:"
echo " update Update .po from .pot"
echo " compile Compile .mo from .po"
echo " generate Generate template or en_US locale"
echo ""
echo "Examples:"
echo " $0 update # Update all locales"
echo " $0 update zh_CN # Update zh_CN locale"
echo " $0 compile # Compile all locales"
echo " $0 compile zh_CN # Compile zh_CN locale"
echo " $0 generate template # Generate template"
echo " $0 generate en # Generate en_US locale"
}
main() {
if [[ $PWD != "$GIT_ROOT" ]]; then
err "Must execute in the project root"
exit 1
fi
case "$1" in
"update")
update "$2"
;;
"compile")
compile "$2"
;;
"generate")
generate "$2"
;;
*)
echo "Error: Unknown command '$1'"
show_help
exit 1
;;
esac
}
main "$@"

View File

@ -322,7 +322,7 @@ func (_NotificationMuteLabel) ServiceStateChanged(serviceId uint64) *string {
return &label return &label
} }
func (_NotificationMuteLabel) ServiceSSL(serviceId uint64, extraInfo string) *string { func (_NotificationMuteLabel) ServiceTLS(serviceId uint64, extraInfo string) *string {
label := fmt.Sprintf("bf::sssl-%d-%s", serviceId, extraInfo) label := fmt.Sprintf("bf::stls-%d-%s", serviceId, extraInfo)
return &label return &label
} }

View File

@ -43,7 +43,7 @@ func NewServiceSentinel(serviceSentinelDispatchBus chan<- model.Service) {
serviceResponseDataStoreCurrentAvgDelay: make(map[uint64]float32), serviceResponseDataStoreCurrentAvgDelay: make(map[uint64]float32),
serviceResponsePing: make(map[uint64]map[uint64]*pingStore), serviceResponsePing: make(map[uint64]map[uint64]*pingStore),
Services: make(map[uint64]*model.Service), Services: make(map[uint64]*model.Service),
sslCertCache: make(map[uint64]string), tlsCertCache: make(map[uint64]string),
// 30天数据缓存 // 30天数据缓存
monthlyStatus: make(map[uint64]*model.ServiceResponseItem), monthlyStatus: make(map[uint64]*model.ServiceResponseItem),
dispatchBus: serviceSentinelDispatchBus, dispatchBus: serviceSentinelDispatchBus,
@ -102,7 +102,7 @@ type ServiceSentinel struct {
serviceResponseDataStoreCurrentAvgDelay map[uint64]float32 // [service_id] -> 当前服务离线计数 serviceResponseDataStoreCurrentAvgDelay map[uint64]float32 // [service_id] -> 当前服务离线计数
serviceResponsePing map[uint64]map[uint64]*pingStore // [service_id] -> ClientID -> delay serviceResponsePing map[uint64]map[uint64]*pingStore // [service_id] -> ClientID -> delay
lastStatus map[uint64]int lastStatus map[uint64]int
sslCertCache map[uint64]string tlsCertCache map[uint64]string
ServicesLock sync.RWMutex ServicesLock sync.RWMutex
Services map[uint64]*model.Service Services map[uint64]*model.Service
@ -279,7 +279,7 @@ func (ss *ServiceSentinel) OnServiceDelete(ids []uint64) {
delete(ss.serviceResponseDataStoreCurrentUp, id) delete(ss.serviceResponseDataStoreCurrentUp, id)
delete(ss.serviceResponseDataStoreCurrentDown, id) delete(ss.serviceResponseDataStoreCurrentDown, id)
delete(ss.serviceResponseDataStoreCurrentAvgDelay, id) delete(ss.serviceResponseDataStoreCurrentAvgDelay, id)
delete(ss.sslCertCache, id) delete(ss.tlsCertCache, id)
delete(ss.serviceStatusToday, id) delete(ss.serviceStatusToday, id)
// 停掉定时任务 // 停掉定时任务
@ -501,7 +501,7 @@ func (ss *ServiceSentinel) worker() {
} }
ss.serviceResponseDataStoreLock.Unlock() ss.serviceResponseDataStoreLock.Unlock()
// SSL 证书报警 // TLS 证书报警
var errMsg string var errMsg string
if strings.HasPrefix(mh.Data, "SSL证书错误") { if strings.HasPrefix(mh.Data, "SSL证书错误") {
// i/o timeout、connection timeout、EOF 错误 // i/o timeout、connection timeout、EOF 错误
@ -511,15 +511,15 @@ func (ss *ServiceSentinel) worker() {
errMsg = mh.Data errMsg = mh.Data
ss.ServicesLock.RLock() ss.ServicesLock.RLock()
if ss.Services[mh.GetId()].Notify { if ss.Services[mh.GetId()].Notify {
muteLabel := NotificationMuteLabel.ServiceSSL(mh.GetId(), "network") muteLabel := NotificationMuteLabel.ServiceTLS(mh.GetId(), "network")
go SendNotification(ss.Services[mh.GetId()].NotificationGroupID, Localizer.Tf("[SSL] Fetch cert info failed, %s %s", ss.Services[mh.GetId()].Name, errMsg), muteLabel) go SendNotification(ss.Services[mh.GetId()].NotificationGroupID, Localizer.Tf("[TLS] Fetch cert info failed, Reporter: %s, Error: %s", ss.Services[mh.GetId()].Name, errMsg), muteLabel)
} }
ss.ServicesLock.RUnlock() ss.ServicesLock.RUnlock()
} }
} else { } else {
// 清除网络错误静音缓存 // 清除网络错误静音缓存
UnMuteNotification(ss.Services[mh.GetId()].NotificationGroupID, NotificationMuteLabel.ServiceSSL(mh.GetId(), "network")) UnMuteNotification(ss.Services[mh.GetId()].NotificationGroupID, NotificationMuteLabel.ServiceTLS(mh.GetId(), "network"))
var newCert = strings.Split(mh.Data, "|") var newCert = strings.Split(mh.Data, "|")
if len(newCert) > 1 { if len(newCert) > 1 {
@ -527,11 +527,11 @@ func (ss *ServiceSentinel) worker() {
enableNotify := ss.Services[mh.GetId()].Notify enableNotify := ss.Services[mh.GetId()].Notify
// 首次获取证书信息时,缓存证书信息 // 首次获取证书信息时,缓存证书信息
if ss.sslCertCache[mh.GetId()] == "" { if ss.tlsCertCache[mh.GetId()] == "" {
ss.sslCertCache[mh.GetId()] = mh.Data ss.tlsCertCache[mh.GetId()] = mh.Data
} }
oldCert := strings.Split(ss.sslCertCache[mh.GetId()], "|") oldCert := strings.Split(ss.tlsCertCache[mh.GetId()], "|")
isCertChanged := false isCertChanged := false
expiresOld, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", oldCert[1]) expiresOld, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", oldCert[1])
expiresNew, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", newCert[1]) expiresNew, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", newCert[1])
@ -539,7 +539,7 @@ func (ss *ServiceSentinel) worker() {
// 证书变更时,更新缓存 // 证书变更时,更新缓存
if oldCert[0] != newCert[0] && !expiresNew.Equal(expiresOld) { if oldCert[0] != newCert[0] && !expiresNew.Equal(expiresOld) {
isCertChanged = true isCertChanged = true
ss.sslCertCache[mh.GetId()] = mh.Data ss.tlsCertCache[mh.GetId()] = mh.Data
} }
notificationGroupID := ss.Services[mh.GetId()].NotificationGroupID notificationGroupID := ss.Services[mh.GetId()].NotificationGroupID
@ -552,24 +552,24 @@ func (ss *ServiceSentinel) worker() {
if expiresNew.Before(time.Now().AddDate(0, 0, 7)) { if expiresNew.Before(time.Now().AddDate(0, 0, 7)) {
expiresTimeStr := expiresNew.Format("2006-01-02 15:04:05") expiresTimeStr := expiresNew.Format("2006-01-02 15:04:05")
errMsg = Localizer.Tf( errMsg = Localizer.Tf(
"The SSL certificate will expire within seven days. Expiration time: %s", "The TLS certificate will expire within seven days. Expiration time: %s",
expiresTimeStr, expiresTimeStr,
) )
// 静音规则: 服务id+证书过期时间 // 静音规则: 服务id+证书过期时间
// 用于避免多个监测点对相同证书同时报警 // 用于避免多个监测点对相同证书同时报警
muteLabel := NotificationMuteLabel.ServiceSSL(mh.GetId(), fmt.Sprintf("expire_%s", expiresTimeStr)) muteLabel := NotificationMuteLabel.ServiceTLS(mh.GetId(), fmt.Sprintf("expire_%s", expiresTimeStr))
go SendNotification(notificationGroupID, fmt.Sprintf("[SSL] %s %s", serviceName, errMsg), muteLabel) go SendNotification(notificationGroupID, fmt.Sprintf("[TLS] %s %s", serviceName, errMsg), muteLabel)
} }
// 证书变更提醒 // 证书变更提醒
if isCertChanged { if isCertChanged {
errMsg = Localizer.Tf( errMsg = Localizer.Tf(
"SSL certificate changed, old: issuer %s, expires at %s; new: issuer %s, expires at %s", "TLS certificate changed, old: issuer %s, expires at %s; new: issuer %s, expires at %s",
oldCert[0], expiresOld.Format("2006-01-02 15:04:05"), newCert[0], expiresNew.Format("2006-01-02 15:04:05")) oldCert[0], expiresOld.Format("2006-01-02 15:04:05"), newCert[0], expiresNew.Format("2006-01-02 15:04:05"))
// 证书变更后会自动更新缓存,所以不需要静音 // 证书变更后会自动更新缓存,所以不需要静音
go SendNotification(notificationGroupID, fmt.Sprintf("[SSL] %s %s", serviceName, errMsg), nil) go SendNotification(notificationGroupID, fmt.Sprintf("[TLS] %s %s", serviceName, errMsg), nil)
} }
} }
} }