From f0137a3695469ebc6f7087bd2b399da63acff0a8 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Fri, 9 Mar 2018 10:26:41 +0900 Subject: [PATCH] feat: Display pkg information to slack notification #611 (#612) --- report/slack.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/report/slack.go b/report/slack.go index 89a9d164..4b94cbed 100644 --- a/report/slack.go +++ b/report/slack.go @@ -61,12 +61,8 @@ func (w SlackWriter) Write(rs ...models.ScanResult) (err error) { } if 0 < len(r.Errors) { - serverInfo := fmt.Sprintf("*%s*", r.ServerInfo()) - notifyUsers := getNotifyUsers(config.Conf.Slack.NotifyUsers) - txt := fmt.Sprintf("%s\n%s\nError: %s", - notifyUsers, serverInfo, r.Errors) msg := message{ - Text: txt, + Text: msgText(r), Username: conf.AuthUser, IconEmoji: conf.IconEmoji, Channel: channel, @@ -179,10 +175,20 @@ func msgText(r models.ScanResult) string { notifyUsers = getNotifyUsers(config.Conf.Slack.NotifyUsers) } serverInfo := fmt.Sprintf("*%s*", r.ServerInfo()) - return fmt.Sprintf("%s\n%s\n>%s", + + if 0 < len(r.Errors) { + return fmt.Sprintf("%s\n%s\n%s\n%s\nError: %s", + notifyUsers, + serverInfo, + r.ScannedCves.FormatCveSummary(), + r.Packages.FormatUpdatablePacksSummary(), + r.Errors) + } + return fmt.Sprintf("%s\n%s\n%s\n%s", notifyUsers, serverInfo, - r.ScannedCves.FormatCveSummary()) + r.ScannedCves.FormatCveSummary(), + r.Packages.FormatUpdatablePacksSummary()) } func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) {