Skip to content
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
25 changes: 6 additions & 19 deletions dev-tools/packaging/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,12 @@ const (
radiotapLicense = `Dependency : ieee80211_radiotap.h Header File`
)

var (
// These reflect the order that the licenses and notices appear in the relevant files.
npcapConfigPattern = regexp.MustCompile(
"(?s)" + npcapSettings +
".*" + npcapGrant,
)
npcapLicensePattern = regexp.MustCompile(
"(?s)" + npcapLicense +
".*" + libpcapLicense +
".*" + winpcapLicense +
".*" + radiotapLicense,
)
// This reflects the order that the licenses and notices appear in the relevant files.
var npcapLicensePattern = regexp.MustCompile(
"(?s)" + npcapLicense +
".*" + libpcapLicense +
".*" + winpcapLicense +
".*" + radiotapLicense,
)

func checkNpcapNotices(pkg, file string, contents io.Reader) error {
Expand All @@ -222,13 +216,6 @@ func checkNpcapNotices(pkg, file string, contents io.Reader) error {
return err
}
switch file {
case "packetbeat.yml", "packetbeat.reference.yml":
if npcapConfigPattern.MatchReader(bufio.NewReader(contents)) != wantNotices {
if wantNotices {
return fmt.Errorf("Npcap config section not found in config file %s in %s", file, pkg)
}
return fmt.Errorf("unexpected Npcap config section found in config file %s in %s", file, pkg)
}
case "NOTICE.txt":
if npcapLicensePattern.MatchReader(bufio.NewReader(contents)) != wantNotices {
if wantNotices {
Expand Down
2 changes: 0 additions & 2 deletions packetbeat/_meta/config/beat.reference.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ packetbeat.interfaces.internal_networks:
# can stay enabled even after beat is shut down.
#packetbeat.interfaces.auto_promisc_mode: true

{{- template "windows_npcap.yml.tmpl" .}}

{{header "Flows"}}

packetbeat.flows:
Expand Down
2 changes: 0 additions & 2 deletions packetbeat/_meta/config/beat.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ packetbeat.interfaces.device: {{ call .device .GOOS }}
packetbeat.interfaces.internal_networks:
- private

{{- template "windows_npcap.yml.tmpl" .}}

{{header "Flows"}}

# Set `enabled: false` or comment out all options to disable flows reporting.
Expand Down
36 changes: 0 additions & 36 deletions packetbeat/_meta/config/windows_npcap.yml.tmpl

This file was deleted.

29 changes: 3 additions & 26 deletions packetbeat/beater/install_npcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ import (
"github.com/elastic/beats/v7/packetbeat/npcap"
)

type npcapConfig struct {
NeverInstall bool `config:"npcap.never_install"`
ForceReinstall bool `config:"npcap.force_reinstall"`
InstallTimeout time.Duration `config:"npcap.install_timeout"`
InstallDestination string `config:"npcal.install_destination"`
}

func (c *npcapConfig) Init() {
// Set defaults.
c.InstallTimeout = 120 * time.Second
}
const installTimeout = 120 * time.Second

func installNpcap(b *beat.Beat) error {
if !b.Info.ElasticLicensed {
Expand All @@ -62,27 +52,14 @@ func installNpcap(b *beat.Beat) error {
}
}()

var cfg npcapConfig
err := b.BeatConfig.Unpack(&cfg)
if err != nil {
return fmt.Errorf("failed to unpack npcap config: %w", err)
}
if cfg.NeverInstall {
return nil
}

ctx, cancel := context.WithTimeout(context.Background(), cfg.InstallTimeout)
ctx, cancel := context.WithTimeout(context.Background(), installTimeout)
defer cancel()

log := logp.NewLogger("npcap_install")

if npcap.Installer == nil {
return nil
}
if !cfg.ForceReinstall && !npcap.Upgradeable() {
npcap.Installer = nil
return nil
}
tmp, err := os.MkdirTemp("", "")
if err != nil {
return fmt.Errorf("could not create installation temporary directory: %w", err)
Expand All @@ -100,5 +77,5 @@ func installNpcap(b *beat.Beat) error {
if err != nil {
return fmt.Errorf("could not create installation temporary file: %w", err)
}
return npcap.Install(ctx, log, installerPath, cfg.InstallDestination, false)
return npcap.Install(ctx, log, installerPath, "", false)
}