diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 818064c619f0..683061171a3a 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -111,6 +111,7 @@ https://github.com/elastic/beats/compare/v5.4.0...v6.0.0-alpha1[View commits] *Packetbeat* - Remove deprecated geoip. {pull}3766[3766] +- Replace `waitstop` command line argument by `shutdown_timeout` in configuration file. {pull}3588[3588] *Winlogbeat* diff --git a/packetbeat/beater/packetbeat.go b/packetbeat/beater/packetbeat.go index 67949c088227..90616bf4a1f4 100644 --- a/packetbeat/beater/packetbeat.go +++ b/packetbeat/beater/packetbeat.go @@ -40,24 +40,22 @@ type packetbeat struct { } type flags struct { - file *string - loop *int - oneAtAtime *bool - topSpeed *bool - dumpfile *string - waitShutdown *int + file *string + loop *int + oneAtAtime *bool + topSpeed *bool + dumpfile *string } var cmdLineArgs flags func init() { cmdLineArgs = flags{ - file: flag.String("I", "", "Read packet data from specified file"), - loop: flag.Int("l", 1, "Loop file. 0 - loop forever"), - oneAtAtime: flag.Bool("O", false, "Read packets one at a time (press Enter)"), - topSpeed: flag.Bool("t", false, "Read packets as fast as possible, without sleeping"), - dumpfile: flag.String("dump", "", "Write all captured packets to this libpcap file"), - waitShutdown: flag.Int("waitstop", 0, "Additional seconds to wait before shutting down"), + file: flag.String("I", "", "Read packet data from specified file"), + loop: flag.Int("l", 1, "Loop file. 0 - loop forever"), + oneAtAtime: flag.Bool("O", false, "Read packets one at a time (press Enter)"), + topSpeed: flag.Bool("t", false, "Read packets as fast as possible, without sleeping"), + dumpfile: flag.String("dump", "", "Write all captured packets to this libpcap file"), } } @@ -172,9 +170,9 @@ func (pb *packetbeat) Run(b *beat.Beat) error { service.Stop() } - waitShutdown := pb.cmdLineArgs.waitShutdown - if waitShutdown != nil && *waitShutdown > 0 { - time.Sleep(time.Duration(*waitShutdown) * time.Second) + timeout := pb.config.ShutdownTimeout + if timeout > 0 { + time.Sleep(timeout) } return nil diff --git a/packetbeat/config/config.go b/packetbeat/config/config.go index cbcf98345159..afbf37d3a282 100644 --- a/packetbeat/config/config.go +++ b/packetbeat/config/config.go @@ -9,13 +9,14 @@ import ( ) type Config struct { - Interfaces InterfacesConfig `config:"interfaces"` - Flows *Flows `config:"flows"` - Protocols map[string]*common.Config `config:"protocols"` - ProtocolsList []*common.Config `config:"protocols"` - Procs procs.ProcsConfig `config:"procs"` - IgnoreOutgoing bool `config:"ignore_outgoing"` - RunOptions droppriv.RunOptions + Interfaces InterfacesConfig `config:"interfaces"` + Flows *Flows `config:"flows"` + Protocols map[string]*common.Config `config:"protocols"` + ProtocolsList []*common.Config `config:"protocols"` + Procs procs.ProcsConfig `config:"procs"` + IgnoreOutgoing bool `config:"ignore_outgoing"` + ShutdownTimeout time.Duration `config:"shutdown_timeout"` + RunOptions droppriv.RunOptions } type InterfacesConfig struct { diff --git a/packetbeat/docs/command-line.asciidoc b/packetbeat/docs/command-line.asciidoc index e9738a2948c6..40b9ed3e555b 100644 --- a/packetbeat/docs/command-line.asciidoc +++ b/packetbeat/docs/command-line.asciidoc @@ -2,7 +2,7 @@ === Command Line Options The following command line options are available for Packetbeat. To use these options, -you need to start Packetbeat in the foreground. +you need to start Packetbeat in the foreground. TIP: Run `./packetbeat -h` to see the full list of options from the command line. @@ -29,9 +29,6 @@ For an infinite loop, use _0_. The `-l` option is useful only for testing Packet *`-t`*:: Read the packets from the pcap file as fast as possible without sleeping. Use this option in combination with the `-I` option. The `-t` option is useful only for testing Packetbeat. -*`-waitstop `*:: -Wait an additional `n` seconds before exiting. - ==== Other Options These command line options from libbeat are also available for Packetbeat: diff --git a/packetbeat/docs/reference/configuration/packetbeat-options.asciidoc b/packetbeat/docs/reference/configuration/packetbeat-options.asciidoc index 5876899c2e2d..ed3811d20be9 100644 --- a/packetbeat/docs/reference/configuration/packetbeat-options.asciidoc +++ b/packetbeat/docs/reference/configuration/packetbeat-options.asciidoc @@ -832,6 +832,23 @@ periodically afterwards, it scans the process table for processes that match the values specified for this option. The match is done against the process' command line as read from `/proc//cmdline`. + +[[shutdown-timeout]] +===== shutdown_timeout + +How long Packetbeat waits on shutdown. By default, this option is disabled. Packetbeat +will wait for `shutdown_timeout` and then close. It will not track if all events were sent +previously. + +Example configuration: + +[source,yaml] +------------------------------------------------------------------------------------- +packetbeat.shutdown_timeout: 5s +------------------------------------------------------------------------------------- + + + include::../../../../libbeat/docs/generalconfig.asciidoc[] include::../../../../libbeat/docs/processors-config.asciidoc[] diff --git a/packetbeat/tests/system/config/packetbeat.yml.j2 b/packetbeat/tests/system/config/packetbeat.yml.j2 index 06299ada154b..527d00e32f76 100644 --- a/packetbeat/tests/system/config/packetbeat.yml.j2 +++ b/packetbeat/tests/system/config/packetbeat.yml.j2 @@ -168,6 +168,8 @@ tags: [ {%- endif -%} ] +packetbeat.shutdown_timeout: {{ shutdown_timeout|default(0) }} + {%- if processors %} #================================ Filters ===================================== diff --git a/packetbeat/tests/system/packetbeat.py b/packetbeat/tests/system/packetbeat.py index 02a3a8430068..7202ee48ab68 100644 --- a/packetbeat/tests/system/packetbeat.py +++ b/packetbeat/tests/system/packetbeat.py @@ -29,8 +29,7 @@ def run_packetbeat(self, pcap, output="packetbeat.log", extra_args=[], debug_selectors=[], - exit_code=0, - wait_stop=0): + exit_code=0): """ Executes packetbeat on an input pcap file. Waits for the process to finish before returning to @@ -49,7 +48,6 @@ def run_packetbeat(self, pcap, "-t", "-systemTest", "-test.coverprofile", os.path.join(self.working_dir, "coverage.cov"), - "-waitstop", str(wait_stop), ]) if extra_args: diff --git a/packetbeat/tests/system/test_0041_memcache_udp_bin_basic.py b/packetbeat/tests/system/test_0041_memcache_udp_bin_basic.py index 4a23cf84b731..95e6e36601e4 100644 --- a/packetbeat/tests/system/test_0041_memcache_udp_bin_basic.py +++ b/packetbeat/tests/system/test_0041_memcache_udp_bin_basic.py @@ -17,7 +17,6 @@ def _run(self, pcap): memcache_udp_transaction_timeout=10 ) self.run_packetbeat(pcap=pcap, - extra_args=['-waitstop', '1'], debug_selectors=["memcache", "udp", "publish"]) objs = self.read_output() self.assert_common(objs) diff --git a/packetbeat/tests/system/test_0041_memcache_udp_text_basic.py b/packetbeat/tests/system/test_0041_memcache_udp_text_basic.py index 30ff2e3558dd..67bab8b65c64 100644 --- a/packetbeat/tests/system/test_0041_memcache_udp_text_basic.py +++ b/packetbeat/tests/system/test_0041_memcache_udp_text_basic.py @@ -17,7 +17,6 @@ def _run(self, pcap): memcache_udp_transaction_timeout=10 ) self.run_packetbeat(pcap=pcap, - extra_args=['-waitstop', '1'], debug_selectors=["memcache", "udp", "publish"]) objs = self.read_output() self.assert_common(objs) diff --git a/packetbeat/tests/system/test_0060_flows.py b/packetbeat/tests/system/test_0060_flows.py index 4b5911b081e7..c61e91cda255 100644 --- a/packetbeat/tests/system/test_0060_flows.py +++ b/packetbeat/tests/system/test_0060_flows.py @@ -16,10 +16,10 @@ class Test(BaseTest): def test_mysql_flow(self): self.render_config_template( flows=True, + shutdown_timeout="1s", ) self.run_packetbeat( pcap="mysql_long.pcap", - wait_stop=1, debug_selectors=["*"]) objs = self.read_output( @@ -46,10 +46,10 @@ def test_mysql_flow(self): def test_memcache_udp_flow(self): self.render_config_template( flows=True, + shutdown_timeout="1s", ) self.run_packetbeat( pcap="memcache/memcache_bin_udp_counter_ops.pcap", - wait_stop=1, debug_selectors=["*"]) objs = self.read_output( @@ -74,10 +74,10 @@ def test_memcache_udp_flow(self): def test_icmp4_ping(self): self.render_config_template( flows=True, + shutdown_timeout="1s", ) self.run_packetbeat( pcap="icmp/icmp4_ping_over_vlan.pcap", - wait_stop=1, debug_selectors=["*"]) objs = self.read_output( @@ -103,10 +103,10 @@ def test_icmp4_ping(self): def test_icmp6_ping(self): self.render_config_template( flows=True, + shutdown_timeout="1s", ) self.run_packetbeat( pcap="icmp/icmp6_ping_over_vlan.pcap", - wait_stop=1, debug_selectors=["*"]) objs = self.read_output(