add parameter to control whether raise error or not when global channel is not enabled
This commit is contained in:
parent
ba99e26a3a
commit
8afc1f3951
|
@ -72,7 +72,7 @@ func ResolveMessage(messageTemplate string, ctx map[string]interface{}) ([]byte,
|
||||||
return msgBuffer.Bytes(), err
|
return msgBuffer.Bytes(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RetrieveChannel(ch *alerting.Channel) (*alerting.Channel, error) {
|
func RetrieveChannel(ch *alerting.Channel, raiseChannelEnabledErr bool) (*alerting.Channel, error) {
|
||||||
if ch == nil {
|
if ch == nil {
|
||||||
return nil, fmt.Errorf("empty channel")
|
return nil, fmt.Errorf("empty channel")
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,10 @@ func RetrieveChannel(ch *alerting.Channel) (*alerting.Channel, error) {
|
||||||
}
|
}
|
||||||
if !refCh.Enabled {
|
if !refCh.Enabled {
|
||||||
ch.Enabled = false
|
ch.Enabled = false
|
||||||
return ch, fmt.Errorf("global channel is not enabled")
|
if raiseChannelEnabledErr {
|
||||||
|
return ch, fmt.Errorf("global channel is not enabled")
|
||||||
|
}
|
||||||
|
return ch, nil
|
||||||
}
|
}
|
||||||
ch.Type = refCh.Type
|
ch.Type = refCh.Type
|
||||||
ch.Name = refCh.Name
|
ch.Name = refCh.Name
|
||||||
|
|
|
@ -698,7 +698,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
actionResults, _ := performChannels(recoverCfg.Normal, paramsCtx)
|
actionResults, _ := performChannels(recoverCfg.Normal, paramsCtx, false)
|
||||||
alertItem.ActionExecutionResults = actionResults
|
alertItem.ActionExecutionResults = actionResults
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -819,7 +819,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertMessage == nil || period > periodDuration {
|
if alertMessage == nil || period > periodDuration {
|
||||||
actionResults, _ := performChannels(notifyCfg.Normal, paramsCtx)
|
actionResults, _ := performChannels(notifyCfg.Normal, paramsCtx, false)
|
||||||
alertItem.ActionExecutionResults = actionResults
|
alertItem.ActionExecutionResults = actionResults
|
||||||
//change and save last notification time in local kv store when action error count equals zero
|
//change and save last notification time in local kv store when action error count equals zero
|
||||||
rule.LastNotificationTime = time.Now()
|
rule.LastNotificationTime = time.Now()
|
||||||
|
@ -849,7 +849,7 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if time.Now().Sub(rule.LastEscalationTime.Local()) > periodDuration {
|
if time.Now().Sub(rule.LastEscalationTime.Local()) > periodDuration {
|
||||||
actionResults, errCount := performChannels(notifyCfg.Escalation, paramsCtx)
|
actionResults, errCount := performChannels(notifyCfg.Escalation, paramsCtx, false)
|
||||||
alertItem.ActionExecutionResults = actionResults
|
alertItem.ActionExecutionResults = actionResults
|
||||||
//todo init last escalation time when create task (by last alert item is escalated)
|
//todo init last escalation time when create task (by last alert item is escalated)
|
||||||
if errCount == 0 {
|
if errCount == 0 {
|
||||||
|
@ -1025,14 +1025,14 @@ func (engine *Engine) Test(rule *alerting.Rule, msgType string) ([]alerting.Acti
|
||||||
channels = notifyCfg.Normal
|
channels = notifyCfg.Normal
|
||||||
}
|
}
|
||||||
if len(channels) > 0 {
|
if len(channels) > 0 {
|
||||||
actionResults, _ = performChannels(channels, paramsCtx)
|
actionResults, _ = performChannels(channels, paramsCtx, true)
|
||||||
}else{
|
}else{
|
||||||
return nil, fmt.Errorf("no useable channel")
|
return nil, fmt.Errorf("no useable channel")
|
||||||
}
|
}
|
||||||
return actionResults, nil
|
return actionResults, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func performChannels(channels []alerting.Channel, ctx map[string]interface{}) ([]alerting.ActionExecutionResult, int) {
|
func performChannels(channels []alerting.Channel, ctx map[string]interface{}, raiseChannelEnabledErr bool) ([]alerting.ActionExecutionResult, int) {
|
||||||
var errCount int
|
var errCount int
|
||||||
var actionResults []alerting.ActionExecutionResult
|
var actionResults []alerting.ActionExecutionResult
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
|
@ -1041,7 +1041,7 @@ func performChannels(channels []alerting.Channel, ctx map[string]interface{}) ([
|
||||||
resBytes []byte
|
resBytes []byte
|
||||||
messageBytes []byte
|
messageBytes []byte
|
||||||
)
|
)
|
||||||
_, err := common.RetrieveChannel(&channel)
|
_, err := common.RetrieveChannel(&channel, raiseChannelEnabledErr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
errCount++
|
errCount++
|
||||||
|
|
Loading…
Reference in New Issue