MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / ExternalUpdateAlert

Method ExternalUpdateAlert

agent/app/service/alert.go:700–754  ·  view source on GitHub ↗
(updateAlert dto.AlertCreate, operator string)

Source from the content-addressed store, hash-verified

698}
699
700func (a AlertService) ExternalUpdateAlert(updateAlert dto.AlertCreate, operator string) error {
701 if err := a.validateCommunityAlertMethod(updateAlert.Method); err != nil {
702 return err
703 }
704 upMap := make(map[string]interface{})
705 var newStatus string
706 if updateAlert.SendCount == 0 {
707 newStatus = constant.AlertDisable
708 } else {
709 newStatus = constant.AlertEnable
710 upMap["send_count"] = updateAlert.SendCount
711 if updateAlert.Method != "" {
712 upMap["method"] = updateAlert.Method
713 }
714 }
715 upMap["status"] = newStatus
716
717 alertInfo, _ := alertRepo.Get(
718 alertRepo.WithByType(updateAlert.Type),
719 alertRepo.WithByProject(updateAlert.Project),
720 )
721
722 if alertInfo.ID > 0 {
723 shouldUpdate := false
724
725 if alertInfo.Status != newStatus {
726 shouldUpdate = true
727 }
728 if val, ok := upMap["send_count"]; ok && val != alertInfo.SendCount {
729 shouldUpdate = true
730 }
731 if val, ok := upMap["method"]; ok && val != "" && val != alertInfo.Method {
732 shouldUpdate = true
733 }
734
735 if shouldUpdate {
736 if err := alertRepo.Update(
737 upMap,
738 alertRepo.WithByProject(updateAlert.Project),
739 alertRepo.WithByType(updateAlert.Type),
740 ); err != nil {
741 return err
742 }
743 }
744 } else {
745 if updateAlert.Method != "" && updateAlert.Title != "" {
746 updateAlert.Status = newStatus
747 if err := a.CreateAlert(updateAlert, operator); err != nil {
748 return err
749 }
750 }
751 }
752
753 return nil
754}

Callers

nothing calls this directly

Calls 6

CreateAlertMethod · 0.95
GetMethod · 0.65
WithByTypeMethod · 0.65
WithByProjectMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected