mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-12 08:26:50 +08:00
fix: Fix errors in creating cron job and clam alerts (#9910)
This commit is contained in:
parent
2b7ec9ffe1
commit
c49c16cbb5
3 changed files with 41 additions and 13 deletions
|
@ -483,23 +483,51 @@ func (a AlertService) TestAlertConfig(req dto.AlertConfigTest) (bool, error) {
|
|||
|
||||
func (a AlertService) ExternalUpdateAlert(updateAlert dto.AlertCreate) error {
|
||||
upMap := make(map[string]interface{})
|
||||
var newStatus string
|
||||
if updateAlert.SendCount == 0 {
|
||||
upMap["status"] = constant.AlertDisable
|
||||
newStatus = constant.AlertDisable
|
||||
} else {
|
||||
upMap["status"] = constant.AlertEnable
|
||||
newStatus = constant.AlertEnable
|
||||
upMap["send_count"] = updateAlert.SendCount
|
||||
if updateAlert.Method != "" {
|
||||
upMap["method"] = updateAlert.Method
|
||||
}
|
||||
}
|
||||
upMap["method"] = updateAlert.Method
|
||||
alertInfo, _ := alertRepo.Get(alertRepo.WithByType(updateAlert.Type), alertRepo.WithByProject(updateAlert.Project))
|
||||
upMap["status"] = newStatus
|
||||
|
||||
alertInfo, _ := alertRepo.Get(
|
||||
alertRepo.WithByType(updateAlert.Type),
|
||||
alertRepo.WithByProject(updateAlert.Project),
|
||||
)
|
||||
|
||||
if alertInfo.ID > 0 {
|
||||
if err := alertRepo.Update(upMap, alertRepo.WithByProject(updateAlert.Project), alertRepo.WithByType(updateAlert.Type)); err != nil {
|
||||
return err
|
||||
shouldUpdate := false
|
||||
|
||||
if alertInfo.Status != newStatus {
|
||||
shouldUpdate = true
|
||||
}
|
||||
if val, ok := upMap["send_count"]; ok && val != alertInfo.SendCount {
|
||||
shouldUpdate = true
|
||||
}
|
||||
if val, ok := upMap["method"]; ok && val != "" && val != alertInfo.Method {
|
||||
shouldUpdate = true
|
||||
}
|
||||
|
||||
if shouldUpdate {
|
||||
if err := alertRepo.Update(
|
||||
upMap,
|
||||
alertRepo.WithByProject(updateAlert.Project),
|
||||
alertRepo.WithByType(updateAlert.Type),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateAlert.Status = constant.AlertEnable
|
||||
err := a.CreateAlert(updateAlert)
|
||||
if err != nil {
|
||||
return err
|
||||
if updateAlert.Method != "" && updateAlert.Title != "" {
|
||||
updateAlert.Status = newStatus
|
||||
if err := a.CreateAlert(updateAlert); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ func (c *ClamService) Create(req dto.ClamCreate) error {
|
|||
if err := clamRepo.Create(&clam); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.AlertCount != 0 {
|
||||
if req.AlertCount != 0 && req.AlertTitle != "" && req.AlertMethod != "" {
|
||||
createAlert := dto.AlertCreate{
|
||||
Title: req.AlertTitle,
|
||||
SendCount: req.AlertCount,
|
||||
|
|
|
@ -381,7 +381,7 @@ func (u *CronjobService) Import(req []dto.CronjobTrans) error {
|
|||
cronjob.Status = constant.StatusDisable
|
||||
}
|
||||
_ = cronjobRepo.Create(&cronjob)
|
||||
if item.AlertCount != 0 {
|
||||
if item.AlertCount != 0 && item.AlertTitle != "" && item.AlertMethod != "" {
|
||||
createAlert := dto.AlertCreate{
|
||||
Title: item.AlertTitle,
|
||||
SendCount: item.AlertCount,
|
||||
|
@ -579,7 +579,7 @@ func (u *CronjobService) Create(req dto.CronjobOperate) error {
|
|||
if err := cronjobRepo.Create(&cronjob); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.AlertCount != 0 {
|
||||
if req.AlertCount != 0 && req.AlertTitle != "" && req.AlertMethod != "" {
|
||||
createAlert := dto.AlertCreate{
|
||||
Title: req.AlertTitle,
|
||||
SendCount: req.AlertCount,
|
||||
|
|
Loading…
Add table
Reference in a new issue