Skip to content

Commit

Permalink
First pass at auditbeat support (#33026)
Browse files Browse the repository at this point in the history
* first attempt at auditbeat support

* add license header

* cleanup

* move files around
  • Loading branch information
fearful-symmetry authored Oct 4, 2022
1 parent 6d52bd3 commit 6eecb84
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions x-pack/auditbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
package cmd

import (
"fmt"
"strings"

auditbeatcmd "github.com/elastic/beats/v7/auditbeat/cmd"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/common/reload"
"github.com/elastic/beats/v7/x-pack/libbeat/management"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"

// Register Auditbeat x-pack modules.
_ "github.com/elastic/beats/v7/x-pack/auditbeat/include"
Expand All @@ -19,7 +26,33 @@ var Name = auditbeatcmd.Name
// RootCmd to handle beats CLI.
var RootCmd *cmd.BeatsRootCmd

// auditbeatCfg is a callback registered with central management to perform any needed config transformations
// before agent configs are sent to a beat
func auditbeatCfg(rawIn *proto.UnitExpectedConfig, agentInfo *client.AgentInfo) ([]*reload.ConfigWithMeta, error) {
modules, err := management.CreateInputsFromStreams(rawIn, "metrics", agentInfo)
if err != nil {
return nil, fmt.Errorf("error creating input list from raw expected config: %w", err)
}

// Extract the type field that has "audit/auditd", treat this
// as the module config key
module := strings.Split(rawIn.Type, "/")[1]

for iter := range modules {
modules[iter]["module"] = module
}

// Format for the reloadable list needed bythe cm.Reload() method.
configList, err := management.CreateReloadConfigFromInputs(modules)
if err != nil {
return nil, fmt.Errorf("error creating reloader config: %w", err)
}

return configList, nil
}

func init() {
management.ConfigTransform.SetTransform(auditbeatCfg)
settings := auditbeatcmd.AuditbeatSettings()
settings.ElasticLicensed = true
RootCmd = auditbeatcmd.Initialize(settings)
Expand Down

0 comments on commit 6eecb84

Please sign in to comment.