🔥 移除后台登录类型设置,增加调度失败计划任务提醒

This commit is contained in:
naiba 2021-09-30 00:01:04 +08:00
parent 8af9b1ab18
commit 092f40b47f
8 changed files with 22 additions and 20 deletions

View File

@ -4,7 +4,7 @@
<br> <br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small> <small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br> <br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.10.2&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.7.0-brightgreen?style=for-the-badge&logo=linux"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.10.3&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.7.0-brightgreen?style=for-the-badge&logo=linux">
<br> <br>
<br> <br>
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p> <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>

View File

@ -457,7 +457,6 @@ type settingForm struct {
ViewPassword string ViewPassword string
EnableIPChangeNotification string EnableIPChangeNotification string
IgnoredIPNotification string IgnoredIPNotification string
Oauth2Type string
GRPCHost string GRPCHost string
Cover uint8 Cover uint8
} }
@ -479,7 +478,6 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
dao.Conf.Site.Theme = sf.Theme dao.Conf.Site.Theme = sf.Theme
dao.Conf.Site.CustomCode = sf.CustomCode dao.Conf.Site.CustomCode = sf.CustomCode
dao.Conf.Site.ViewPassword = sf.ViewPassword dao.Conf.Site.ViewPassword = sf.ViewPassword
dao.Conf.Oauth2.Type = sf.Oauth2Type
dao.Conf.Oauth2.Admin = sf.Admin dao.Conf.Oauth2.Admin = sf.Admin
if err := dao.Conf.Save(); err != nil { if err := dao.Conf.Save(); err != nil {
c.JSON(http.StatusOK, model.Response{ c.JSON(http.StatusOK, model.Response{

View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"bytes"
"context" "context"
"fmt"
"log" "log"
"time" "time"
@ -56,6 +58,7 @@ func initSystem() {
model.Notification{}, model.AlertRule{}, model.Monitor{}, model.Notification{}, model.AlertRule{}, model.Monitor{},
model.MonitorHistory{}, model.Cron{}, model.Transfer{}) model.MonitorHistory{}, model.Cron{}, model.Transfer{})
dao.LoadNotifications()
loadServers() //加载服务器列表 loadServers() //加载服务器列表
loadCrons() //加载计划任务 loadCrons() //加载计划任务
@ -153,6 +156,7 @@ func loadCrons() {
var crons []model.Cron var crons []model.Cron
dao.DB.Find(&crons) dao.DB.Find(&crons)
var err error var err error
errMsg := new(bytes.Buffer)
for i := 0; i < len(crons); i++ { for i := 0; i < len(crons); i++ {
cr := crons[i] cr := crons[i]
@ -165,9 +169,16 @@ func loadCrons() {
if err == nil { if err == nil {
dao.Crons[cr.ID] = &cr dao.Crons[cr.ID] = &cr
} else { } else {
log.Println("NEZHA>> 计划任务调度失败", cr, err) if errMsg.Len() == 0 {
errMsg.WriteString("调度失败的计划任务:[")
}
errMsg.WriteString(fmt.Sprintf("%d,", cr.ID))
} }
} }
if errMsg.Len() > 0 {
msg := errMsg.String()
dao.SendNotification(msg[:len(msg)-1]+"] 这些任务将无法正常执行,请进入后点重新修改保存。", false)
}
dao.Cron.Start() dao.Cron.Start()
} }

View File

@ -8,15 +8,6 @@
<label>站点标题</label> <label>站点标题</label>
<input type="text" name="Title" placeholder="哪吒监控" value="{{.Conf.Site.Brand}}"> <input type="text" name="Title" placeholder="哪吒监控" value="{{.Conf.Site.Brand}}">
</div> </div>
<div class="field">
<label>登录类型</label>
<select name="Oauth2Type">
<option value="github" {{if eq .Conf.Oauth2.Type "github" }} selected="selected" {{end}}>GitHub
</option>
<option value="gitee" {{if eq .Conf.Oauth2.Type "gitee" }} selected="selected" {{end}}>Gitee
</option>
</select>
</div>
<div class="field"> <div class="field">
<label>管理员列表</label> <label>管理员列表</label>
<input type="text" name="Admin" placeholder="1010,2020" value="{{.Conf.Oauth2.Admin}}"> <input type="text" name="Admin" placeholder="1010,2020" value="{{.Conf.Oauth2.Admin}}">

View File

@ -30,11 +30,6 @@ type NotificationHistory struct {
func AlertSentinelStart() { func AlertSentinelStart() {
alertsStore = make(map[uint64]map[uint64][][]interface{}) alertsStore = make(map[uint64]map[uint64][][]interface{})
alertsPrevState = make(map[uint64]map[uint64]uint) alertsPrevState = make(map[uint64]map[uint64]uint)
notificationsLock.Lock()
if err := DB.Find(&notifications).Error; err != nil {
panic(err)
}
notificationsLock.Unlock()
alertsLock.Lock() alertsLock.Lock()
if err := DB.Find(&alerts).Error; err != nil { if err := DB.Find(&alerts).Error; err != nil {
panic(err) panic(err)

View File

@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto" pb "github.com/naiba/nezha/proto"
) )
var Version = "v0.10.2" // !!记得修改 README 中的 badge 版本!! var Version = "v0.10.3" // !!记得修改 README 中的 badge 版本!!
var ( var (
Conf *model.Config Conf *model.Config

View File

@ -16,6 +16,14 @@ const firstNotificationDelay = time.Minute * 15
var notifications []model.Notification var notifications []model.Notification
var notificationsLock sync.RWMutex var notificationsLock sync.RWMutex
func LoadNotifications() {
notificationsLock.Lock()
if err := DB.Find(&notifications).Error; err != nil {
panic(err)
}
notificationsLock.Unlock()
}
func OnRefreshOrAddNotification(n model.Notification) { func OnRefreshOrAddNotification(n model.Notification) {
notificationsLock.Lock() notificationsLock.Lock()
defer notificationsLock.Unlock() defer notificationsLock.Unlock()

View File

@ -146,7 +146,6 @@ func (ss *ServiceSentinel) loadMonitorHistory() {
monitors[i].CronJobID, err = Cron.AddFunc(task.CronSpec(), func() { monitors[i].CronJobID, err = Cron.AddFunc(task.CronSpec(), func() {
ss.dispatchBus <- task ss.dispatchBus <- task
}) })
log.Println("NEZHA>> 服务监控任务", monitors[i].ID, monitors[i].Name, monitors[i].CronJobID)
if err != nil { if err != nil {
panic(err) panic(err)
} }