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

Method CreateAlert

agent/app/service/alert.go:141–180  ·  view source on GitHub ↗
(create dto.AlertCreate, operator string)

Source from the content-addressed store, hash-verified

139}
140
141func (a AlertService) CreateAlert(create dto.AlertCreate, operator string) error {
142 if err := a.validateCommunityAlertMethod(create.Method); err != nil {
143 return err
144 }
145 var alertID uint
146 var alertInfo model.Alert
147 if create.Project != "" {
148 alertInfo, _ := alertRepo.Get(alertRepo.WithByType(create.Type), alertRepo.WithByProject(create.Project))
149 alertID = alertInfo.ID
150 } else {
151 alertInfo, _ := alertRepo.Get(alertRepo.WithByType(create.Type))
152 alertID = alertInfo.ID
153 }
154
155 if alertID != 0 {
156 var upAlert dto.AlertUpdate
157 if err := copier.Copy(&upAlert, &create); err != nil {
158 return buserr.WithErr("ErrStructTransform", err)
159 }
160 upAlert.ID = alertID
161 err := a.UpdateAlert(upAlert, operator)
162 if err != nil {
163 return err
164 }
165 } else {
166 alertInfo.Status = constant.AlertEnable
167 if err := copier.Copy(&alertInfo, &create); err != nil {
168 return buserr.WithErr("ErrStructTransform", err)
169 }
170 alertInfo.CreateUser = operator
171 alertInfo.UpdateUser = operator
172
173 if err := alertRepo.Create(&alertInfo); err != nil {
174 return err
175 }
176 NewIAlertTaskHelper().InitTask(alertInfo.Type)
177 }
178
179 return nil
180}
181
182func (a AlertService) UpdateAlert(req dto.AlertUpdate, operator string) error {
183 if err := a.validateCommunityAlertMethod(req.Method); err != nil {

Callers 1

ExternalUpdateAlertMethod · 0.95

Calls 9

UpdateAlertMethod · 0.95
NewIAlertTaskHelperFunction · 0.85
CopyMethod · 0.80
GetMethod · 0.65
WithByTypeMethod · 0.65
WithByProjectMethod · 0.65
CreateMethod · 0.65
InitTaskMethod · 0.65

Tested by

no test coverage detected