🔥 移除后台登录类型设置,增加调度失败计划任务提醒
This commit is contained in:
		
							parent
							
								
									8af9b1ab18
								
							
						
					
					
						commit
						092f40b47f
					
				@ -4,7 +4,7 @@
 | 
			
		||||
  <br>
 | 
			
		||||
  <small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
 | 
			
		||||
  <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"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <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"> <img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge"> <img src="https://img.shields.io/badge/Installer-v0.7.0-brightgreen?style=for-the-badge&logo=linux">
 | 
			
		||||
  <br>
 | 
			
		||||
  <br>
 | 
			
		||||
  <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
 | 
			
		||||
 | 
			
		||||
@ -457,7 +457,6 @@ type settingForm struct {
 | 
			
		||||
	ViewPassword               string
 | 
			
		||||
	EnableIPChangeNotification string
 | 
			
		||||
	IgnoredIPNotification      string
 | 
			
		||||
	Oauth2Type                 string
 | 
			
		||||
	GRPCHost                   string
 | 
			
		||||
	Cover                      uint8
 | 
			
		||||
}
 | 
			
		||||
@ -479,7 +478,6 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
 | 
			
		||||
	dao.Conf.Site.Theme = sf.Theme
 | 
			
		||||
	dao.Conf.Site.CustomCode = sf.CustomCode
 | 
			
		||||
	dao.Conf.Site.ViewPassword = sf.ViewPassword
 | 
			
		||||
	dao.Conf.Oauth2.Type = sf.Oauth2Type
 | 
			
		||||
	dao.Conf.Oauth2.Admin = sf.Admin
 | 
			
		||||
	if err := dao.Conf.Save(); err != nil {
 | 
			
		||||
		c.JSON(http.StatusOK, model.Response{
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,9 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
@ -56,6 +58,7 @@ func initSystem() {
 | 
			
		||||
		model.Notification{}, model.AlertRule{}, model.Monitor{},
 | 
			
		||||
		model.MonitorHistory{}, model.Cron{}, model.Transfer{})
 | 
			
		||||
 | 
			
		||||
	dao.LoadNotifications()
 | 
			
		||||
	loadServers() //加载服务器列表
 | 
			
		||||
	loadCrons()   //加载计划任务
 | 
			
		||||
 | 
			
		||||
@ -153,6 +156,7 @@ func loadCrons() {
 | 
			
		||||
	var crons []model.Cron
 | 
			
		||||
	dao.DB.Find(&crons)
 | 
			
		||||
	var err error
 | 
			
		||||
	errMsg := new(bytes.Buffer)
 | 
			
		||||
	for i := 0; i < len(crons); i++ {
 | 
			
		||||
		cr := crons[i]
 | 
			
		||||
 | 
			
		||||
@ -165,8 +169,15 @@ func loadCrons() {
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			dao.Crons[cr.ID] = &cr
 | 
			
		||||
		} 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()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,15 +8,6 @@
 | 
			
		||||
                <label>站点标题</label>
 | 
			
		||||
                <input type="text" name="Title" placeholder="哪吒监控" value="{{.Conf.Site.Brand}}">
 | 
			
		||||
            </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">
 | 
			
		||||
                <label>管理员列表</label>
 | 
			
		||||
                <input type="text" name="Admin" placeholder="1010,2020" value="{{.Conf.Oauth2.Admin}}">
 | 
			
		||||
 | 
			
		||||
@ -30,11 +30,6 @@ type NotificationHistory struct {
 | 
			
		||||
func AlertSentinelStart() {
 | 
			
		||||
	alertsStore = make(map[uint64]map[uint64][][]interface{})
 | 
			
		||||
	alertsPrevState = make(map[uint64]map[uint64]uint)
 | 
			
		||||
	notificationsLock.Lock()
 | 
			
		||||
	if err := DB.Find(¬ifications).Error; err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	notificationsLock.Unlock()
 | 
			
		||||
	alertsLock.Lock()
 | 
			
		||||
	if err := DB.Find(&alerts).Error; err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ import (
 | 
			
		||||
	pb "github.com/naiba/nezha/proto"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var Version = "v0.10.2" // !!记得修改 README 中的 badge 版本!!
 | 
			
		||||
var Version = "v0.10.3" // !!记得修改 README 中的 badge 版本!!
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	Conf  *model.Config
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,14 @@ const firstNotificationDelay = time.Minute * 15
 | 
			
		||||
var notifications []model.Notification
 | 
			
		||||
var notificationsLock sync.RWMutex
 | 
			
		||||
 | 
			
		||||
func LoadNotifications() {
 | 
			
		||||
	notificationsLock.Lock()
 | 
			
		||||
	if err := DB.Find(¬ifications).Error; err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	notificationsLock.Unlock()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func OnRefreshOrAddNotification(n model.Notification) {
 | 
			
		||||
	notificationsLock.Lock()
 | 
			
		||||
	defer notificationsLock.Unlock()
 | 
			
		||||
 | 
			
		||||
@ -146,7 +146,6 @@ func (ss *ServiceSentinel) loadMonitorHistory() {
 | 
			
		||||
		monitors[i].CronJobID, err = Cron.AddFunc(task.CronSpec(), func() {
 | 
			
		||||
			ss.dispatchBus <- task
 | 
			
		||||
		})
 | 
			
		||||
		log.Println("NEZHA>> 服务监控任务", monitors[i].ID, monitors[i].Name, monitors[i].CronJobID)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user