From 01048073247bdfea8281614cdde3310a5f991f03 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 26 Jan 2021 09:12:48 +0800 Subject: [PATCH] =?UTF-8?q?[dashboard=20v0.3.12]=20=E4=BF=AE=E5=A4=8DSSL?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E5=BC=82=E5=B8=B8=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 30 ++++++++++++++++++++++++++++-- service/dao/dao.go | 2 +- service/rpc/nezha.go | 27 ++++++++++++++++----------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b1dbb9a..0aa519f 100644 --- a/README.md +++ b/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 里面也可放置占位符,请求时会进行简单的字符串替换。 ## 常见问题
- 数据备份恢复:数据迁移、备份恢复。 + 数据备份恢复:数据迁移、备份恢复。 来自 @艾斯德斯 数据储存在 `/opt/nezha` 文件夹中,迁移数据时打包这个文件夹,到新环境解压。然后执行一键脚本安装即可
+
+ 路由器:OpenWrt/LEDE 自启动 + +首先在 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` +
+
服务器时间不准确:导致首页服务器随机频繁掉线。 diff --git a/service/dao/dao.go b/service/dao/dao.go index 81798c3..4b24ca2 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -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 diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index 6fea4bd..04d8010 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -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 != "" {