-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateway.go
244 lines (207 loc) · 7.99 KB
/
gateway.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
Copyright © 2022 ITRS Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Geneos configuration data model, sparsely populated
As the requirements for the various configuration items increases, just
add more to these structs
Beware the complexities of encoding/xml tags
Order of fields in structs is important, otherwise the Gateway validation
will warn of wrong ordering
*/
package geneos
import (
"encoding/xml"
"io"
)
// Gateway is for reading a Gateway configuration
type Gateway struct {
XMLName xml.Name `xml:"gateway"`
Compatibility int `xml:"compatibility,attr"`
XMLNs string `xml:"xmlns:xsi,attr"` // http://www.w3.org/2001/XMLSchema-instance
XSI string `xml:"xsi:noNamespaceSchemaLocation,attr"` // http://schema.itrsgroup.com/GA5.12.0-220125/gateway.xsd
Probes *Probes `xml:"probes"`
ManagedEntities *ManagedEntities `xml:"managedEntities,omitempty"`
Types *Types `xml:"types,omitempty"`
Samplers *Samplers `xml:"samplers,omitempty"`
Rules *Rules `xml:"rules,omitempty"`
Environments *Environments `xml:"environments,omitempty"`
ProcessDescriptors *ProcessDescriptors `xml:"staticVars>processDescriptors,omitempty"`
OperatingEnvironment *OperatingEnvironment `xml:"operatingEnvironment,omitempty"`
}
type OperatingEnvironment struct {
XMLName xml.Name `xml:"operatingEnvironment"`
GatewayID int `xml:"gatewayId"`
GatewayName string `xml:"gatewayName"`
SecurePort int `xml:"listenPorts>secure>listenPort,omitempty"`
InsecurePort int `xml:"listenPorts>insecure>listenPort,omitempty"`
}
type Dataview struct {
Name string `xml:"name,attr"`
Additions DataviewAdditions `xml:"additions,omitempty" json:",omitempty" yaml:",omitempty"`
}
type DataviewAdditions struct {
XMLName xml.Name `xml:"additions" json:"-" yaml:"-"`
Headlines DataviewAdditionHeadlines `xml:"var-headlines,omitempty"`
Columns DataviewAdditionColumns `xml:"var-columns,omitempty"`
Rows DataviewAdditionRows `xml:"var-rows,omitempty"`
}
var _ xml.Unmarshaler = (*DataviewAdditions)(nil)
// UnmarshalXML deals with the case where merged XML configs have the
// "var-" prefix of the tags removed
func (v *DataviewAdditions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
if v == nil {
v = &DataviewAdditions{}
}
for {
tok, err := d.Token()
if err != nil {
if err == io.EOF {
return nil
}
return err
}
element, ok := tok.(xml.StartElement)
if !ok {
continue
}
switch element.Name.Local {
case "var-headlines", "headlines":
s := DataviewAdditionHeadlines{}
err = d.DecodeElement(&s, &element)
if err != nil {
return err
}
v.Headlines = s
case "var-columns", "columns":
s := DataviewAdditionColumns{}
err = d.DecodeElement(&s, &element)
if err != nil {
return err
}
v.Columns = s
case "var-rows", "rows":
s := DataviewAdditionRows{}
err = d.DecodeElement(&s, &element)
if err != nil {
return err
}
v.Rows = s
}
}
}
type DataviewAddition struct {
XMLName xml.Name `xml:"data" json:"-" yaml:"-"`
Name *SingleLineStringVar `xml:"headline,omitempty"`
}
type DataviewAdditionHeadlines struct {
Var *Var `xml:"var,omitempty"`
Headlines []SingleLineStringVar `xml:"data>headline,omitempty"`
}
type DataviewAdditionColumns struct {
Var *Var `xml:"var,omitempty"`
Headlines []SingleLineStringVar `xml:"data>column,omitempty"`
}
type DataviewAdditionRows struct {
Var *Var `xml:"var,omitempty"`
Headlines []SingleLineStringVar `xml:"data>rows,omitempty"`
}
type Schemas struct {
Dataviews *[]DataviewSchema `xml:"dataviews>dataviewSchema,omitempty"`
}
type DataviewSchema struct {
Dataview string `xml:"dataview,omitempty"`
Schema Schema `xml:"schema>data"`
}
type Schema struct {
Headlines *[]SchemaTypedItem `xml:"headlines>headline,omitempty"`
Columns *[]SchemaTypedItem `xml:"columns>column,omitempty"`
Pivot bool `xml:"pivot,omitempty"`
Publish bool `xml:"publish"`
}
type SchemaTypedItem struct {
Name string `xml:"name"`
String *EmptyStruct `xml:"string,omitempty"`
Boolean *EmptyStruct `xml:"boolean,omitempty"`
Float32 *UnitOfMeasure `xml:"float32,omitempty"`
Float64 *UnitOfMeasure `xml:"float64,omitempty"`
Int32 *UnitOfMeasure `xml:"int32,omitempty"`
Int64 *UnitOfMeasure `xml:"int64,omitempty"`
Date *EmptyStruct `xml:"date,omitempty"`
DateTime *EmptyStruct `xml:"dateTime,omitempty"`
}
type UOM string
const (
None UOM = ""
Percent UOM = "percent"
Seconds UOM = "seconds"
Milliseconds UOM = "milliseconds"
Microseconds UOM = "microseconds"
Nanoseconds UOM = "nanoseconds"
Days UOM = "days"
PerSecond UOM = "per second"
Megahertz UOM = "megahertz"
Bytes UOM = "bytes"
Kibibytes UOM = "kibibytes"
Mebibytes UOM = "mebibytes"
Gibibytes UOM = "gibibytes"
BytesPerSecond UOM = "bytes per second"
Megabits UOM = "megabits"
MegabitsPerSecond UOM = "megabits per second"
)
type UnitOfMeasure struct {
Unit UOM `xml:"unitOfMeasure"`
}
type StandardisedFormatting struct {
Dataviews []StandardisedFormattingDataview `xml:"dataviews>dataview,omitempty" json:",omitempty" yaml:",omitempty"`
}
type StandardisedFormattingDataview struct {
Name string `xml:"name"` // do not omitempty
Variables []StandardisedFormattingVariable `xml:"variables>variable"`
}
type StandardisedFormattingVariable struct {
Type *StandardisedFormattingType `xml:"type"`
Applicability *StandardisedFormattingApplicability `xml:"applicability"`
}
type StandardisedFormattingType struct {
DateTime *StandardisedFormattingDateTime `xml:"dateTime"`
}
type StandardisedFormattingDateTime struct {
Formats []string `xml:"formats>format,omitempty"`
Exceptions []string `xml:"exceptions,omitempty"`
IgnoreErrorsIfFormatFails bool `xml:"ignoreErrorsIfFormatsFail,omitempty"`
OverrideTimezone string `xml:"overrideTimezone,omitempty"`
}
type StandardisedFormattingApplicability struct {
Headlines []Regex `xml:"headlines>pattern,omitempty"`
Columns []Regex `xml:"columns>pattern,omitempty"`
Cells []StandardisedFormattingCell `xml:"cells>cell,omitempty"`
}
type StandardisedFormattingCell struct {
Row string `xml:"row"`
Column string `xml:"column"`
}
type ActiveTimeRef struct {
XMLName xml.Name `xml:"activeTime"`
ActiveTime *ActiveTimeByName `xml:"activeTime,omitempty"`
Var *Var `xml:"var,omitempty"`
}
type ActiveTimeByName struct {
XMLName xml.Name `xml:"activeTime"`
ActiveTime string `xml:"ref,attr"`
}