summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/agent/discovery/sd/discoverer/netlisteners/target.go
blob: 501b280ba17a00d409fc687231e2abfbf47b7777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: GPL-3.0-or-later

package netlisteners

import (
	"fmt"
	"strings"

	"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/model"
)

type targetGroup struct {
	provider string
	source   string
	targets  []model.Target
}

func (g *targetGroup) Provider() string        { return g.provider }
func (g *targetGroup) Source() string          { return g.source }
func (g *targetGroup) Targets() []model.Target { return g.targets }

type target struct {
	model.Base

	hash uint64

	Protocol string
	Address  string
	Port     string
	Comm     string
	Cmdline  string
}

func (t *target) TUID() string { return tuid(t) }
func (t *target) Hash() uint64 { return t.hash }

func tuid(tgt *target) string {
	return fmt.Sprintf("%s_%s_%d", strings.ToLower(tgt.Protocol), tgt.Port, tgt.hash)
}