99 "github.com/spf13/pflag"
1010 "net/url"
1111 "os"
12+ "strings"
1213)
1314
1415type Config struct {
@@ -111,8 +112,10 @@ func (c *Config) Run() (rc int, output string, err error) {
111112 byLocation [index ] = append (byLocation [index ], threat )
112113 }
113114
115+ var sb strings.Builder
116+
114117 for index , list := range byLocation {
115- output += fmt .Sprintf ("\n ## %s\n \n " , index )
118+ sb . WriteString ( fmt .Sprintf ("\n ## %s\n \n " , index ) )
116119
117120 for _ , threat := range list {
118121 var stateText string
@@ -127,29 +130,31 @@ func (c *Config) Run() (rc int, output string, err error) {
127130 stateText = "WARNING"
128131 }
129132
130- output += fmt .Sprintf ("[%s] [%s] %s: (%s) %s (%s)\n " ,
133+ sb . WriteString ( fmt .Sprintf ("[%s] [%s] %s: (%s) %s (%s)\n " ,
131134 threat .ThreatInfo .CreatedAt .Local ().Format ("2006-01-02 15:04 MST" ),
132135 stateText ,
133136 threat .AgentRealtimeInfo .AgentComputerName ,
134137 threat .ThreatInfo .Classification ,
135138 threat .ThreatInfo .ThreatName ,
136139 threat .ThreatInfo .MitigationStatusDescription ,
137- )
140+ ))
138141 }
139142 }
140143
141144 // Add summary on top
142- output = fmt .Sprintf ("%d threats found, %d not mitigated\n " , total , notMitigated ) + output
145+ sb .WriteString (fmt .Sprintf ("%d threats found, %d not mitigated\n " , total , notMitigated ) + sb .String ())
146+
143147 if c .SiteName != "" && c .ComputerName == "" {
144- output = fmt .Sprintf ("site %s - " , c .SiteName ) + output
148+ sb . WriteString ( fmt .Sprintf ("site %s - " , c .SiteName ) + sb . String ())
145149 } else if c .ComputerName != "" {
146- output = fmt .Sprintf ("Computer %s - " , c .ComputerName ) + output
150+ sb . WriteString ( fmt .Sprintf ("Computer %s - " , c .ComputerName ) + sb . String ())
147151 }
148152
149153 // Add perfdata
150- output += "|"
151- output += fmt .Sprintf (" threats=%d" , total )
152- output += fmt .Sprintf (" threats_not_mitigated=%d" , notMitigated )
154+ sb .WriteString ("|" )
155+ sb .WriteString (fmt .Sprintf (" threats=%d" , total ))
156+ sb .WriteString (fmt .Sprintf (" threats_not_mitigated=%d" , notMitigated ))
157+ output = sb .String ()
153158
154159 // determine final state
155160 if notMitigated > 0 {
0 commit comments