inspektor-gadget

Форк
0
87 строк · 2.3 Кб
1
// Copyright 2022-2023 The Inspektor Gadget authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package tracer
16

17
import (
18
	"fmt"
19
	"strings"
20

21
	gadgetregistry "github.com/inspektor-gadget/inspektor-gadget/pkg/gadget-registry"
22
	"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets"
23
	"github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/snapshot/socket/types"
24
	"github.com/inspektor-gadget/inspektor-gadget/pkg/params"
25
	"github.com/inspektor-gadget/inspektor-gadget/pkg/parser"
26
)
27

28
const (
29
	ParamProto  = "proto"
30
	ParamExtend = "extend"
31
)
32

33
type GadgetDesc struct{}
34

35
func (g *GadgetDesc) Name() string {
36
	return "socket"
37
}
38

39
func (g *GadgetDesc) Category() string {
40
	return gadgets.CategorySnapshot
41
}
42

43
func (g *GadgetDesc) Type() gadgets.GadgetType {
44
	return gadgets.TypeOneShot
45
}
46

47
func (g *GadgetDesc) Description() string {
48
	return "Gather information about TCP and UDP sockets"
49
}
50

51
func (g *GadgetDesc) ParamDescs() params.ParamDescs {
52
	var protocols []string
53
	for protocol := range types.ProtocolsMap {
54
		protocols = append(protocols, protocol)
55
	}
56
	return params.ParamDescs{
57
		{
58
			Key:            ParamProto,
59
			Title:          "Protocol",
60
			DefaultValue:   "all",
61
			Description:    fmt.Sprintf("Show only sockets using this protocol (%s)", strings.Join(protocols, ", ")),
62
			PossibleValues: protocols,
63
		},
64
	}
65
}
66

67
func (g *GadgetDesc) Parser() parser.Parser {
68
	return parser.NewParser[types.Event](types.GetColumns())
69
}
70

71
func (g *GadgetDesc) EventPrototype() any {
72
	return &types.Event{}
73
}
74

75
func (g *GadgetDesc) SortByDefault() []string {
76
	return []string{
77
		"k8s.node", "k8s.namespace", "k8s.pod", "protocol", "status", "src", "dst", "inode",
78
	}
79
}
80

81
func (g *GadgetDesc) SkipParams() []params.ValueHint {
82
	return []params.ValueHint{gadgets.K8SContainerName}
83
}
84

85
func init() {
86
	gadgetregistry.Register(&GadgetDesc{})
87
}
88

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.