-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Spencer Krum <nibz@spencerkrum.com> Co-authored-by: Thomas Labarussias <issif+github@gadz.org>
- Loading branch information
Showing
10 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ config.yaml | |
.env | ||
.vscode | ||
.idea | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package outputs | ||
|
||
import ( | ||
"github.com/falcosecurity/falcosidekick/types" | ||
"strings" | ||
) | ||
|
||
type discordPayload struct { | ||
Content string `json:"content"` | ||
Avatar_url string `json:"avatar_url,omitempty"` | ||
Embeds []discordEmbedPayload `json:"embeds"` | ||
} | ||
|
||
type discordEmbedPayload struct { | ||
Title string `json:"title"` | ||
Url string `json:"url"` | ||
Description string `json:"description"` | ||
Color string `json:"color"` | ||
Fields []discordEmbedFieldPayload `json:"fields"` | ||
} | ||
|
||
type discordEmbedFieldPayload struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
Inline bool `json:"inline"` | ||
} | ||
|
||
func newDiscordPayload(falcopayload types.FalcoPayload, config *types.Configuration) discordPayload { | ||
var iconURL string | ||
if config.Discord.Icon != "" { | ||
iconURL = config.Discord.Icon | ||
} else { | ||
iconURL = "https://raw.githubusercontent.com/falcosecurity/falcosidekick/master/imgs/falcosidekick.png" | ||
} | ||
|
||
var color string | ||
switch strings.ToLower(falcopayload.Priority) { | ||
case "emergency": | ||
color = "15158332" // red | ||
case "alert": | ||
color = "11027200" // dark orange | ||
case "critical": | ||
color = "15105570" // orange | ||
case "error": | ||
color = "15844367" // gold | ||
case "warning": | ||
color = "12745742" // dark gold | ||
case "notice": | ||
color = "3066993" // teal | ||
case "informational": | ||
color = "3447003" // blue | ||
case "debug": | ||
color = "12370112" // light grey | ||
} | ||
|
||
embeds := make([]discordEmbedPayload, 0) | ||
|
||
embedFields := make([]discordEmbedFieldPayload, 0) | ||
var embedField discordEmbedFieldPayload | ||
|
||
for i, j := range falcopayload.OutputFields { | ||
switch j.(type) { | ||
case string: | ||
embedField.Name = i | ||
embedField.Inline = true | ||
embedField.Value = "```" + j.(string) + "```" | ||
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) | ||
|
||
embed := discordEmbedPayload{ | ||
Title: "", | ||
Description: falcopayload.Output, | ||
Color: color, | ||
Fields: embedFields, | ||
} | ||
embeds = append(embeds, embed) | ||
|
||
ds := discordPayload{ | ||
Content: "", | ||
Avatar_url: iconURL, | ||
Embeds: embeds, | ||
} | ||
return ds | ||
} | ||
|
||
// DiscordPost posts events to discord | ||
func (c *Client) DiscordPost(falcopayload types.FalcoPayload) { | ||
err := c.Post(newDiscordPayload(falcopayload, c.Config)) | ||
if err != nil { | ||
c.Stats.Discord.Add("error", 1) | ||
} else { | ||
c.Stats.Discord.Add("ok", 1) | ||
} | ||
c.Stats.Discord.Add("total", 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters