Skip to content

Commit

Permalink
Adapt packetbeat structure to newest libbeat structure
Browse files Browse the repository at this point in the history
Update to most recent libbeat version
  • Loading branch information
ruflin committed Nov 25, 2015
1 parent 32b65ed commit cde2ddb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 71 deletions.
45 changes: 15 additions & 30 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Godeps/_workspace/src/github.com/elastic/libbeat/beat/beat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions packetbeat.go → beat/packetbeat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package beat

import (
"flag"
Expand Down Expand Up @@ -31,10 +31,6 @@ import (
"github.com/elastic/packetbeat/sniffer"
)

// You can overwrite these, e.g.: go build -ldflags "-X main.Version 1.0.0-beta3"
var Version = "1.0.0"
var Name = "packetbeat"

var EnabledProtocolPlugins map[protos.Protocol]protos.ProtocolPlugin = map[protos.Protocol]protos.ProtocolPlugin{
protos.HttpProtocol: new(http.Http),
protos.MemcacheProtocol: new(memcache.Memcache),
Expand Down Expand Up @@ -82,13 +78,16 @@ func init() {
}
}

func fetchAdditionalCmdLineArgs() CmdLineArgs {
func New() *Packetbeat {

pb := &Packetbeat{}
pb.CmdLineArgs = cmdLineArgs

return cmdLineArgs
return pb
}

// Handle custom command line flags
func (pb *Packetbeat) CliFlags(b *beat.Beat) {
func (pb *Packetbeat) HandleFlags(b *beat.Beat) {
// -devices CLI flag
if *pb.CmdLineArgs.PrintDevices {
devs, err := sniffer.ListDeviceNames(true)
Expand Down
37 changes: 6 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
package main

import (
"os"
packetbeat "github.com/elastic/packetbeat/beat"

"github.com/elastic/libbeat/beat"
"github.com/elastic/libbeat/logp"
)

// You can overwrite these, e.g.: go build -ldflags "-X main.Version 1.0.0-beta3"
var Version = "1.0.0"
var Name = "packetbeat"

// Setups and Runs Packetbeat
func main() {

// Create Beater object
pb := &Packetbeat{}

// Initi beat objectefile
b := beat.NewBeat(Name, Version, pb)

// Additional command line args are used to overwrite config options
pb.CmdLineArgs = fetchAdditionalCmdLineArgs()

// Base CLI flags
b.CommandLineSetup()

// Beat CLI flags
pb.CliFlags(b)

// Loads base config
b.LoadConfig()

// Configures beat
err := pb.Config(b)
if err != nil {
logp.Critical("Config error: %v", err)
os.Exit(1)
}

// Run beat. This calls first beater.Setup,
// then beater.Run and beater.Cleanup in the end
b.Run()
beat.Run(Name, Version, packetbeat.New())
}

0 comments on commit cde2ddb

Please sign in to comment.