-
Notifications
You must be signed in to change notification settings - Fork 1
/
play_script_action.go
143 lines (119 loc) · 4.19 KB
/
play_script_action.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"log/slog"
)
// ***************************************************************************************
// ***************************************************************************************
// play_script_fact
// ***************************************************************************************
// ***************************************************************************************
type PlayScriptAction struct {
Name *Field `yaml:"name,omitempty" json:"name,omitempty"`
With []any `yaml:"with,omitempty" json:"with,omitempty"`
When []*exporterTemplate `yaml:"when,omitempty" json:"when,omitempty"`
LoopVar string `yaml:"loop_var,omitempty" json:"loop_var,omitempty"`
Vars [][]any `yaml:"vars,omitempty" json:"vars,omitempty"`
Until []*exporterTemplate `yaml:"until,omitempty" json:"until,omitempty"`
PlayScriptActionName string `yaml:"play_script" json:"play_script"`
playScriptAction *YAMLScript
vars [][]any
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
func (a *PlayScriptAction) Type() int {
return play_script_action
}
func (a *PlayScriptAction) GetName(symtab map[string]any, logger *slog.Logger) string {
str, err := a.Name.GetValueString(symtab, nil, false)
if err != nil {
logger.Warn(
fmt.Sprintf("invalid action name: %v", err),
"collid", CollectorId(symtab, logger),
"script", ScriptName(symtab, logger))
return ""
}
return str
}
func (a *PlayScriptAction) GetNameField() *Field {
return a.Name
}
func (a *PlayScriptAction) SetNameField(name *Field) {
a.Name = name
}
func (a *PlayScriptAction) GetWidh() []any {
return a.With
}
func (a *PlayScriptAction) SetWidth(with []any) {
a.With = with
}
func (a *PlayScriptAction) GetWhen() []*exporterTemplate {
return a.When
}
func (a *PlayScriptAction) SetWhen(when []*exporterTemplate) {
a.When = when
}
func (a *PlayScriptAction) GetLoopVar() string {
return a.LoopVar
}
func (a *PlayScriptAction) SetLoopVar(loopvar string) {
a.LoopVar = loopvar
}
func (a *PlayScriptAction) GetVars() [][]any {
return a.Vars
}
func (a *PlayScriptAction) SetVars(vars [][]any) {
a.vars = vars
}
func (a *PlayScriptAction) GetUntil() []*exporterTemplate {
return a.Until
}
func (a *PlayScriptAction) SetUntil(until []*exporterTemplate) {
a.Until = until
}
func (a *PlayScriptAction) setBasicElement(
nameField *Field,
vars [][]any,
with []any,
loopVar string,
when []*exporterTemplate,
until []*exporterTemplate) error {
return setBasicElement(a, nameField, vars, with, loopVar, when, until)
}
func (a *PlayScriptAction) PlayAction(script *YAMLScript, symtab map[string]any, logger *slog.Logger) error {
return PlayBaseAction(script, symtab, logger, a, a.CustomAction)
}
// only for MetricsAction
func (a *PlayScriptAction) GetMetrics() []*GetMetricsRes {
return nil
}
// only for MetricAction
func (a *PlayScriptAction) GetMetric() *MetricConfig {
return nil
}
func (a *PlayScriptAction) SetMetricFamily(*MetricFamily) {
}
// only for PlayAction
func (a *PlayScriptAction) SetPlayAction(scripts map[string]*YAMLScript) error {
if script, ok := scripts[a.PlayScriptActionName]; ok && script != nil {
a.playScriptAction = script
return nil
}
return fmt.Errorf("scriptname not found in play_script action %s", a.PlayScriptActionName)
}
// specific behavior for the PlayScriptAction
func (a *PlayScriptAction) CustomAction(script *YAMLScript, symtab map[string]any, logger *slog.Logger) error {
logger.Debug(
fmt.Sprintf("[Type: PlayScriptAction] Name: %s", a.GetName(symtab, logger)),
"collid", CollectorId(symtab, logger),
"script", ScriptName(symtab, logger),
"name", a.GetName(symtab, logger))
return a.playScriptAction.Play(symtab, false, logger)
}
func (a *PlayScriptAction) AddCustomTemplate(customTemplate *exporterTemplate) error {
if err := AddCustomTemplate(a, customTemplate); err != nil {
return err
}
return a.playScriptAction.AddCustomTemplate(customTemplate)
}
// ***************************************************************************************