mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
init jwt
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
)
|
||||
@@ -159,22 +157,22 @@ func checkStatus() {
|
||||
// 始终触发模式或上次检查不为失败时触发报警(跳过单次触发+上次失败的情况)
|
||||
if alert.TriggerMode == model.ModeAlwaysTrigger || alertsPrevState[alert.ID][server.ID] != _RuleCheckFail {
|
||||
alertsPrevState[alert.ID][server.ID] = _RuleCheckFail
|
||||
message := fmt.Sprintf("[%s] %s(%s) %s", Localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "Incident",
|
||||
}), server.Name, IPDesensitize(server.Host.IP), alert.Name)
|
||||
// message := fmt.Sprintf("[%s] %s(%s) %s", Localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
// MessageID: "Incident",
|
||||
// }), server.Name, IPDesensitize(server.Host.IP), alert.Name)
|
||||
go SendTriggerTasks(alert.FailTriggerTasks, curServer.ID)
|
||||
go SendNotification(alert.NotificationTag, message, NotificationMuteLabel.ServerIncident(server.ID, alert.ID), &curServer)
|
||||
// go SendNotification(alert.NotificationTag, message, NotificationMuteLabel.ServerIncident(server.ID, alert.ID), &curServer)
|
||||
// 清除恢复通知的静音缓存
|
||||
UnMuteNotification(alert.NotificationTag, NotificationMuteLabel.ServerIncidentResolved(server.ID, alert.ID))
|
||||
}
|
||||
} else {
|
||||
// 本次通过检查但上一次的状态为失败,则发送恢复通知
|
||||
if alertsPrevState[alert.ID][server.ID] == _RuleCheckFail {
|
||||
message := fmt.Sprintf("[%s] %s(%s) %s", Localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
MessageID: "Resolved",
|
||||
}), server.Name, IPDesensitize(server.Host.IP), alert.Name)
|
||||
// message := fmt.Sprintf("[%s] %s(%s) %s", Localizer.MustLocalize(&i18n.LocalizeConfig{
|
||||
// MessageID: "Resolved",
|
||||
// }), server.Name, IPDesensitize(server.Host.IP), alert.Name)
|
||||
go SendTriggerTasks(alert.RecoverTriggerTasks, curServer.ID)
|
||||
go SendNotification(alert.NotificationTag, message, NotificationMuteLabel.ServerIncidentResolved(server.ID, alert.ID), &curServer)
|
||||
// go SendNotification(alert.NotificationTag, message, NotificationMuteLabel.ServerIncidentResolved(server.ID, alert.ID), &curServer)
|
||||
// 清除失败通知的静音缓存
|
||||
UnMuteNotification(alert.NotificationTag, NotificationMuteLabel.ServerIncident(server.ID, alert.ID))
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
"github.com/naiba/nezha/resource"
|
||||
)
|
||||
|
||||
var Localizer *i18n.Localizer
|
||||
|
||||
func InitLocalizer() {
|
||||
bundle := i18n.NewBundle(language.Chinese)
|
||||
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||
|
||||
if _, exists := model.Languages[Conf.Language]; !exists {
|
||||
log.Println("NEZHA>> language not exists:", Conf.Language)
|
||||
Conf.Language = "zh-CN"
|
||||
} else {
|
||||
_, err := bundle.LoadMessageFileFS(resource.I18nFS, "l10n/"+Conf.Language+".toml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := bundle.LoadMessageFileFS(resource.I18nFS, "l10n/zh-CN.toml"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Localizer = i18n.NewLocalizer(bundle, Conf.Language)
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
@@ -609,14 +607,15 @@ func GetStatusCode[T float32 | uint64](percent T) int {
|
||||
func StatusCodeToString(statusCode int) string {
|
||||
switch statusCode {
|
||||
case StatusNoData:
|
||||
return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusNoData"})
|
||||
// return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusNoData"})
|
||||
case StatusGood:
|
||||
return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusGood"})
|
||||
// return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusGood"})
|
||||
case StatusLowAvailability:
|
||||
return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusLowAvailability"})
|
||||
// return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusLowAvailability"})
|
||||
case StatusDown:
|
||||
return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusDown"})
|
||||
// return Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "StatusDown"})
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user