Skip to content

Commit

Permalink
Add short name in agent report (#1649)
Browse files Browse the repository at this point in the history
* Short process name

* Update dependencies
  • Loading branch information
ramanan-ravi authored Oct 9, 2023
1 parent 1c045cc commit 2a214be
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/YaraHunter
2 changes: 1 addition & 1 deletion deepfence_agent/tools/apache/scope/probe/cri/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewReporter(cri client.RuntimeServiceClient, hostID string, criImageClient
}

// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "CRI" }
func (*Reporter) Name() string { return "CRI" }

// Report generates a Report containing Container topologies
func (r *Reporter) Report() (report.Report, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewReporter(registry Registry, hostID string, probeID string, probe *probe.
}

// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "Docker" }
func (*Reporter) Name() string { return "Docker" }

// Report generates a Report containing Container and ContainerImage topologies
func (r *Reporter) Report() (report.Report, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ type ReporterConfig struct {
}

// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "Endpoint" }
func (*Reporter) Name() string { return "Endpoint" }
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *Reporter) Stop() {
}

// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "K8s" }
func (*Reporter) Name() string { return "K8s" }

//func (r *Reporter) podEvent(e Event, pod Pod) {
// // filter out non-local pods, if we have been given a node name to report on
Expand Down
8 changes: 7 additions & 1 deletion deepfence_agent/tools/apache/scope/probe/process/reporter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package process

import (
"path/filepath"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -70,7 +71,7 @@ func NewReporter(walker Walker, hostID string, jiffies Jiffies, noCommandLineArg
}

// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "Process" }
func (*Reporter) Name() string { return "Process" }

func (r *Reporter) updateProcessCache() {

Expand Down Expand Up @@ -110,6 +111,10 @@ func (r *Reporter) Report() (report.Report, error) {
return result, nil
}

func shortProcessName(processName string) string {
return filepath.Base(processName)
}

func (r *Reporter) processTopology() (report.Topology, error) {
t := report.MakeTopology()
deltaTotal, maxCPU, err := r.jiffies()
Expand All @@ -124,6 +129,7 @@ func (r *Reporter) processTopology() (report.Topology, error) {
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
NodeID: nodeID,
NodeName: p.Name,
ShortNodeName: shortProcessName(p.Name),
NodeType: report.Process,
HostName: r.hostName,
Pid: p.PID,
Expand Down
9 changes: 5 additions & 4 deletions deepfence_agent/tools/apache/scope/report/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func (m Metadata) WithID(id string) Metadata {
}

type Metadata struct {
NodeID string `json:"node_id"`
NodeType string `json:"node_type,omitempty"`
NodeName string `json:"node_name,omitempty"`
Timestamp string `json:"timestamp"`
NodeID string `json:"node_id"`
NodeType string `json:"node_type,omitempty"`
NodeName string `json:"node_name,omitempty"`
ShortNodeName string `json:"short_name,omitempty"`
Timestamp string `json:"timestamp"`

// cloud metadata
InstanceID string `json:"instance_id,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion deepfence_server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
go.opentelemetry.io/otel v1.18.0
go.opentelemetry.io/otel/exporters/jaeger v1.16.0
go.opentelemetry.io/otel/sdk v1.18.0
go.opentelemetry.io/otel/trace v1.18.0
golang.org/x/crypto v0.12.0
gotest.tools v2.2.0+incompatible
k8s.io/api v0.28.0
Expand Down Expand Up @@ -119,7 +120,6 @@ require (
github.com/twmb/franz-go/pkg/kmsg v1.6.1 // indirect
go.opentelemetry.io/contrib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.14.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions deepfence_server/model/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (c Container) id() string {
type Process struct {
ID string `json:"node_id" required:"true"`
Name string `json:"node_name" required:"true"`
ShortNodeName string `json:"short_name" required:"true"`
PID int `json:"pid" required:"true"`
Command string `json:"cmdline" required:"true"`
PPID int `json:"ppid" required:"true"`
Expand Down
9 changes: 5 additions & 4 deletions deepfence_server/pkg/scope/report/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func (m Metadata) WithID(id string) Metadata {
}

type Metadata struct {
NodeID string `json:"node_id"`
NodeType string `json:"node_type"`
NodeName string `json:"node_name"`
Timestamp string `json:"timestamp"`
NodeID string `json:"node_id"`
NodeType string `json:"node_type"`
NodeName string `json:"node_name"`
ShortNodeName string `json:"short_name,omitempty"`
Timestamp string `json:"timestamp"`

// cloud metadata
InstanceID string `json:"instance_id,omitempty"`
Expand Down

0 comments on commit 2a214be

Please sign in to comment.