mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-07 14:06:19 +08:00
feat: Adjust alarm settings (#9616)
This commit is contained in:
parent
033f08a6d2
commit
cca1863b63
14 changed files with 174 additions and 112 deletions
|
@ -307,13 +307,13 @@ type AlertSendTimeRange struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertCommonConfig struct {
|
type AlertCommonConfig struct {
|
||||||
AlertDailyNum uint `json:"alertDailyNum"`
|
|
||||||
IsOffline string `json:"isOffline"`
|
IsOffline string `json:"isOffline"`
|
||||||
AlertSendTimeRange AlertSendTimeRange `json:"alertSendTimeRange"`
|
AlertSendTimeRange AlertSendTimeRange `json:"alertSendTimeRange"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertSmsConfig struct {
|
type AlertSmsConfig struct {
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
|
AlertDailyNum uint `json:"alertDailyNum"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertEmailConfig struct {
|
type AlertEmailConfig struct {
|
||||||
|
|
|
@ -18,6 +18,7 @@ type AlertTask struct {
|
||||||
Type string `gorm:"type:varchar(64);not null" json:"type"`
|
Type string `gorm:"type:varchar(64);not null" json:"type"`
|
||||||
Quota string `gorm:"type:varchar(64)" json:"quota"`
|
Quota string `gorm:"type:varchar(64)" json:"quota"`
|
||||||
QuotaType string `gorm:"type:varchar(64)" json:"quotaType"`
|
QuotaType string `gorm:"type:varchar(64)" json:"quotaType"`
|
||||||
|
Method string `gorm:"type:varchar(64);not null;default:'sms" json:"method"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlertLog struct {
|
type AlertLog struct {
|
||||||
|
|
|
@ -44,7 +44,7 @@ type IAlertRepo interface {
|
||||||
GetAlertTask(opts ...DBOption) (model.AlertTask, error)
|
GetAlertTask(opts ...DBOption) (model.AlertTask, error)
|
||||||
LoadTaskCount(alertType string, project string) (uint, uint, error)
|
LoadTaskCount(alertType string, project string) (uint, uint, error)
|
||||||
GetTaskLog(alertType string, alertId uint) (time.Time, error)
|
GetTaskLog(alertType string, alertId uint) (time.Time, error)
|
||||||
GetLicensePushCount() (uint, error)
|
GetLicensePushCount(method string) (uint, error)
|
||||||
|
|
||||||
GetConfig(opts ...DBOption) (model.AlertConfig, error)
|
GetConfig(opts ...DBOption) (model.AlertConfig, error)
|
||||||
AlertConfigList(opts ...DBOption) ([]model.AlertConfig, error)
|
AlertConfigList(opts ...DBOption) ([]model.AlertConfig, error)
|
||||||
|
@ -267,14 +267,14 @@ func getAlertDB(opts ...DBOption) (*gorm.DB, error) {
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AlertRepo) GetLicensePushCount() (uint, error) {
|
func (a *AlertRepo) GetLicensePushCount(method string) (uint, error) {
|
||||||
var (
|
var (
|
||||||
todayCount int64
|
todayCount int64
|
||||||
)
|
)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
todayMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
todayMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||||
tomorrowMidnight := todayMidnight.Add(24 * time.Hour)
|
tomorrowMidnight := todayMidnight.Add(24 * time.Hour)
|
||||||
err := global.AlertDB.Model(&model.AlertTask{}).Where("created_at > ? AND created_at < ?", todayMidnight, tomorrowMidnight).Count(&todayCount).Error
|
err := global.AlertDB.Model(&model.AlertTask{}).Where("created_at > ? AND created_at < ? AND method = ?", todayMidnight, tomorrowMidnight, method).Count(&todayCount).Error
|
||||||
return uint(todayCount), err
|
return uint(todayCount), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,9 +87,6 @@ func (m *AlertTaskHelper) InitTask(alertType string) {
|
||||||
|
|
||||||
func resourceTask(resourceAlert []dto.AlertDTO) {
|
func resourceTask(resourceAlert []dto.AlertDTO) {
|
||||||
for _, alert := range resourceAlert {
|
for _, alert := range resourceAlert {
|
||||||
if !alertUtil.CheckTaskFrequency() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !alertUtil.CheckSendTimeRange(alert.Type) {
|
if !alertUtil.CheckSendTimeRange(alert.Type) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -109,9 +106,6 @@ func resourceTask(resourceAlert []dto.AlertDTO) {
|
||||||
|
|
||||||
func baseTask(baseAlert []dto.AlertDTO) {
|
func baseTask(baseAlert []dto.AlertDTO) {
|
||||||
for _, alert := range baseAlert {
|
for _, alert := range baseAlert {
|
||||||
if !alertUtil.CheckTaskFrequency() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !alertUtil.CheckSendTimeRange(alert.Type) {
|
if !alertUtil.CheckSendTimeRange(alert.Type) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -245,7 +239,11 @@ func loadSSLInfo(alert dto.AlertDTO) {
|
||||||
params = createAlertBaseParams(strconv.Itoa(len(primaryDomain)), strconv.Itoa(daysDifference))
|
params = createAlertBaseParams(strconv.Itoa(len(primaryDomain)), strconv.Itoa(daysDifference))
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, primaryDomain, params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, primaryDomain, params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON, constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, primaryDomain, params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, primaryDomain, params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -253,12 +251,11 @@ func loadSSLInfo(alert dto.AlertDTO) {
|
||||||
create.AlertDetail = alertDetail
|
create.AlertDetail = alertDetail
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON, constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON)
|
|
||||||
global.LOG.Info("SSL alert push successful")
|
global.LOG.Info("SSL alert push successful")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,7 +302,11 @@ func loadWebsiteInfo(alert dto.AlertDTO) {
|
||||||
params = createAlertBaseParams(strconv.Itoa(len(websites)), strconv.Itoa(daysDifference))
|
params = createAlertBaseParams(strconv.Itoa(len(websites)), strconv.Itoa(daysDifference))
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, primaryDomain, params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, primaryDomain, params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON, constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, primaryDomain, params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, primaryDomain, params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -313,11 +314,11 @@ func loadWebsiteInfo(alert dto.AlertDTO) {
|
||||||
create.AlertRule = alertRule
|
create.AlertRule = alertRule
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON, constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alertUtil.CreateNewAlertTask(alert.Project, alert.Type, projectJSON)
|
|
||||||
global.LOG.Info("website expiration alert push successful")
|
global.LOG.Info("website expiration alert push successful")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,7 +359,11 @@ func loadPanelPwd(alert dto.AlertDTO) {
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, strconv.Itoa(daysDifference), params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, strconv.Itoa(daysDifference), params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(expirationTime.Value, alert.Type, expirationTime.Value, constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, strconv.Itoa(daysDifference), params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, strconv.Itoa(daysDifference), params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -366,10 +371,10 @@ func loadPanelPwd(alert dto.AlertDTO) {
|
||||||
create.AlertDetail = alertDetail
|
create.AlertDetail = alertDetail
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(expirationTime.Value, alert.Type, expirationTime.Value, constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alertUtil.CreateNewAlertTask(expirationTime.Value, alert.Type, expirationTime.Value)
|
|
||||||
global.LOG.Info("panel password expiration alert push successful")
|
global.LOG.Info("panel password expiration alert push successful")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +416,11 @@ func loadPanelUpdate(alert dto.AlertDTO) {
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, version, params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, version, params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(version, alert.Type, version, constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, version, params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, version, params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -419,10 +428,10 @@ func loadPanelUpdate(alert dto.AlertDTO) {
|
||||||
create.AlertDetail = alertDetail
|
create.AlertDetail = alertDetail
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(version, alert.Type, version, constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alertUtil.CreateNewAlertTask(version, alert.Type, version)
|
|
||||||
global.LOG.Info("panel update alert push successful")
|
global.LOG.Info("panel update alert push successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,7 +595,11 @@ func createAndLogAlert(alert dto.AlertDTO, avgUsage float64, todayCount uint) {
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, avgUsagePercent, params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, avgUsagePercent, params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(avgUsagePercent, alert.Type, strconv.Itoa(int(alert.Cycle)), constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, avgUsagePercent, params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, avgUsagePercent, params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -594,10 +607,10 @@ func createAndLogAlert(alert dto.AlertDTO, avgUsage float64, todayCount uint) {
|
||||||
create.AlertDetail = alertDetail
|
create.AlertDetail = alertDetail
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(avgUsagePercent, alert.Type, strconv.Itoa(int(alert.Cycle)), constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alertUtil.CreateNewAlertTask(avgUsagePercent, alert.Type, strconv.Itoa(int(alert.Cycle)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getModule(alertType string) string {
|
func getModule(alertType string) string {
|
||||||
|
@ -649,25 +662,20 @@ func processAllDisks(alert dto.AlertDTO, todayCount uint) error {
|
||||||
flag = true
|
flag = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag {
|
if flag {
|
||||||
alertUtil.CreateNewAlertTask(strconv.Itoa(int(alert.Cycle)), alert.Type, alert.Project)
|
|
||||||
global.LOG.Info("all disk alert push successful")
|
global.LOG.Info("all disk alert push successful")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSingleDisk(alert dto.AlertDTO, todayCount uint) error {
|
func processSingleDisk(alert dto.AlertDTO, todayCount uint) error {
|
||||||
|
|
||||||
success, err := checkAndCreateDiskAlert(alert, alert.Project, todayCount)
|
success, err := checkAndCreateDiskAlert(alert, alert.Project, todayCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if success {
|
if success {
|
||||||
alertUtil.CreateNewAlertTask(strconv.Itoa(int(alert.Cycle)), alert.Type, alert.Project)
|
|
||||||
global.LOG.Info("disk alert push successful")
|
global.LOG.Info("disk alert push successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,7 +708,11 @@ func checkAndCreateDiskAlert(alert dto.AlertDTO, path string, todayCount uint) (
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateSMSAlertLog(alert, create, path, params, constant.SMS)
|
_ = xpack.CreateSMSAlertLog(alert, create, path, params, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(strconv.Itoa(int(alert.Cycle)), alert.Type, alert.Project, constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
alertDetail := alertUtil.ProcessAlertDetail(alert, path, params, constant.Email)
|
alertDetail := alertUtil.ProcessAlertDetail(alert, path, params, constant.Email)
|
||||||
alertRule := alertUtil.ProcessAlertRule(alert)
|
alertRule := alertUtil.ProcessAlertRule(alert)
|
||||||
|
@ -708,6 +720,7 @@ func checkAndCreateDiskAlert(alert dto.AlertDTO, path string, todayCount uint) (
|
||||||
create.AlertDetail = alertDetail
|
create.AlertDetail = alertDetail
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
_ = alertUtil.CreateEmailAlertLog(create, alert, params, transport)
|
||||||
|
alertUtil.CreateNewAlertTask(strconv.Itoa(int(alert.Cycle)), alert.Type, alert.Project, constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ func InitAgentDB() {
|
||||||
migrations.AddTableAlert,
|
migrations.AddTableAlert,
|
||||||
migrations.InitAlertConfig,
|
migrations.InitAlertConfig,
|
||||||
migrations.AddMethodToAlertLog,
|
migrations.AddMethodToAlertLog,
|
||||||
|
migrations.AddMethodToAlertTask,
|
||||||
})
|
})
|
||||||
if err := m.Migrate(); err != nil {
|
if err := m.Migrate(); err != nil {
|
||||||
global.LOG.Error(err)
|
global.LOG.Error(err)
|
||||||
|
|
|
@ -376,13 +376,13 @@ var InitAlertConfig = &gormigrate.Migration{
|
||||||
Type: "sms",
|
Type: "sms",
|
||||||
Title: "xpack.alert.smsConfig",
|
Title: "xpack.alert.smsConfig",
|
||||||
Status: "Enable",
|
Status: "Enable",
|
||||||
Config: "{}",
|
Config: `{"alertDailyNum":50}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: "common",
|
Type: "common",
|
||||||
Title: "xpack.alert.commonConfig",
|
Title: "xpack.alert.commonConfig",
|
||||||
Status: "Enable",
|
Status: "Enable",
|
||||||
Config: `{"alertDailyNum":50,"isOffline":"Disable","alertSendTimeRange":{"noticeAlert":{"sendTimeRange":"08:00:00 - 23:59:59","type":["ssl","siteEndTime","panelPwdEndTime","panelUpdate"]},"resourceAlert":{"sendTimeRange":"00:00:00 - 23:59:59","type":["clams","cronJob","cpu","memory","load","disk"]}}}`,
|
Config: `{"isOffline":"Disable","alertSendTimeRange":{"noticeAlert":{"sendTimeRange":"08:00:00 - 23:59:59","type":["ssl","siteEndTime","panelPwdEndTime","panelUpdate"]},"resourceAlert":{"sendTimeRange":"00:00:00 - 23:59:59","type":["clams","cronJob","cpu","memory","load","disk"]}}}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, r := range records {
|
for _, r := range records {
|
||||||
|
@ -406,3 +406,16 @@ var AddMethodToAlertLog = &gormigrate.Migration{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AddMethodToAlertTask = &gormigrate.Migration{
|
||||||
|
ID: "20250723-add-method-to-alert_task",
|
||||||
|
Migrate: func(tx *gorm.DB) error {
|
||||||
|
if err := global.AlertDB.AutoMigrate(&model.AlertTask{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := global.AlertDB.Model(&model.AlertTask{}).Where("method IS NULL OR method = ''").Update("method", "sms").Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -100,12 +100,13 @@ func SaveAlertLog(create dto.AlertLogCreate, alertLog *model.AlertLog) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewAlertTask(quota, alertType, quotaType string) {
|
func CreateNewAlertTask(quota, alertType, quotaType, method string) {
|
||||||
alertRepo := repo.NewIAlertRepo()
|
alertRepo := repo.NewIAlertRepo()
|
||||||
taskBase := model.AlertTask{
|
taskBase := model.AlertTask{
|
||||||
Type: alertType,
|
Type: alertType,
|
||||||
Quota: quota,
|
Quota: quota,
|
||||||
QuotaType: quotaType,
|
QuotaType: quotaType,
|
||||||
|
Method: method,
|
||||||
}
|
}
|
||||||
err := alertRepo.CreateAlertTask(&taskBase)
|
err := alertRepo.CreateAlertTask(&taskBase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -190,20 +191,20 @@ func CreateAlertParams(param string) []dto.Param {
|
||||||
|
|
||||||
var checkTaskMutex sync.Mutex
|
var checkTaskMutex sync.Mutex
|
||||||
|
|
||||||
func CheckTaskFrequency() bool {
|
func CheckTaskFrequency(method string) bool {
|
||||||
alertRepo := repo.NewIAlertRepo()
|
alertRepo := repo.NewIAlertRepo()
|
||||||
config, err := alertRepo.GetConfig(alertRepo.WithByType(constant.CommonConfig))
|
config, err := alertRepo.GetConfig(alertRepo.WithByType(constant.SMSConfig))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var cfg dto.AlertCommonConfig
|
var cfg dto.AlertSmsConfig
|
||||||
err = json.Unmarshal([]byte(config.Config), &cfg)
|
err = json.Unmarshal([]byte(config.Config), &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
limitCount := cfg.AlertDailyNum
|
limitCount := cfg.AlertDailyNum
|
||||||
checkTaskMutex.Lock()
|
checkTaskMutex.Lock()
|
||||||
todayCount, err := repo.NewIAlertRepo().GetLicensePushCount()
|
todayCount, err := alertRepo.GetLicensePushCount(method)
|
||||||
defer checkTaskMutex.Unlock()
|
defer checkTaskMutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.LOG.Errorf("error getting license push count info, err: %v", err)
|
global.LOG.Errorf("error getting license push count info, err: %v", err)
|
||||||
|
|
|
@ -13,10 +13,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func PushAlert(pushAlert dto.PushAlert) error {
|
func PushAlert(pushAlert dto.PushAlert) error {
|
||||||
if !alertUtil.CheckTaskFrequency() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !alertUtil.CheckSendTimeRange(alertUtil.GetCronJobType(pushAlert.AlertType)) {
|
if !alertUtil.CheckSendTimeRange(alertUtil.GetCronJobType(pushAlert.AlertType)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -45,18 +41,21 @@ func PushAlert(pushAlert dto.PushAlert) error {
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch m {
|
switch m {
|
||||||
case constant.SMS:
|
case constant.SMS:
|
||||||
|
if !alertUtil.CheckTaskFrequency(constant.SMS) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
_ = xpack.CreateTaskScanSMSAlertLog(alert, create, pushAlert, constant.SMS)
|
_ = xpack.CreateTaskScanSMSAlertLog(alert, create, pushAlert, constant.SMS)
|
||||||
|
alertUtil.CreateNewAlertTask(strconv.Itoa(int(pushAlert.EntryID)), alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), constant.SMS)
|
||||||
case constant.Email:
|
case constant.Email:
|
||||||
transport := xpack.LoadRequestTransport()
|
transport := xpack.LoadRequestTransport()
|
||||||
err := alertUtil.CreateTaskScanEmailAlertLog(alert, create, pushAlert, constant.Email, transport)
|
err := alertUtil.CreateTaskScanEmailAlertLog(alert, create, pushAlert, constant.Email, transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
alertUtil.CreateNewAlertTask(strconv.Itoa(int(pushAlert.EntryID)), alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), constant.Email)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 处理告警任务
|
|
||||||
alertUtil.CreateNewAlertTask(strconv.Itoa(int(pushAlert.EntryID)), alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)))
|
|
||||||
global.LOG.Infof("%s alert push successful", alert.Type)
|
global.LOG.Infof("%s alert push successful", alert.Type)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,4 +253,10 @@ export namespace Setting {
|
||||||
force: boolean;
|
force: boolean;
|
||||||
withDockerRestart: boolean;
|
withDockerRestart: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SmsInfo {
|
||||||
|
licenseName: string;
|
||||||
|
smsUsed: number;
|
||||||
|
smsTotal: number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ export const listAllNodes = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLicenseSmsInfo = () => {
|
export const getLicenseSmsInfo = () => {
|
||||||
return http.get<Setting.LicenseStatus>(`/core/licenses/sms/info`);
|
return http.get<Setting.SmsInfo>(`/core/licenses/sms/info`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// agent
|
// agent
|
||||||
|
|
|
@ -818,7 +818,7 @@ const form = reactive<Cronjob.CronjobInfo>({
|
||||||
status: '',
|
status: '',
|
||||||
secret: '',
|
secret: '',
|
||||||
hasAlert: false,
|
hasAlert: false,
|
||||||
alertCount: 0,
|
alertCount: 3,
|
||||||
alertTitle: '',
|
alertTitle: '',
|
||||||
alertMethod: '',
|
alertMethod: '',
|
||||||
alertMethodItems: [],
|
alertMethodItems: [],
|
||||||
|
|
|
@ -19,10 +19,6 @@
|
||||||
>
|
>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col>
|
<el-col>
|
||||||
<el-form-item :label="$t('xpack.alert.dailyAlertNum')" prop="dailyAlertNum">
|
|
||||||
{{ commonConfig.config.alertDailyNum }}
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item :label="$t('xpack.alert.sendTimeRange')" prop="sendTimeRange">
|
<el-form-item :label="$t('xpack.alert.sendTimeRange')" prop="sendTimeRange">
|
||||||
{{ sendTimeRange }}
|
{{ sendTimeRange }}
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
@ -111,19 +107,40 @@
|
||||||
v-if="globalStore.isProductPro && !globalStore.isIntl"
|
v-if="globalStore.isProductPro && !globalStore.isIntl"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between mb-2">
|
<div class="flex items-center justify-between mb-2">
|
||||||
<div class="text-lg font-semibold">{{ $t('xpack.alert.smsConfig') }}</div>
|
<div class="text-lg font-semibold">
|
||||||
|
{{ $t('xpack.alert.smsConfig') }}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<el-button plain round @click="onChangePhone(smsConfig.id)">
|
<el-button plain round @click="onChangePhone(smsConfig.id)">
|
||||||
{{ $t('commons.button.edit') }}
|
{{ $t('commons.button.edit') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm mb-2">{{ $t('xpack.alert.smsConfigHelper') }}</div>
|
<!-- <div class="text-sm mb-2">{{ $t('xpack.alert.smsConfigHelper') }}</div>-->
|
||||||
|
<div class="text-sm mb-2">
|
||||||
|
{{ $t('xpack.alert.alertSmsHelper', [totalSms, usedSms]) }}
|
||||||
|
<el-link class="ml-1 text-xs" @click="goBuy" type="primary" icon="Position">
|
||||||
|
<span class="ml-0.5">{{ $t('xpack.alert.goBuy') }}</span>
|
||||||
|
</el-link>
|
||||||
|
</div>
|
||||||
<el-divider class="!mb-2 !mt-3" />
|
<el-divider class="!mb-2 !mt-3" />
|
||||||
<el-form-item :label="$t('xpack.alert.phone')">
|
<div class="text-sm email-form">
|
||||||
<span v-if="smsConfig.config.phone">{{ smsConfig.config.phone }}</span>
|
<el-form
|
||||||
<span v-else class="label">{{ $t('xpack.alert.defaultPhone') }}</span>
|
:model="form"
|
||||||
</el-form-item>
|
@submit.prevent
|
||||||
|
ref="alertFormRef"
|
||||||
|
:label-position="mobile ? 'top' : 'left'"
|
||||||
|
label-width="110px"
|
||||||
|
>
|
||||||
|
<el-form-item :label="$t('xpack.alert.phone')">
|
||||||
|
<span v-if="smsConfig.config.phone">{{ smsConfig.config.phone }}</span>
|
||||||
|
<span v-else class="label">{{ $t('xpack.alert.defaultPhone') }}</span>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item :label="$t('xpack.alert.dailyAlertNum')" prop="dailyAlertNum">
|
||||||
|
{{ smsConfig.config.alertDailyNum }}
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -147,6 +164,7 @@ import { storeToRefs } from 'pinia';
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import EmailDrawer from '@/views/setting/alert/setting/email/index.vue';
|
import EmailDrawer from '@/views/setting/alert/setting/email/index.vue';
|
||||||
import { Alert } from '@/api/interface/alert';
|
import { Alert } from '@/api/interface/alert';
|
||||||
|
import { getLicenseSmsInfo } from '@/api/modules/setting';
|
||||||
|
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
const { isMaster } = storeToRefs(globalStore);
|
const { isMaster } = storeToRefs(globalStore);
|
||||||
|
@ -201,7 +219,6 @@ export interface CommonConfig {
|
||||||
status: string;
|
status: string;
|
||||||
config: {
|
config: {
|
||||||
isOffline?: string;
|
isOffline?: string;
|
||||||
alertDailyNum?: number;
|
|
||||||
alertSendTimeRange?: string;
|
alertSendTimeRange?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -209,9 +226,8 @@ const defaultCommonConfig: CommonConfig = {
|
||||||
id: undefined,
|
id: undefined,
|
||||||
type: 'common',
|
type: 'common',
|
||||||
title: 'xpack.alert.commonConfig',
|
title: 'xpack.alert.commonConfig',
|
||||||
status: 'Ena ble',
|
status: 'Enable',
|
||||||
config: {
|
config: {
|
||||||
alertDailyNum: 50,
|
|
||||||
alertSendTimeRange:
|
alertSendTimeRange:
|
||||||
i18n.global.t('xpack.alert.noticeAlert') +
|
i18n.global.t('xpack.alert.noticeAlert') +
|
||||||
': ' +
|
': ' +
|
||||||
|
@ -233,6 +249,7 @@ export interface SmsConfig {
|
||||||
status: string;
|
status: string;
|
||||||
config: {
|
config: {
|
||||||
phone?: string;
|
phone?: string;
|
||||||
|
alertDailyNum?: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const defaultSmsConfig: SmsConfig = {
|
const defaultSmsConfig: SmsConfig = {
|
||||||
|
@ -242,6 +259,7 @@ const defaultSmsConfig: SmsConfig = {
|
||||||
status: 'Enable',
|
status: 'Enable',
|
||||||
config: {
|
config: {
|
||||||
phone: '',
|
phone: '',
|
||||||
|
alertDailyNum: 50,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const smsConfig = ref<SmsConfig>({ ...defaultSmsConfig });
|
const smsConfig = ref<SmsConfig>({ ...defaultSmsConfig });
|
||||||
|
@ -253,6 +271,9 @@ const config = ref<Alert.AlertConfigInfo>({
|
||||||
status: '',
|
status: '',
|
||||||
config: '',
|
config: '',
|
||||||
});
|
});
|
||||||
|
const licenseName = ref('-');
|
||||||
|
const totalSms = ref(0);
|
||||||
|
const usedSms = ref(0);
|
||||||
const mobile = computed(() => {
|
const mobile = computed(() => {
|
||||||
return globalStore.isMobile();
|
return globalStore.isMobile();
|
||||||
});
|
});
|
||||||
|
@ -314,13 +335,16 @@ const search = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onChangePhone = (id: any) => {
|
const onChangePhone = (id: any) => {
|
||||||
phoneRef.value.acceptParams({ id: id, phone: smsConfig.value.config.phone });
|
phoneRef.value.acceptParams({
|
||||||
|
id: id,
|
||||||
|
phone: smsConfig.value.config.phone,
|
||||||
|
dailyAlertNum: smsConfig.value.config.alertDailyNum,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onChangeCommon = (id: any) => {
|
const onChangeCommon = (id: any) => {
|
||||||
sendTimeRangeRef.value.acceptParams({
|
sendTimeRangeRef.value.acceptParams({
|
||||||
id: id,
|
id: id,
|
||||||
dailyAlertNum: commonConfig.value.config.alertDailyNum,
|
|
||||||
sendTimeRange: sendTimeRangeValue.value,
|
sendTimeRange: sendTimeRangeValue.value,
|
||||||
isOffline: commonConfig.value.config.isOffline,
|
isOffline: commonConfig.value.config.isOffline,
|
||||||
});
|
});
|
||||||
|
@ -378,8 +402,24 @@ const onDelete = (id: number) => {
|
||||||
await search();
|
await search();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSmsInfo = async () => {
|
||||||
|
const res = await getLicenseSmsInfo();
|
||||||
|
licenseName.value = res.data.licenseName;
|
||||||
|
usedSms.value = res.data.smsUsed;
|
||||||
|
totalSms.value = res.data.smsTotal;
|
||||||
|
};
|
||||||
|
|
||||||
|
const goBuy = async () => {
|
||||||
|
const uri = licenseName.value === '-' ? '' : `${licenseName.value}/buy-sms`;
|
||||||
|
window.open('https://www.lxware.cn/uc/cloud/licenses/' + uri, '_blank', 'noopener,noreferrer');
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await search();
|
await search();
|
||||||
|
if (globalStore.isProductPro && !globalStore.isIntl) {
|
||||||
|
await getSmsInfo();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
|
@ -7,6 +7,14 @@
|
||||||
<el-input clearable v-model="form.phone" />
|
<el-input clearable v-model="form.phone" />
|
||||||
<span class="input-help">{{ $t('xpack.alert.phoneHelper') }}</span>
|
<span class="input-help">{{ $t('xpack.alert.phoneHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item
|
||||||
|
:label="$t('xpack.alert.dailyAlertNum')"
|
||||||
|
:rules="[Rules.integerNumber, checkNumberRange(20, 100)]"
|
||||||
|
prop="dailyAlertNum"
|
||||||
|
>
|
||||||
|
<el-input clearable v-model.number="form.dailyAlertNum" min="20" max="100" />
|
||||||
|
<span class="input-help">{{ $t('xpack.alert.dailyAlertNumHelper') }}</span>
|
||||||
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
@ -25,12 +33,13 @@ import { reactive, ref } from 'vue';
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import { FormInstance } from 'element-plus';
|
import { FormInstance } from 'element-plus';
|
||||||
import { Rules } from '@/global/form-rules';
|
import { checkNumberRange, Rules } from '@/global/form-rules';
|
||||||
import { UpdateAlertConfig } from '@/api/modules/alert';
|
import { UpdateAlertConfig } from '@/api/modules/alert';
|
||||||
const emit = defineEmits<{ (e: 'search'): void }>();
|
const emit = defineEmits<{ (e: 'search'): void }>();
|
||||||
|
|
||||||
interface DialogProps {
|
interface DialogProps {
|
||||||
phone: string;
|
phone: string;
|
||||||
|
dailyAlertNum: number;
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
const drawerVisible = ref();
|
const drawerVisible = ref();
|
||||||
|
@ -38,6 +47,7 @@ const loading = ref();
|
||||||
|
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
phone: '',
|
phone: '',
|
||||||
|
dailyAlertNum: 50,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,6 +56,7 @@ const formRef = ref<FormInstance>();
|
||||||
const acceptParams = (params: DialogProps): void => {
|
const acceptParams = (params: DialogProps): void => {
|
||||||
form.phone = params.phone;
|
form.phone = params.phone;
|
||||||
form.id = params.id;
|
form.id = params.id;
|
||||||
|
form.dailyAlertNum = Number(params.dailyAlertNum);
|
||||||
drawerVisible.value = true;
|
drawerVisible.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,7 +66,7 @@ const onSave = async (formEl: FormInstance | undefined) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const configInfo = { phone: form.phone };
|
const configInfo = { phone: form.phone, alertDailyNum: form.dailyAlertNum };
|
||||||
await UpdateAlertConfig({
|
await UpdateAlertConfig({
|
||||||
id: form.id,
|
id: form.id,
|
||||||
type: 'sms',
|
type: 'sms',
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<DrawerPro v-model="drawerVisible" :header="$t('xpack.alert.sendTimeRange')" @close="handleClose" size="736">
|
<DrawerPro v-model="drawerVisible" :header="$t('xpack.alert.sendTimeRange')" @close="handleClose" size="736">
|
||||||
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
|
<el-form ref="formRef" label-position="top" @submit.prevent v-loading="loading">
|
||||||
<el-form-item
|
|
||||||
:label="$t('xpack.alert.dailyAlertNum')"
|
|
||||||
:rules="[Rules.integerNumber, checkNumberRange(20, 100)]"
|
|
||||||
prop="dailyAlertNum"
|
|
||||||
>
|
|
||||||
<el-input clearable v-model.number="form.dailyAlertNum" min="20" max="100" />
|
|
||||||
<span class="input-help">{{ $t('xpack.alert.dailyAlertNumHelper') }}</span>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item :label="$t('xpack.alert.sendTimeRange')" prop="sendTimeRange">
|
<el-form-item :label="$t('xpack.alert.sendTimeRange')" prop="sendTimeRange">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<el-transfer
|
<el-transfer
|
||||||
|
@ -64,7 +56,7 @@
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
|
<el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
|
||||||
<el-button :disabled="loading" type="primary" @click="onSave(formRef)">
|
<el-button :disabled="loading" type="primary" @click="onSave()">
|
||||||
{{ $t('commons.button.confirm') }}
|
{{ $t('commons.button.confirm') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</span>
|
</span>
|
||||||
|
@ -72,12 +64,11 @@
|
||||||
</DrawerPro>
|
</DrawerPro>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ComputedRef, reactive, ref } from 'vue';
|
import { computed, ComputedRef, ref } from 'vue';
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||||
import { FormInstance } from 'element-plus';
|
import { FormInstance } from 'element-plus';
|
||||||
import { UpdateAlertConfig } from '@/api/modules/alert';
|
import { UpdateAlertConfig } from '@/api/modules/alert';
|
||||||
import { checkNumberRange, Rules } from '@/global/form-rules';
|
|
||||||
import { Alert } from '@/api/interface/alert';
|
import { Alert } from '@/api/interface/alert';
|
||||||
|
|
||||||
const emit = defineEmits<{ (e: 'search'): void }>();
|
const emit = defineEmits<{ (e: 'search'): void }>();
|
||||||
|
@ -105,26 +96,20 @@ interface SendTimeRange {
|
||||||
|
|
||||||
interface DialogProps {
|
interface DialogProps {
|
||||||
id: any;
|
id: any;
|
||||||
dailyAlertNum: number;
|
|
||||||
sendTimeRange: SendTimeRange;
|
sendTimeRange: SendTimeRange;
|
||||||
isOffline: string;
|
isOffline: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConfigInfo {
|
interface ConfigInfo {
|
||||||
alertDailyNum: number;
|
|
||||||
alertSendTimeRange: SendTimeRange;
|
alertSendTimeRange: SendTimeRange;
|
||||||
isOffline: string;
|
isOffline: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const drawerVisible = ref(false);
|
const drawerVisible = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const form = reactive({
|
|
||||||
dailyAlertNum: 50,
|
|
||||||
});
|
|
||||||
const isOffline = ref();
|
const isOffline = ref();
|
||||||
const id = ref();
|
const id = ref();
|
||||||
const configInfo = ref<ConfigInfo>({
|
const configInfo = ref<ConfigInfo>({
|
||||||
alertDailyNum: 0,
|
|
||||||
isOffline: '',
|
isOffline: '',
|
||||||
alertSendTimeRange: {
|
alertSendTimeRange: {
|
||||||
noticeAlert: { sendTimeRange: '', type: [] },
|
noticeAlert: { sendTimeRange: '', type: [] },
|
||||||
|
@ -170,53 +155,45 @@ const acceptParams = (params: DialogProps): void => {
|
||||||
resourceTimeRange.value = parseTimeRange(params.sendTimeRange.resourceAlert.sendTimeRange);
|
resourceTimeRange.value = parseTimeRange(params.sendTimeRange.resourceAlert.sendTimeRange);
|
||||||
resourceValue.value = params.sendTimeRange.resourceAlert.type;
|
resourceValue.value = params.sendTimeRange.resourceAlert.type;
|
||||||
}
|
}
|
||||||
form.dailyAlertNum = Number(params.dailyAlertNum);
|
|
||||||
isOffline.value = params.isOffline;
|
isOffline.value = params.isOffline;
|
||||||
id.value = params.id;
|
id.value = params.id;
|
||||||
drawerVisible.value = true;
|
drawerVisible.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSave = async (formEl: FormInstance | undefined) => {
|
const onSave = async () => {
|
||||||
if (!formEl) return;
|
if (
|
||||||
formEl.validate(async (valid) => {
|
typeof noticeTimeRange.value === 'object' &&
|
||||||
if (!valid) return;
|
noticeTimeRange.value !== null &&
|
||||||
if (
|
typeof resourceTimeRange.value === 'object' &&
|
||||||
typeof noticeTimeRange.value === 'object' &&
|
resourceTimeRange.value !== null
|
||||||
noticeTimeRange.value !== null &&
|
) {
|
||||||
typeof resourceTimeRange.value === 'object' &&
|
loading.value = true;
|
||||||
resourceTimeRange.value !== null
|
configInfo.value.alertSendTimeRange = {
|
||||||
) {
|
noticeAlert: { sendTimeRange: stringifyTimeRange(noticeTimeRange.value), type: noticeValue.value },
|
||||||
loading.value = true;
|
resourceAlert: {
|
||||||
configInfo.value.alertSendTimeRange = {
|
sendTimeRange: stringifyTimeRange(resourceTimeRange.value),
|
||||||
noticeAlert: { sendTimeRange: stringifyTimeRange(noticeTimeRange.value), type: noticeValue.value },
|
type: resourceValue.value,
|
||||||
resourceAlert: {
|
},
|
||||||
sendTimeRange: stringifyTimeRange(resourceTimeRange.value),
|
};
|
||||||
type: resourceValue.value,
|
configInfo.value.isOffline = isOffline.value;
|
||||||
},
|
try {
|
||||||
};
|
config.value.id = id.value;
|
||||||
configInfo.value.isOffline = isOffline.value;
|
config.value.type = 'common';
|
||||||
configInfo.value.alertDailyNum = form.dailyAlertNum;
|
config.value.title = 'xpack.alert.commonConfig';
|
||||||
try {
|
config.value.status = 'Enable';
|
||||||
config.value.id = id.value;
|
config.value.config = JSON.stringify(configInfo.value);
|
||||||
config.value.type = 'common';
|
await UpdateAlertConfig(config.value);
|
||||||
config.value.title = 'xpack.alert.commonConfig';
|
|
||||||
config.value.status = 'Enable';
|
|
||||||
config.value.config = JSON.stringify(configInfo.value);
|
|
||||||
await UpdateAlertConfig(config.value);
|
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
handleClose();
|
handleClose();
|
||||||
emit('search');
|
emit('search');
|
||||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MsgError(
|
|
||||||
i18n.global.t('commons.msg.confirmNoNull', [i18n.global.t('xpack.alert.timeRange').toLowerCase()]),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
MsgError(i18n.global.t('commons.msg.confirmNoNull', [i18n.global.t('xpack.alert.timeRange').toLowerCase()]));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseTimeRange = (timeRangeStr: string): [Date, Date] => {
|
const parseTimeRange = (timeRangeStr: string): [Date, Date] => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue