feat(slack): enable -format-one-line-text with -to-slack (#792)

This commit is contained in:
Kota Kanbe
2019-03-18 13:56:49 +09:00
committed by GitHub
parent 1723c3f6a0
commit d630680a51
2 changed files with 20 additions and 14 deletions

View File

@@ -59,19 +59,6 @@ func (w SlackWriter) Write(rs ...models.ScanResult) (err error) {
channel = fmt.Sprintf("#%s", r.ServerName)
}
if 0 < len(r.Errors) {
msg := message{
Text: msgText(r),
Username: conf.AuthUser,
IconEmoji: conf.IconEmoji,
Channel: channel,
}
if err = send(msg); err != nil {
return err
}
continue
}
// A maximum of 100 attachments are allowed on a message.
// Split into chunks with 100 elements
// https://api.slack.com/methods/chat.postMessage
@@ -95,6 +82,13 @@ func (w SlackWriter) Write(rs ...models.ScanResult) (err error) {
IconEmoji: conf.IconEmoji,
}
if config.Conf.FormatOneLineText {
if _, _, err = api.PostMessage(channel, formatOneLineSummary(r), ParentMsg); err != nil {
return err
}
continue
}
var ts string
if _, ts, err = api.PostMessage(channel, msgText(r), ParentMsg); err != nil {
return err
@@ -113,6 +107,19 @@ func (w SlackWriter) Write(rs ...models.ScanResult) (err error) {
}
}
} else {
if config.Conf.FormatOneLineText {
msg := message{
Text: formatOneLineSummary(r),
Username: conf.AuthUser,
IconEmoji: conf.IconEmoji,
Channel: channel,
}
if err := send(msg); err != nil {
return err
}
continue
}
for i, k := range chunkKeys {
txt := ""
if i == 0 {

View File

@@ -304,7 +304,6 @@ func detectContainerOSes(timeoutSec int) (actives, inactives []osTypeInterface)
})
inactives = append(inactives)
util.Log.Errorf("Timed out: %s", servername)
}
}
}