Skip to content

Commit

Permalink
Refactor discord
Browse files Browse the repository at this point in the history
Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com>
  • Loading branch information
KeisukeYamashita authored and poiana committed Nov 20, 2020
1 parent 6e28253 commit d69b3df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
22 changes: 7 additions & 15 deletions outputs/discord.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package outputs

import (
"fmt"
"strings"

"github.com/falcosecurity/falcosidekick/types"
Expand Down Expand Up @@ -62,26 +63,17 @@ func newDiscordPayload(falcopayload types.FalcoPayload, config *types.Configurat
for i, j := range falcopayload.OutputFields {
switch v := j.(type) {
case string:
embedField.Name = i
embedField.Inline = true
embedField.Value = "```" + v + "```"
embedField = discordEmbedFieldPayload{i, fmt.Sprintf("```%s```", v), true}
default:
continue
}

embedFields = append(embedFields, embedField)
}
embedField.Name = Rule
embedField.Value = falcopayload.Rule
embedField.Inline = true
embedFields = append(embedFields, embedField)
embedField.Name = Priority
embedField.Value = falcopayload.Priority
embedField.Inline = true
embedFields = append(embedFields, embedField)
embedField.Name = Time
embedField.Value = falcopayload.Time.String()
embedField.Inline = true
embedFields = append(embedFields, embedField)

embedFields = append(embedFields, discordEmbedFieldPayload{Rule, falcopayload.Rule, true})
embedFields = append(embedFields, discordEmbedFieldPayload{Priority, falcopayload.Priority, true})
embedFields = append(embedFields, discordEmbedFieldPayload{Time, falcopayload.Time.String(), true})

embed := discordEmbedPayload{
Title: "",
Expand Down
3 changes: 2 additions & 1 deletion outputs/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package outputs

import (
"encoding/json"
"fmt"
"testing"

"github.com/falcosecurity/falcosidekick/types"
Expand All @@ -20,7 +21,7 @@ func TestNewDiscordPayload(t *testing.T) {
Fields: []discordEmbedFieldPayload{
{
Name: "proc.name",
Value: "```falcosidekick```",
Value: fmt.Sprintf("```%s```", "falcosidekick"),
Inline: true,
},
{
Expand Down

0 comments on commit d69b3df

Please sign in to comment.