-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckCommandArgument.go
More file actions
88 lines (71 loc) · 2.1 KB
/
CheckCommandArgument.go
File metadata and controls
88 lines (71 loc) · 2.1 KB
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
package icingadsl
import (
"strconv"
"strings"
)
// https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#checkcommand-arguments
type CheckCommandArgument struct {
Name string
Value string
Description String
SetIf Object
Separator string
Key string
Order int
RepeatKey bool
Required bool
SkipKey bool
}
// String returns the CheckCommandArgument Object as string with the given prefix
// and proper indentation
func (cca *CheckCommandArgument) String(prefix string) string {
var b strings.Builder
b.WriteString(indentString() + "\"" + cca.Name + "\" = {\n")
indentation++
if cca.Value != "" {
if prefix != "" {
b.WriteString(indentString() + "value = \"$" + prefix + "_" + strings.ReplaceAll(cca.Value, "-", "_") + "$\"\n")
} else {
b.WriteString(indentString() + "value = \"$" + strings.ReplaceAll(cca.Value, "-", "_") + "$\"\n")
}
} else {
b.WriteString(indentString() + "value = \"\"\n")
}
if cca.Description != "" {
b.WriteString(indentString() + "description = " + cca.Description.String() + "\n")
}
if cca.Required {
b.WriteString(indentString() + "required = true\n")
}
if cca.SkipKey {
b.WriteString(indentString() + "skip_key = true\n")
}
if cca.SetIf != nil {
switch tmp := cca.SetIf.(type) {
case String:
if prefix != "" {
b.WriteString(indentString() + "set_if = \"$" + prefix + "_" + strings.ReplaceAll(tmp.RawString(), "-", "_") + "$\"\n")
} else {
b.WriteString(indentString() + "set_if = \"$" + strings.ReplaceAll(tmp.RawString(), "-", "_") + "$\"\n")
}
case Boolean:
b.WriteString(indentString() + "set_if = " + tmp.String() + "\n")
default:
}
}
if cca.Order != 0 {
b.WriteString(indentString() + "order = " + strconv.Itoa(cca.Order) + "\n")
}
if !cca.RepeatKey {
b.WriteString(indentString() + "repeat_key = false\n")
}
if cca.Key != "" {
b.WriteString(indentString() + "key = \"" + cca.Key + "\"\n")
}
if cca.Separator != "" {
b.WriteString(indentString() + "separator = \"" + cca.Separator + "\"\n")
}
indentation--
b.WriteString(indentString() + "}")
return b.String()
}