mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-08-05 21:20:12 +00:00
Compare commits
2
Commits
f3dded3186
...
c778472571
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c778472571 | ||
|
|
cabbfff858 |
@@ -140,5 +140,8 @@ func SyncDomainWHOIS(c *gin.Context) (any, error) {
|
||||
|
||||
func SyncAllDomains(c *gin.Context) (any, error) {
|
||||
singleton.SyncAllDomains()
|
||||
// 手动触发到期检查,方便调试
|
||||
singleton.CronJobForDomainStatus()
|
||||
singleton.CronJobForServerStatus()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
+39
-4
@@ -233,7 +233,10 @@ func (ns *NotificationServerBundle) replaceParamsInString(str string, message st
|
||||
"#SERVER.EXPIRE_DATE#", mod(expiresStr),
|
||||
"#SERVER.BILLING_AMOUNT#", mod(amountStr),
|
||||
"#SERVER.BILLING_CYCLE#", mod(cycleStr),
|
||||
)
|
||||
|
||||
if ns.Server.State != nil && ns.Server.Host != nil {
|
||||
replacements = append(replacements,
|
||||
// Converted metrics
|
||||
"#SERVER.CPU#", mod(ns.formatUsage(false, ns.Server.State.CPU)),
|
||||
"#SERVER.MEM#", mod(ns.formatUsage(true, float64(ns.Server.State.MemUsed)/float64(ns.Server.Host.MemTotal))),
|
||||
@@ -249,21 +252,52 @@ func (ns *NotificationServerBundle) replaceParamsInString(str string, message st
|
||||
"#SERVER.MEMUSED#", mod(fmt.Sprintf("%d", ns.Server.State.MemUsed)),
|
||||
"#SERVER.SWAPUSED#", mod(fmt.Sprintf("%d", ns.Server.State.SwapUsed)),
|
||||
"#SERVER.DISKUSED#", mod(fmt.Sprintf("%d", ns.Server.State.DiskUsed)),
|
||||
"#SERVER.NETINSPEED#", mod(fmt.Sprintf("%d", ns.Server.State.NetInSpeed)),
|
||||
"#SERVER.NETOUTSPEED#", mod(fmt.Sprintf("%d", ns.Server.State.NetOutSpeed)),
|
||||
"#SERVER.TRANSFERINRAW#", mod(fmt.Sprintf("%d", ns.Server.State.NetInTransfer)),
|
||||
"#SERVER.TRANSFEROUTRAW#", mod(fmt.Sprintf("%d", ns.Server.State.NetOutTransfer)),
|
||||
"#SERVER.UPTIME#", mod(fmt.Sprintf("%d", ns.Server.State.Uptime)),
|
||||
"#SERVER.MEMTOTAL#", mod(fmt.Sprintf("%d", ns.Server.Host.MemTotal)),
|
||||
"#SERVER.SWAPTOTAL#", mod(fmt.Sprintf("%d", ns.Server.Host.SwapTotal)),
|
||||
"#SERVER.DISKTOTAL#", mod(fmt.Sprintf("%d", ns.Server.Host.DiskTotal)),
|
||||
"#SERVER.NETINSPEED#", mod(fmt.Sprintf("%d", ns.Server.State.NetInSpeed)),
|
||||
"#SERVER.NETOUTSPEED#", mod(fmt.Sprintf("%d", ns.Server.State.NetOutSpeed)),
|
||||
"#SERVER.NETINTRANSFER#", mod(fmt.Sprintf("%d", ns.Server.State.NetInTransfer)),
|
||||
"#SERVER.NETOUTTRANSFER#", mod(fmt.Sprintf("%d", ns.Server.State.NetOutTransfer)),
|
||||
"#SERVER.LOAD1#", mod(fmt.Sprintf("%f", ns.Server.State.Load1)),
|
||||
"#SERVER.LOAD5#", mod(fmt.Sprintf("%f", ns.Server.State.Load5)),
|
||||
"#SERVER.LOAD15#", mod(fmt.Sprintf("%f", ns.Server.State.Load15)),
|
||||
"#SERVER.TCPCONNCOUNT#", mod(fmt.Sprintf("%d", ns.Server.State.TcpConnCount)),
|
||||
"#SERVER.UDPCONNCOUNT#", mod(fmt.Sprintf("%d", ns.Server.State.UdpConnCount)),
|
||||
)
|
||||
} else {
|
||||
replacements = append(replacements,
|
||||
"#SERVER.CPU#", mod("N/A"),
|
||||
"#SERVER.MEM#", mod("N/A"),
|
||||
"#SERVER.SWAP#", mod("N/A"),
|
||||
"#SERVER.DISK#", mod("N/A"),
|
||||
"#SERVER.SPEEDIN#", mod("N/A"),
|
||||
"#SERVER.SPEEDOUT#", mod("N/A"),
|
||||
"#SERVER.TRANSFERIN#", mod("N/A"),
|
||||
"#SERVER.TRANSFEROUT#", mod("N/A"),
|
||||
"#SERVER.CPUUSED#", mod("0"),
|
||||
"#SERVER.MEMUSED#", mod("0"),
|
||||
"#SERVER.SWAPUSED#", mod("0"),
|
||||
"#SERVER.DISKUSED#", mod("0"),
|
||||
"#SERVER.NETINSPEED#", mod("0"),
|
||||
"#SERVER.NETOUTSPEED#", mod("0"),
|
||||
"#SERVER.TRANSFERINRAW#", mod("0"),
|
||||
"#SERVER.TRANSFEROUTRAW#", mod("0"),
|
||||
"#SERVER.UPTIME#", mod("0"),
|
||||
"#SERVER.MEMTOTAL#", mod("0"),
|
||||
"#SERVER.SWAPTOTAL#", mod("0"),
|
||||
"#SERVER.DISKTOTAL#", mod("0"),
|
||||
"#SERVER.LOAD1#", mod("0"),
|
||||
"#SERVER.LOAD5#", mod("0"),
|
||||
"#SERVER.LOAD15#", mod("0"),
|
||||
"#SERVER.TCPCONNCOUNT#", mod("0"),
|
||||
"#SERVER.UDPCONNCOUNT#", mod("0"),
|
||||
)
|
||||
}
|
||||
|
||||
var ipv4, ipv6, validIP string
|
||||
if ns.Server.GeoIP != nil {
|
||||
ip := ns.Server.GeoIP.IP
|
||||
if ip.IPv4Addr != "" && ip.IPv6Addr != "" {
|
||||
ipv4 = ip.IPv4Addr
|
||||
@@ -276,6 +310,7 @@ func (ns *NotificationServerBundle) replaceParamsInString(str string, message st
|
||||
ipv6 = ip.IPv6Addr
|
||||
validIP = ipv6
|
||||
}
|
||||
}
|
||||
|
||||
replacements = append(replacements,
|
||||
"#SERVER.IP#", mod(validIP),
|
||||
|
||||
@@ -399,7 +399,18 @@ func CronJobForDomainStatus() {
|
||||
continue
|
||||
}
|
||||
|
||||
endDate, err := time.Parse(time.RFC3339, billing.EndDate)
|
||||
// 处理类似 2026-10-10 甚至其他不带时区的格式
|
||||
endDateStr := billing.EndDate
|
||||
var endDate time.Time
|
||||
var err error
|
||||
if len(endDateStr) == 10 { // YYYY-MM-DD
|
||||
endDate, err = time.Parse("2006-01-02", endDateStr)
|
||||
} else if len(endDateStr) == 19 && endDateStr[10] == ' ' { // YYYY-MM-DD HH:MM:SS
|
||||
endDate, err = time.Parse("2006-01-02 15:04:05", endDateStr)
|
||||
} else {
|
||||
endDate, err = time.Parse(time.RFC3339, endDateStr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> Cron::Error parsing end date for domain %s: %v", d.Domain, err)
|
||||
continue
|
||||
@@ -466,21 +477,37 @@ func CronJobForServerStatus() {
|
||||
|
||||
for i := range servers {
|
||||
s := servers[i]
|
||||
if s.BillingData == nil {
|
||||
var pn struct {
|
||||
BillingDataMod struct {
|
||||
EndDate string `json:"endDate"`
|
||||
} `json:"billingDataMod"`
|
||||
}
|
||||
if s.PublicNote != "" {
|
||||
_ = json.Unmarshal([]byte(s.PublicNote), &pn)
|
||||
}
|
||||
if pn.BillingDataMod.EndDate == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var billing model.BillingDataMod
|
||||
if err := json.Unmarshal(s.BillingData, &billing); err != nil {
|
||||
// 忽略前端默认生成的空日期
|
||||
if strings.HasPrefix(pn.BillingDataMod.EndDate, "0000-00-00") {
|
||||
continue
|
||||
}
|
||||
|
||||
if billing.EndDate == "" {
|
||||
continue
|
||||
// 处理类似 2026-10-10 甚至其他不带时区的格式
|
||||
endDateStr := pn.BillingDataMod.EndDate
|
||||
var endDate time.Time
|
||||
var err error
|
||||
if len(endDateStr) == 10 { // YYYY-MM-DD
|
||||
endDate, err = time.Parse("2006-01-02", endDateStr)
|
||||
} else if len(endDateStr) == 19 && endDateStr[10] == ' ' { // YYYY-MM-DD HH:MM:SS
|
||||
endDate, err = time.Parse("2006-01-02 15:04:05", endDateStr)
|
||||
} else {
|
||||
endDate, err = time.Parse(time.RFC3339, endDateStr)
|
||||
}
|
||||
|
||||
endDate, err := time.Parse(time.RFC3339, billing.EndDate)
|
||||
if err != nil {
|
||||
log.Printf("NEZHA>> Cron::Error parsing end date for VPS %s: %v", s.Name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user