@@ -87,9 +87,6 @@ func (m *AlertTaskHelper) InitTask(alertType string) {
8787
8888func resourceTask (resourceAlert []dto.AlertDTO ) {
8989 for _ , alert := range resourceAlert {
90- if ! alertUtil .CheckTaskFrequency () {
91- return
92- }
9390 if ! alertUtil .CheckSendTimeRange (alert .Type ) {
9491 continue
9592 }
@@ -109,9 +106,6 @@ func resourceTask(resourceAlert []dto.AlertDTO) {
109106
110107func baseTask (baseAlert []dto.AlertDTO ) {
111108 for _ , alert := range baseAlert {
112- if ! alertUtil .CheckTaskFrequency () {
113- return
114- }
115109 if ! alertUtil .CheckSendTimeRange (alert .Type ) {
116110 continue
117111 }
@@ -245,20 +239,23 @@ func loadSSLInfo(alert dto.AlertDTO) {
245239 params = createAlertBaseParams (strconv .Itoa (len (primaryDomain )), strconv .Itoa (daysDifference ))
246240 switch m {
247241 case constant .SMS :
242+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
243+ continue
244+ }
248245 _ = xpack .CreateSMSAlertLog (alert , create , primaryDomain , params , constant .SMS )
246+ alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON , constant .SMS )
249247 case constant .Email :
250248 alertDetail := alertUtil .ProcessAlertDetail (alert , primaryDomain , params , constant .Email )
251249 alertRule := alertUtil .ProcessAlertRule (alert )
252250 create .AlertRule = alertRule
253251 create .AlertDetail = alertDetail
254252 transport := xpack .LoadRequestTransport ()
255253 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
254+ alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON , constant .Email )
256255 default :
257256 }
258257 }
259258 }
260-
261- alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON )
262259 global .LOG .Info ("SSL alert push successful" )
263260 }
264261}
@@ -305,19 +302,23 @@ func loadWebsiteInfo(alert dto.AlertDTO) {
305302 params = createAlertBaseParams (strconv .Itoa (len (websites )), strconv .Itoa (daysDifference ))
306303 switch m {
307304 case constant .SMS :
305+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
306+ continue
307+ }
308308 _ = xpack .CreateSMSAlertLog (alert , create , primaryDomain , params , constant .SMS )
309+ alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON , constant .SMS )
309310 case constant .Email :
310311 alertDetail := alertUtil .ProcessAlertDetail (alert , primaryDomain , params , constant .Email )
311312 alertRule := alertUtil .ProcessAlertRule (alert )
312313 create .AlertDetail = alertDetail
313314 create .AlertRule = alertRule
314315 transport := xpack .LoadRequestTransport ()
315316 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
317+ alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON , constant .Email )
316318 default :
317319 }
318320 }
319321 }
320- alertUtil .CreateNewAlertTask (alert .Project , alert .Type , projectJSON )
321322 global .LOG .Info ("website expiration alert push successful" )
322323 }
323324}
@@ -358,18 +359,22 @@ func loadPanelPwd(alert dto.AlertDTO) {
358359 m = strings .TrimSpace (m )
359360 switch m {
360361 case constant .SMS :
362+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
363+ continue
364+ }
361365 _ = xpack .CreateSMSAlertLog (alert , create , strconv .Itoa (daysDifference ), params , constant .SMS )
366+ alertUtil .CreateNewAlertTask (expirationTime .Value , alert .Type , expirationTime .Value , constant .SMS )
362367 case constant .Email :
363368 alertDetail := alertUtil .ProcessAlertDetail (alert , strconv .Itoa (daysDifference ), params , constant .Email )
364369 alertRule := alertUtil .ProcessAlertRule (alert )
365370 create .AlertRule = alertRule
366371 create .AlertDetail = alertDetail
367372 transport := xpack .LoadRequestTransport ()
368373 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
374+ alertUtil .CreateNewAlertTask (expirationTime .Value , alert .Type , expirationTime .Value , constant .Email )
369375 default :
370376 }
371377 }
372- alertUtil .CreateNewAlertTask (expirationTime .Value , alert .Type , expirationTime .Value )
373378 global .LOG .Info ("panel password expiration alert push successful" )
374379 }
375380}
@@ -411,18 +416,22 @@ func loadPanelUpdate(alert dto.AlertDTO) {
411416 m = strings .TrimSpace (m )
412417 switch m {
413418 case constant .SMS :
419+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
420+ continue
421+ }
414422 _ = xpack .CreateSMSAlertLog (alert , create , version , params , constant .SMS )
423+ alertUtil .CreateNewAlertTask (version , alert .Type , version , constant .SMS )
415424 case constant .Email :
416425 alertDetail := alertUtil .ProcessAlertDetail (alert , version , params , constant .Email )
417426 alertRule := alertUtil .ProcessAlertRule (alert )
418427 create .AlertRule = alertRule
419428 create .AlertDetail = alertDetail
420429 transport := xpack .LoadRequestTransport ()
421430 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
431+ alertUtil .CreateNewAlertTask (version , alert .Type , version , constant .Email )
422432 default :
423433 }
424434 }
425- alertUtil .CreateNewAlertTask (version , alert .Type , version )
426435 global .LOG .Info ("panel update alert push successful" )
427436}
428437
@@ -586,18 +595,22 @@ func createAndLogAlert(alert dto.AlertDTO, avgUsage float64, todayCount uint) {
586595 m = strings .TrimSpace (m )
587596 switch m {
588597 case constant .SMS :
598+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
599+ continue
600+ }
589601 _ = xpack .CreateSMSAlertLog (alert , create , avgUsagePercent , params , constant .SMS )
602+ alertUtil .CreateNewAlertTask (avgUsagePercent , alert .Type , strconv .Itoa (int (alert .Cycle )), constant .SMS )
590603 case constant .Email :
591604 alertDetail := alertUtil .ProcessAlertDetail (alert , avgUsagePercent , params , constant .Email )
592605 alertRule := alertUtil .ProcessAlertRule (alert )
593606 create .AlertRule = alertRule
594607 create .AlertDetail = alertDetail
595608 transport := xpack .LoadRequestTransport ()
596609 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
610+ alertUtil .CreateNewAlertTask (avgUsagePercent , alert .Type , strconv .Itoa (int (alert .Cycle )), constant .Email )
597611 default :
598612 }
599613 }
600- alertUtil .CreateNewAlertTask (avgUsagePercent , alert .Type , strconv .Itoa (int (alert .Cycle )))
601614}
602615
603616func getModule (alertType string ) string {
@@ -649,25 +662,20 @@ func processAllDisks(alert dto.AlertDTO, todayCount uint) error {
649662 flag = true
650663 }
651664 }
652-
653665 if flag {
654- alertUtil .CreateNewAlertTask (strconv .Itoa (int (alert .Cycle )), alert .Type , alert .Project )
655666 global .LOG .Info ("all disk alert push successful" )
656667 }
657668 return nil
658669}
659670
660671func processSingleDisk (alert dto.AlertDTO , todayCount uint ) error {
661-
662672 success , err := checkAndCreateDiskAlert (alert , alert .Project , todayCount )
663673 if err != nil {
664674 return err
665675 }
666676 if success {
667- alertUtil .CreateNewAlertTask (strconv .Itoa (int (alert .Cycle )), alert .Type , alert .Project )
668677 global .LOG .Info ("disk alert push successful" )
669678 }
670-
671679 return nil
672680}
673681
@@ -700,14 +708,19 @@ func checkAndCreateDiskAlert(alert dto.AlertDTO, path string, todayCount uint) (
700708 m = strings .TrimSpace (m )
701709 switch m {
702710 case constant .SMS :
711+ if ! alertUtil .CheckTaskFrequency (constant .SMS ) {
712+ continue
713+ }
703714 _ = xpack .CreateSMSAlertLog (alert , create , path , params , constant .SMS )
715+ alertUtil .CreateNewAlertTask (strconv .Itoa (int (alert .Cycle )), alert .Type , alert .Project , constant .SMS )
704716 case constant .Email :
705717 alertDetail := alertUtil .ProcessAlertDetail (alert , path , params , constant .Email )
706718 alertRule := alertUtil .ProcessAlertRule (alert )
707719 create .AlertRule = alertRule
708720 create .AlertDetail = alertDetail
709721 transport := xpack .LoadRequestTransport ()
710722 _ = alertUtil .CreateEmailAlertLog (create , alert , params , transport )
723+ alertUtil .CreateNewAlertTask (strconv .Itoa (int (alert .Cycle )), alert .Type , alert .Project , constant .Email )
711724 default :
712725 }
713726 }
0 commit comments