mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
[dashboard v0.3.12] 修复SSL证书异常数据导致重启
This commit is contained in:
parent
e28d5b1b9a
commit
0104807324
30
README.md
30
README.md
@ -1,6 +1,6 @@
|
||||
# 哪吒面板
|
||||
|
||||
![dashboard](https://img.shields.io/badge/管理面板-v0.3.11-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
||||
![dashboard](https://img.shields.io/badge/管理面板-v0.3.12-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
||||
|
||||
系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。
|
||||
|
||||
@ -153,11 +153,37 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
|
||||
## 常见问题
|
||||
|
||||
<details>
|
||||
<summary>数据备份恢复:数据迁移、备份恢复。</summary>
|
||||
<summary>数据备份恢复:数据迁移、备份恢复。 来自 @艾斯德斯</summary>
|
||||
|
||||
数据储存在 `/opt/nezha` 文件夹中,迁移数据时打包这个文件夹,到新环境解压。然后执行一键脚本安装即可
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>路由器:OpenWrt/LEDE 自启动</summary>
|
||||
|
||||
首先在 release 下载对应的二进制解压后放置到 `/root/nezha-agent`,然后 `chmod +x /root/nezha-agent` 赋予执行权限,然后创建 `/etc/init.d/nezha-agent`:
|
||||
|
||||
```
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
|
||||
start(){
|
||||
nohup /root/nezha-agent -i XXX -d >/dev/null 2>&1 &
|
||||
}
|
||||
stop(){
|
||||
# kill your pid
|
||||
kill -9 `ps | grep '/root/nezha-agent' | grep -v 'grep' | awk '{print $1}'`
|
||||
}
|
||||
restart(){
|
||||
kill -9 `ps | grep '/root/nezha-agent' | grep -v 'grep' | awk '{print $1}'`
|
||||
nohup /root/nezha-agent -i XXX -d >/dev/null 2>&1 &
|
||||
}
|
||||
```
|
||||
|
||||
赋予执行权限 `chmod +x /etc/init.d/nezha-agnt` 然后启动服务 `/etc/init.d/nezha-agent enable && /etc/init.d/nezha-agent start`
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>服务器时间不准确:导致首页服务器随机频繁掉线。</summary>
|
||||
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
var Version = "v0.3.11" // !!记得修改 README 重的 badge 版本!!
|
||||
var Version = "v0.3.12" // !!记得修改 README 重的 badge 版本!!
|
||||
|
||||
const (
|
||||
SnapshotDelay = 3
|
||||
|
@ -29,23 +29,28 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
||||
errMsg = r.GetData()
|
||||
} else {
|
||||
var last model.MonitorHistory
|
||||
if err := dao.DB.Where("monitor_id = ? AND data LIKE ?", r.GetId(), "%|%").Order("id DESC").First(&last).Error; err == nil {
|
||||
var oldCert = strings.Split(last.Data, "|")
|
||||
var newCert = strings.Split(r.GetData(), "|")
|
||||
expiresOld, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", oldCert[1])
|
||||
var newCert = strings.Split(r.GetData(), "|")
|
||||
if len(newCert) > 1 {
|
||||
expiresNew, _ := time.Parse("2006-01-02 15:04:05 -0700 MST", newCert[1])
|
||||
// 证书变更提醒
|
||||
if last.Data != "" && oldCert[0] != newCert[0] && !expiresNew.Equal(expiresOld) {
|
||||
errMsg = fmt.Sprintf(
|
||||
"SSL证书变更,旧:%s, %s 过期;新:%s, %s 过期。",
|
||||
oldCert[0], expiresOld.Format("2006-01-02 15:04:05"), newCert[0], expiresNew.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
// 证书过期提醒
|
||||
if err == nil && expiresNew.Before(time.Now().AddDate(0, 0, 7)) {
|
||||
if expiresNew.Before(time.Now().AddDate(0, 0, 7)) {
|
||||
errMsg = fmt.Sprintf(
|
||||
"SSL证书将在七天内过期,过期时间:%s。",
|
||||
expiresNew.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
// 证书变更提醒
|
||||
if err := dao.DB.Where("monitor_id = ? AND data LIKE ?", r.GetId(), "%|%").Order("id DESC").First(&last).Error; err == nil {
|
||||
var oldCert = strings.Split(last.Data, "|")
|
||||
var expiresOld time.Time
|
||||
if len(oldCert) > 1 {
|
||||
expiresOld, _ = time.Parse("2006-01-02 15:04:05 -0700 MST", oldCert[1])
|
||||
}
|
||||
if last.Data != "" && oldCert[0] != newCert[0] && !expiresNew.Equal(expiresOld) {
|
||||
errMsg = fmt.Sprintf(
|
||||
"SSL证书变更,旧:%s, %s 过期;新:%s, %s 过期。",
|
||||
oldCert[0], expiresOld.Format("2006-01-02 15:04:05"), newCert[0], expiresNew.Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if errMsg != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user