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

Function sendAlert

agent/utils/alert_push/alert_push.go:69–161  ·  view source on GitHub ↗
(alertRepo repo.IAlertRepo, alert dto.AlertDTO, pushAlert dto.PushAlert, config model.AlertConfig)

Source from the content-addressed store, hash-verified

67}
68
69func sendAlert(alertRepo repo.IAlertRepo, alert dto.AlertDTO, pushAlert dto.PushAlert, config model.AlertConfig) {
70 if !alertUtil.IsAlertConfigEnabled(config) {
71 return
72 }
73 methodStr := strconv.Itoa(int(config.ID))
74 switch config.Type {
75 case constant.SMS:
76 if !alertUtil.CheckSMSSendLimit(config, methodStr) {
77 return
78 }
79 todayCount, _, err := alertRepo.LoadTaskCount(alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), methodStr)
80 if err != nil || alert.SendCount <= todayCount {
81 return
82 }
83 create := dto.AlertLogCreate{
84 Type: alertUtil.GetCronJobType(alert.Type),
85 AlertId: alert.ID,
86 Count: todayCount + 1,
87 Method: methodStr,
88 }
89 err = xpack.AlertProvider.CreateTaskScanSMSAlertLog(alert, alert.Type, create, pushAlert, config, methodStr)
90 if err != nil {
91 global.LOG.Errorf("%s alert sms push failed: %v", alert.Type, err)
92 return
93 }
94 alertUtil.CreateNewAlertTask(strconv.Itoa(int(pushAlert.EntryID)), alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), methodStr)
95
96 case constant.Email:
97 todayCount, _, err := alertRepo.LoadTaskCount(alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), methodStr)
98 if err != nil || alert.SendCount <= todayCount {
99 return
100 }
101 create := dto.AlertLogCreate{
102 Type: alertUtil.GetCronJobType(alert.Type),
103 AlertId: alert.ID,
104 Count: todayCount + 1,
105 Method: methodStr,
106 }
107 transport := xpack.MultiNodeProvider.LoadRequestTransport()
108 agentInfo, _ := xpack.MultiNodeProvider.GetAgentInfo()
109 err = alertUtil.CreateTaskScanEmailAlertLog(alert, create, pushAlert, constant.Email, transport, agentInfo, config)
110 if err != nil {
111 global.LOG.Errorf("%s alert email push failed: %v", alert.Type, err)
112 return
113 }
114 alertUtil.CreateNewAlertTask(strconv.Itoa(int(pushAlert.EntryID)), alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), methodStr)
115
116 case constant.Bark:
117 todayCount, _, err := alertRepo.LoadTaskCount(alertUtil.GetCronJobType(alert.Type), strconv.Itoa(int(pushAlert.EntryID)), methodStr)
118 if err != nil || alert.SendCount <= todayCount {
119 return
120 }
121 create := dto.AlertLogCreate{
122 Type: alertUtil.GetCronJobType(alert.Type),
123 AlertId: alert.ID,
124 Count: todayCount + 1,
125 Method: methodStr,
126 }

Callers 2

pushByConfigIdFunction · 0.85
pushByLegacyMethodFunction · 0.85

Calls 5

LoadTaskCountMethod · 0.65
LoadRequestTransportMethod · 0.65
GetAgentInfoMethod · 0.65

Tested by

no test coverage detected