Skip to content

Commit

Permalink
Rework directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mjwolf committed Jan 17, 2024
1 parent c688f5a commit f35b4c7
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (

"github.com/elastic/elastic-agent-libs/mapstr"

"github.com/elastic/elastic-agent-libs/monitoring"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/provider"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/provider/ebpf_provider"

Expand All @@ -31,11 +29,8 @@ const (
logName = "processor." + processorName
)

var reg *monitoring.Registry

func init() {
processors.RegisterPlugin(processorName, New)
reg = monitoring.Default.NewRegistry(logName, monitoring.DoNotReport)
}

type addSessionMetadata struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"
"github.com/stretchr/testify/assert"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package processdb
import (
"strings"

"slices"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"
// "github.com/elastic/elastic-agent-libs/logp"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"sync"
"time"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/timeutils"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/timeutils"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"
"github.com/elastic/elastic-agent-libs/logp"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package processdb
import (
"testing"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/procfs"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/procfs"
"github.com/stretchr/testify/assert"

"github.com/elastic/elastic-agent-libs/logp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strconv"
"strings"

p "github.com/prometheus/procfs"
"github.com/prometheus/procfs"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/timeutils"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/timeutils"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"
"github.com/elastic/elastic-agent-libs/logp"

Expand Down Expand Up @@ -42,7 +42,7 @@ func NewProcfsReader(logger logp.Logger) ProcfsReader {
}
}

type Stat p.ProcStat
type Stat procfs.ProcStat

type ProcessInfo struct {
Pids types.PidInfo
Expand All @@ -55,7 +55,7 @@ type ProcessInfo struct {
CGroupPath string
}

func credsFromProc(proc p.Proc) (types.CredInfo, error) {
func credsFromProc(proc procfs.Proc) (types.CredInfo, error) {
status, err := proc.NewStatus()
if err != nil {
return types.CredInfo{}, err
Expand Down Expand Up @@ -118,7 +118,7 @@ func credsFromProc(proc p.Proc) (types.CredInfo, error) {
}, nil
}

func (r ProcfsReader) getProcessInfo(proc p.Proc) (ProcessInfo, error) {
func (r ProcfsReader) getProcessInfo(proc procfs.Proc) (ProcessInfo, error) {
pid := uint32(proc.PID)
// All other info can be best effort, but failing to get pid info and
// start time is needed to register the process in the database
Expand Down Expand Up @@ -200,15 +200,15 @@ func (r ProcfsReader) getProcessInfo(proc p.Proc) (ProcessInfo, error) {
}

func (r ProcfsReader) GetProcess(pid uint32) (ProcessInfo, error) {
proc, err := p.NewProc(int(pid))
proc, err := procfs.NewProc(int(pid))
if err != nil {
return ProcessInfo{}, err
}
return r.getProcessInfo(proc)
}
// returns empty slice on error
func (r ProcfsReader) GetAllProcesses() ([]ProcessInfo, error) {
procs, err := p.AllProcs()
procs, err := procfs.AllProcs()
if err != nil {
return nil, err
}
Expand All @@ -226,7 +226,7 @@ func (r ProcfsReader) GetAllProcesses() ([]ProcessInfo, error) {
}

func (r ProcfsReader) getEnviron(pid uint32) (map[string]string, error) {
proc, err := p.NewProc(int(pid))
proc, err := procfs.NewProc(int(pid))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/elastic/beats/v7/libbeat/beat"

"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/pkg/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/processdb"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/provider"
"github.com/elastic/beats/v7/x-pack/auditbeat/processors/add_session_metadata/types"

Expand Down

0 comments on commit f35b4c7

Please sign in to comment.