Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate packetbeat config options to namespace #1490

Merged
merged 1 commit into from
Apr 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha1...master[Check the HEAD d
*Packetbeat*

- Configuration of redis topology support changed. {pull}1353[1353]
- Move all Packetbeat configuration options under the packetbeat namespace {issue}1417[1417]

*Topbeat*

Expand Down
42 changes: 21 additions & 21 deletions packetbeat/beater/packetbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,50 +109,50 @@ func (pb *Packetbeat) Config(b *beat.Beat) error {
return err
}

cfg := &pb.PbConfig.Packetbeat

// CLI flags over-riding config
if *pb.CmdLineArgs.TopSpeed {
pb.PbConfig.Interfaces.TopSpeed = true
cfg.Interfaces.TopSpeed = true
}

if len(*pb.CmdLineArgs.File) > 0 {
pb.PbConfig.Interfaces.File = *pb.CmdLineArgs.File
cfg.Interfaces.File = *pb.CmdLineArgs.File
}

pb.PbConfig.Interfaces.Loop = *pb.CmdLineArgs.Loop
pb.PbConfig.Interfaces.OneAtATime = *pb.CmdLineArgs.OneAtAtime
cfg.Interfaces.Loop = *pb.CmdLineArgs.Loop
cfg.Interfaces.OneAtATime = *pb.CmdLineArgs.OneAtAtime

if len(*pb.CmdLineArgs.Dumpfile) > 0 {
pb.PbConfig.Interfaces.Dumpfile = *pb.CmdLineArgs.Dumpfile
cfg.Interfaces.Dumpfile = *pb.CmdLineArgs.Dumpfile
}

// assign global singleton as it is used in protocols
// TODO: Refactor
config.ConfigSingleton = pb.PbConfig

return nil
}

// Setup packetbeat
func (pb *Packetbeat) Setup(b *beat.Beat) error {

if err := procs.ProcWatcher.Init(pb.PbConfig.Procs); err != nil {
cfg := &pb.PbConfig.Packetbeat

if err := procs.ProcWatcher.Init(cfg.Procs); err != nil {
logp.Critical(err.Error())
return err
}

queueSize := defaultQueueSize
if pb.PbConfig.Shipper.QueueSize != nil {
queueSize = *pb.PbConfig.Shipper.QueueSize
if b.Config.Shipper.QueueSize != nil {
queueSize = *b.Config.Shipper.QueueSize
}
bulkQueueSize := defaultBulkQueueSize
if pb.PbConfig.Shipper.BulkQueueSize != nil {
bulkQueueSize = *pb.PbConfig.Shipper.BulkQueueSize
if b.Config.Shipper.BulkQueueSize != nil {
bulkQueueSize = *b.Config.Shipper.BulkQueueSize
}
pb.Pub = publish.NewPublisher(b.Publisher, queueSize, bulkQueueSize)
pb.Pub.Start()

logp.Debug("main", "Initializing protocol plugins")
err := protos.Protos.Init(false, pb.Pub, pb.PbConfig.Protocols)
err := protos.Protos.Init(false, pb.Pub, cfg.Protocols)
if err != nil {
return fmt.Errorf("Initializing protocol analyzers failed: %v", err)
}
Expand All @@ -163,15 +163,15 @@ func (pb *Packetbeat) Setup(b *beat.Beat) error {
}

// This needs to be after the sniffer Init but before the sniffer Run.
if err := droppriv.DropPrivileges(config.ConfigSingleton.RunOptions); err != nil {
if err := droppriv.DropPrivileges(cfg.RunOptions); err != nil {
return err
}

return nil
}

func (pb *Packetbeat) setupSniffer() error {
cfg := &pb.PbConfig
cfg := &pb.PbConfig.Packetbeat

withVlans := cfg.Interfaces.With_vlans
_, withICMP := cfg.Protocols["icmp"]
Expand All @@ -181,24 +181,24 @@ func (pb *Packetbeat) setupSniffer() error {
}

pb.Sniff = &sniffer.SnifferSetup{}
return pb.Sniff.Init(false, pb.makeWorkerFactory(filter))
return pb.Sniff.Init(false, pb.makeWorkerFactory(filter), &pb.PbConfig.Packetbeat.Interfaces)
}

func (pb *Packetbeat) makeWorkerFactory(filter string) sniffer.WorkerFactory {
return func(dl layers.LinkType) (sniffer.Worker, string, error) {
var f *flows.Flows
var err error

if pb.PbConfig.Flows != nil {
f, err = flows.NewFlows(pb.Pub, pb.PbConfig.Flows)
if pb.PbConfig.Packetbeat.Flows != nil {
f, err = flows.NewFlows(pb.Pub, pb.PbConfig.Packetbeat.Flows)
if err != nil {
return nil, "", err
}
}

var icmp4 icmp.ICMPv4Processor
var icmp6 icmp.ICMPv6Processor
if cfg, exists := pb.PbConfig.Protocols["icmp"]; exists {
if cfg, exists := pb.PbConfig.Packetbeat.Protocols["icmp"]; exists {
icmp, err := icmp.New(false, pb.Pub, cfg)
if err != nil {
return nil, "", err
Expand Down
11 changes: 4 additions & 7 deletions packetbeat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/droppriv"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/publisher"
"github.com/elastic/beats/packetbeat/procs"
)

type Config struct {
Packetbeat PacketbeatConfig
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively this could have been written like:

type Config struct {
  Interfaces InterfacesConfig `config:"packetbeat.interfaces"`
  Flows      *Flows           `config:"packetbeat.flows"`
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I wasn't aware that this would work.

}

type PacketbeatConfig struct {
Interfaces InterfacesConfig
Flows *Flows
Protocols map[string]*common.Config
Shipper publisher.ShipperConfig
Procs procs.ProcsConfig
RunOptions droppriv.RunOptions
Logging logp.Logging
}

type InterfacesConfig struct {
Expand Down Expand Up @@ -45,6 +45,3 @@ type ProtocolCommon struct {
SendResponse bool `config:"send_response"`
TransactionTimeout time.Duration `config:"transaction_timeout"`
}

// Config Singleton
var ConfigSingleton Config
6 changes: 3 additions & 3 deletions packetbeat/docs/gettingstarted.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ server on which Packetbeat is installed. For this, use `any` as the device:
----------------------------------------------------------------------
# Select the network interfaces to sniff the data. You can use the "any"
# keyword to sniff on all connected interfaces.
interfaces:
packetbeat.interfaces:
device: any
----------------------------------------------------------------------

Expand All @@ -131,7 +131,7 @@ Modify the `device` line to point to the index of the device:
+
[source,yml]
----------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: 0
----------------------------------------------------------------------

Expand All @@ -141,7 +141,7 @@ default values should do just fine.
+
[source,yaml]
----------------------------------------------------------------------
protocols:
packetbeat.protocols:
dns:
ports: [53]

Expand Down
26 changes: 13 additions & 13 deletions packetbeat/docs/reference/configuration/packetbeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The `interfaces` section configures the sniffer. Here is an example configuratio
------------------------------------------------------------------------------
# Select the network interfaces to sniff the data. You can use the "any"
# keyword to sniff on all connected interfaces.
interfaces:
packetbeat.interfaces:
# On which device to sniff
device: any

Expand All @@ -34,7 +34,7 @@ Example:

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: eth0
------------------------------------------------------------------------------

Expand Down Expand Up @@ -73,7 +73,7 @@ first interface in the list:

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: 0
------------------------------------------------------------------------------

Expand All @@ -90,7 +90,7 @@ Example:

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: eth0
snaplen: 1514
------------------------------------------------------------------------------
Expand All @@ -114,7 +114,7 @@ the `af_packet` sniffing type:

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: eth0
type: af_packet
------------------------------------------------------------------------------
Expand All @@ -137,7 +137,7 @@ Example:

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: eth0
type: af_packet
buffer_size_mb: 100
Expand Down Expand Up @@ -168,7 +168,7 @@ You can use the `bpf_filter` setting to overwrite the generated BPF filter. For

[source,yaml]
------------------------------------------------------------------------------
interfaces:
packetbeat.interfaces:
device: eth0
bpf_filter: "net 192.168.238.0/0 and port 80 and port 3306"
------------------------------------------------------------------------------
Expand All @@ -187,7 +187,7 @@ disabled.

[source,yaml]
------------------------------------------------------------------------------
flows:
packetbeat.flows:
timeout: 30s
period: 10s
------------------------------------------------------------------------------
Expand Down Expand Up @@ -233,7 +233,7 @@ Example configuration:

[source,yaml]
------------------------------------------------------------------------------
protocols:
packetbeat.protocols:
icmp:
enabled: true

Expand Down Expand Up @@ -314,7 +314,7 @@ The `dns` section specifies configuration options for the DNS protocol. The DNS

[source,yaml]
------------------------------------------------------------------------------
protocols:
packetbeat.protocols:
dns:
ports: [53]

Expand Down Expand Up @@ -345,7 +345,7 @@ sample configuration section:

[source,yaml]
------------------------------------------------------------------------------
protocols:
packetbeat.protocols:
http:

# Configure the ports where to listen for HTTP traffic. You can disable
Expand Down Expand Up @@ -418,7 +418,7 @@ Example configuration:

[source,yml]
------------------------------------------------------------------------------
protocols:
packetbeat.protocols:
http:
ports: [80, 8080]
send_response: true
Expand Down Expand Up @@ -709,7 +709,7 @@ Example configuration:

[source,yaml]
------------------------------------------------------------------------------
procs:
packetbeat.procs:
enabled: true
monitored:
- process: mysqld
Expand Down
8 changes: 4 additions & 4 deletions packetbeat/etc/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

# Select the network interfaces to sniff the data. You can use the "any"
# keyword to sniff on all connected interfaces.
interfaces:
packetbeat.interfaces:
device: any

flows:
packetbeat.flows:
# Set network flow timeout. Flow is killed if no packet is received before being
# timed out.
#timeout: 30s
Expand All @@ -24,7 +24,7 @@ flows:
#period: 10s

############################# Protocols #######################################
protocols:
packetbeat.protocols:
icmp:
# Enable ICMPv4 and ICMPv6 monitoring. Default: false
enabled: true
Expand Down Expand Up @@ -161,7 +161,7 @@ protocols:
# Process matching is optional and can be enabled by uncommenting the following
# lines.
#
#procs:
#packetbeat.procs:
# enabled: false
# monitored:
# - process: mysqld
Expand Down
8 changes: 4 additions & 4 deletions packetbeat/packetbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

# Select the network interfaces to sniff the data. You can use the "any"
# keyword to sniff on all connected interfaces.
interfaces:
packetbeat.interfaces:
device: any

flows:
packetbeat.flows:
# Set network flow timeout. Flow is killed if no packet is received before being
# timed out.
#timeout: 30s
Expand All @@ -24,7 +24,7 @@ flows:
#period: 10s

############################# Protocols #######################################
protocols:
packetbeat.protocols:
icmp:
# Enable ICMPv4 and ICMPv6 monitoring. Default: false
enabled: true
Expand Down Expand Up @@ -161,7 +161,7 @@ protocols:
# Process matching is optional and can be enabled by uncommenting the following
# lines.
#
#procs:
#packetbeat.procs:
# enabled: false
# monitored:
# - process: mysqld
Expand Down
4 changes: 2 additions & 2 deletions packetbeat/sniffer/sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ func (sniffer *SnifferSetup) Datalink() layers.LinkType {
return layers.LinkTypeEthernet
}

func (sniffer *SnifferSetup) Init(test_mode bool, factory WorkerFactory) error {
func (sniffer *SnifferSetup) Init(test_mode bool, factory WorkerFactory, interfaces *config.InterfacesConfig) error {
var err error

if !test_mode {
err = sniffer.setFromConfig(&config.ConfigSingleton.Interfaces)
err = sniffer.setFromConfig(interfaces)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, the ConfigSingleton was only left in one place? Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I remember last time I tried to remove all occurences it was not possible without major refactoring. It seems like the refactoring by Steffen did some magic here.

if err != nil {
return fmt.Errorf("Error creating sniffer: %v", err)
}
Expand Down
Loading