forked from esurdam/go-sophos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snmp.go
211 lines (175 loc) · 7.41 KB
/
snmp.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
package objects
import (
"fmt"
"github.com/esurdam/go-sophos"
)
// Snmp is a generated struct representing the Sophos Snmp Endpoint
// GET /api/nodes/snmp
type Snmp struct {
AllowedNetworks []interface{} `json:"allowed_networks"`
AuthPassword string `json:"auth_password"`
AuthType string `json:"auth_type"`
Community string `json:"community"`
DeviceAdmin string `json:"device_admin"`
DeviceLocation string `json:"device_location"`
DeviceName string `json:"device_name"`
EncryptPassword string `json:"encrypt_password"`
EncryptType string `json:"encrypt_type"`
Status int64 `json:"status"`
Traps []interface{} `json:"traps"`
TrapsUseOldOids int64 `json:"traps_use_old_oids"`
Username string `json:"username"`
Version string `json:"version"`
}
var _ sophos.Endpoint = &Snmp{}
var defsSnmp = map[string]sophos.RestObject{
"SnmpGroup": &SnmpGroup{},
"SnmpTrap": &SnmpTrap{},
}
// RestObjects implements the sophos.Node interface and returns a map of Snmp's Objects
func (Snmp) RestObjects() map[string]sophos.RestObject { return defsSnmp }
// GetPath implements sophos.RestGetter
func (*Snmp) GetPath() string { return "/api/nodes/snmp" }
// RefRequired implements sophos.RestGetter
func (*Snmp) RefRequired() (string, bool) { return "", false }
var defSnmp = &sophos.Definition{Description: "snmp", Name: "snmp", Link: "/api/definitions/snmp"}
// Definition returns the /api/definitions struct of Snmp
func (Snmp) Definition() sophos.Definition { return *defSnmp }
// ApiRoutes returns all known Snmp Paths
func (Snmp) ApiRoutes() []string {
return []string{
"/api/objects/snmp/group/",
"/api/objects/snmp/group/{ref}",
"/api/objects/snmp/group/{ref}/usedby",
"/api/objects/snmp/trap/",
"/api/objects/snmp/trap/{ref}",
"/api/objects/snmp/trap/{ref}/usedby",
}
}
// References returns the Snmp's references. These strings serve no purpose other than to demonstrate which
// Reference keys are used for this Endpoint
func (Snmp) References() []string {
return []string{
"REF_SnmpGroup",
"REF_SnmpTrap",
}
}
// SnmpGroups is an Sophos Endpoint subType and implements sophos.RestObject
type SnmpGroups []SnmpGroup
// SnmpGroup represents a UTM group
type SnmpGroup struct {
Locked string `json:"_locked"`
ObjectType string `json:"_type"`
Reference string `json:"_ref"`
Comment string `json:"comment"`
Name string `json:"name"`
}
var _ sophos.RestGetter = &SnmpGroup{}
// GetPath implements sophos.RestObject and returns the SnmpGroups GET path
// Returns all available snmp/group objects
func (*SnmpGroups) GetPath() string { return "/api/objects/snmp/group/" }
// RefRequired implements sophos.RestObject
func (*SnmpGroups) RefRequired() (string, bool) { return "", false }
// GetPath implements sophos.RestObject and returns the SnmpGroups GET path
// Returns all available group types
func (s *SnmpGroup) GetPath() string { return fmt.Sprintf("/api/objects/snmp/group/%s", s.Reference) }
// RefRequired implements sophos.RestObject
func (s *SnmpGroup) RefRequired() (string, bool) { return s.Reference, true }
// DeletePath implements sophos.RestObject and returns the SnmpGroup DELETE path
// Creates or updates the complete object group
func (*SnmpGroup) DeletePath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/group/%s", ref)
}
// PatchPath implements sophos.RestObject and returns the SnmpGroup PATCH path
// Changes to parts of the object group types
func (*SnmpGroup) PatchPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/group/%s", ref)
}
// PostPath implements sophos.RestObject and returns the SnmpGroup POST path
// Create a new snmp/group object
func (*SnmpGroup) PostPath() string {
return "/api/objects/snmp/group/"
}
// PutPath implements sophos.RestObject and returns the SnmpGroup PUT path
// Creates or updates the complete object group
func (*SnmpGroup) PutPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/group/%s", ref)
}
// UsedByPath implements sophos.RestObject
// Returns the objects and the nodes that use the object with the given ref
func (*SnmpGroup) UsedByPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/group/%s/usedby", ref)
}
// SnmpTraps is an Sophos Endpoint subType and implements sophos.RestObject
type SnmpTraps []SnmpTrap
// SnmpTrap represents a UTM SNMP trap
type SnmpTrap struct {
Locked string `json:"_locked"`
ObjectType string `json:"_type"`
Reference string `json:"_ref"`
Comment string `json:"comment"`
// EncryptType can be one of: []string{"None", "DES", "AES"}
// EncryptType default value is "None"
EncryptType string `json:"encrypt_type"`
// Host description: REF(network/host), REF(network/dns_host), REF(network/availability_group)
Host string `json:"host"`
// Username description: (SNMPSTRING)
// Username default value is ""
Username string `json:"username"`
// Version can be one of: []string{"v2c", "v3"}
// Version default value is "v2c"
Version string `json:"version"`
// AuthPassword description: (SNMPSTRING)
// AuthPassword default value is ""
AuthPassword string `json:"auth_password"`
// AuthType can be one of: []string{"MD5", "SHA"}
// AuthType default value is "MD5"
AuthType string `json:"auth_type"`
// Community description: (SNMPSTRING)
// Community default value is "public"
Community string `json:"community"`
// EncryptPassword description: (SNMPSTRING)
// EncryptPassword default value is ""
EncryptPassword string `json:"encrypt_password"`
// Engineid default value is ""
Engineid string `json:"engineid"`
Name string `json:"name"`
// Status default value is true
Status bool `json:"status"`
}
var _ sophos.RestGetter = &SnmpTrap{}
// GetPath implements sophos.RestObject and returns the SnmpTraps GET path
// Returns all available snmp/trap objects
func (*SnmpTraps) GetPath() string { return "/api/objects/snmp/trap/" }
// RefRequired implements sophos.RestObject
func (*SnmpTraps) RefRequired() (string, bool) { return "", false }
// GetPath implements sophos.RestObject and returns the SnmpTraps GET path
// Returns all available trap types
func (s *SnmpTrap) GetPath() string { return fmt.Sprintf("/api/objects/snmp/trap/%s", s.Reference) }
// RefRequired implements sophos.RestObject
func (s *SnmpTrap) RefRequired() (string, bool) { return s.Reference, true }
// DeletePath implements sophos.RestObject and returns the SnmpTrap DELETE path
// Creates or updates the complete object trap
func (*SnmpTrap) DeletePath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/trap/%s", ref)
}
// PatchPath implements sophos.RestObject and returns the SnmpTrap PATCH path
// Changes to parts of the object trap types
func (*SnmpTrap) PatchPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/trap/%s", ref)
}
// PostPath implements sophos.RestObject and returns the SnmpTrap POST path
// Create a new snmp/trap object
func (*SnmpTrap) PostPath() string {
return "/api/objects/snmp/trap/"
}
// PutPath implements sophos.RestObject and returns the SnmpTrap PUT path
// Creates or updates the complete object trap
func (*SnmpTrap) PutPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/trap/%s", ref)
}
// UsedByPath implements sophos.RestObject
// Returns the objects and the nodes that use the object with the given ref
func (*SnmpTrap) UsedByPath(ref string) string {
return fmt.Sprintf("/api/objects/snmp/trap/%s/usedby", ref)
}