Skip to content

Commit

Permalink
feat(slack): enable -format-one-line-text with -to-slack (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotakanbe committed Mar 18, 2019
1 parent 1723c3f commit d630680
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
33 changes: 20 additions & 13 deletions report/slack.go
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion scan/serverapi.go
Expand Up @@ -304,7 +304,6 @@ func detectContainerOSes(timeoutSec int) (actives, inactives []osTypeInterface)
})
inactives = append(inactives)
util.Log.Errorf("Timed out: %s", servername)

}
}
}
Expand Down

0 comments on commit d630680

Please sign in to comment.