-
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: pandyamarut <[email protected]> extra space remove Signed-off-by: pandyamarut <[email protected]> fixes lint issues Signed-off-by: pandyamarut <[email protected]> fix output file lint issue Signed-off-by: pandyamarut <[email protected]> add another storage type and fix err tests Signed-off-by: pandyamarut <[email protected]> rebase with master Signed-off-by: Marut Pandya <[email protected]> adds configurable key value Signed-off-by: pandyamarut <[email protected]> edit config_example.yaml Signed-off-by: pandyamarut <[email protected]> Add redis output Signed-off-by: pandyamarut <[email protected]> add another storage type and fix err tests Signed-off-by: pandyamarut <[email protected]> adds configurable key value Signed-off-by: pandyamarut <[email protected]> edit config_example.yaml Signed-off-by: pandyamarut <[email protected]>
- Loading branch information
1 parent
20e41e7
commit 3427272
Showing
11 changed files
with
146 additions
and
3 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package outputs | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"log" | ||
"strings" | ||
|
||
"github.com/DataDog/datadog-go/statsd" | ||
"github.com/falcosecurity/falcosidekick/types" | ||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
func (c *Client) ReportError(err error) { | ||
go c.CountMetric(Outputs, 1, []string{"output:redis", "status:error"}) | ||
c.Stats.Redis.Add(Error, 1) | ||
c.PromStats.Outputs.With(map[string]string{"destination": "redis", "status": Error}).Inc() | ||
log.Printf("[ERROR] : Redis - %v\n", err) | ||
return | ||
} | ||
|
||
func NewRedisClient(config *types.Configuration, stats *types.Statistics, promStats *types.PromStatistics, | ||
statsdClient, dogstatsdClient *statsd.Client) (*Client, error) { | ||
|
||
rClient := redis.NewClient(&redis.Options{ | ||
Addr: config.Redis.Address, | ||
Password: config.Redis.Password, | ||
DB: config.Redis.Database, | ||
}) | ||
// Ping the Redis server to check if it's running | ||
pong, err := rClient.Ping(context.Background()).Result() | ||
if err != nil { | ||
log.Printf("[ERROR] : Redis - Misconfiguration, cannot connect to the server %v\n", err) | ||
} | ||
log.Printf("[INFO] : Redis - Connected to redis server: %v\n", pong) | ||
|
||
return &Client{ | ||
OutputType: "Redis", | ||
Config: config, | ||
RedisClient: rClient, | ||
Stats: stats, | ||
PromStats: promStats, | ||
StatsdClient: statsdClient, | ||
DogstatsdClient: dogstatsdClient, | ||
}, nil | ||
} | ||
|
||
func (c *Client) RedisPost(falcopayload types.FalcoPayload) { | ||
c.Stats.Redis.Add(Total, 1) | ||
redisPayload, _ := json.Marshal(falcopayload) | ||
if strings.ToLower(c.Config.Redis.StorageType) == "hashmap" { | ||
_, err := c.RedisClient.HSet(context.Background(), c.Config.Redis.Key, falcopayload.UUID, redisPayload).Result() | ||
if err != nil { | ||
c.ReportError(err) | ||
} | ||
} else { | ||
_, err := c.RedisClient.RPush(context.Background(), c.Config.Redis.Key, redisPayload).Result() | ||
if err != nil { | ||
c.ReportError(err) | ||
} | ||
} | ||
|
||
// Setting the success status | ||
go c.CountMetric(Outputs, 1, []string{"output:redis", "status:ok"}) | ||
c.Stats.Redis.Add(OK, 1) | ||
c.PromStats.Outputs.With(map[string]string{"destination": "redis", "status": OK}).Inc() | ||
} |
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