@@ -176,22 +176,24 @@ func (l *logMonitor) generateStatus(logs []*systemlogtypes.Log, rule systemlogty
176176 var events []types.Event
177177 var changedConditions []* types.Condition
178178
179- // Support configuring rule.Reason as a Sprintf format string and formatting it with the matched capturing groups in rule.Pattern.
180- re := regexp .MustCompile (rule .Pattern )
181- matches := re .FindStringSubmatch (message )
182179 reason := rule .Reason
183- formatArgs := make ([]interface {}, 0 )
184- if len (matches ) > 1 {
185- // Use the matched capturing groups as the arguments for Sprintf.
186- for _ , value := range matches [1 :] {
187- formatArgs = append (formatArgs , value )
180+ // Support configuring rule.Reason as a Sprintf format string and formatting it with the matched capturing groups in rule.Pattern.
181+ if strings .Contains (reason , "%" ) {
182+ re := regexp .MustCompile (rule .Pattern )
183+ matches := re .FindStringSubmatch (message )
184+ formatArgs := make ([]interface {}, 0 )
185+ if len (matches ) > 1 {
186+ // Use the matched capturing groups as the arguments for Sprintf.
187+ for _ , value := range matches [1 :] {
188+ formatArgs = append (formatArgs , value )
189+ }
190+ }
191+ reason = fmt .Sprintf (rule .Reason , formatArgs ... )
192+ // If fmt.Sprintf fails, it will add "%!" for each failed template in the result string.
193+ if strings .Contains (reason , "%!" ) {
194+ klog .Errorf ("Got wrong string %q for reason %q with pattern %q" , reason , rule .Reason , rule .Pattern )
195+ return nil
188196 }
189- }
190- reason = fmt .Sprintf (rule .Reason , formatArgs ... )
191- // If fmt.Sprintf fails, it will add "%!" for each failed template in the result string.
192- if strings .Contains (reason , "%!" ) {
193- klog .Errorf ("Got wrong string %q for reason %q with pattern %q" , reason , rule .Reason , rule .Pattern )
194- return nil
195197 }
196198
197199 if rule .Type == types .Temp {
0 commit comments