forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usergroup.go
146 lines (115 loc) · 4.26 KB
/
usergroup.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
package zabbix
// For `UsergroupObject` field: `DebugMode`
const (
UsergroupDebugModeDisabled = 0
UsergroupDebugModeEnabled = 1
)
// For `UsergroupObject` field: `GuiAccess`
const (
UsergroupGuiAccessSystemDefaultAuth = 0
UsergroupGuiAccessInternalAuth = 1
UsergroupGuiAccessLDAPAuth = 2
UsergroupGuiAccessDisableFrontend = 3
)
// For `UsergroupObject` field: `UsersStatus`
const (
UsergroupUsersStatusEnabled = 0
UsergroupUsersStatusDisabled = 1
)
// For `UsergroupPermissionObject` field: `Permission`
const (
UsergroupPermissionDenied = 0
UsergroupPermissionRO = 2
UsergroupPermissionRW = 3
)
// UsergroupObject struct is used to store usergroup operations results
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/usergroup/object#user_group
type UsergroupObject struct {
UsrgrpID int `json:"usrgrpid,omitempty"`
Name string `json:"name,omitempty"`
DebugMode int `json:"debug_mode,omitempty"` // has defined consts, see above
GuiAccess int `json:"gui_access,omitempty"` // has defined consts, see above
UsersStatus int `json:"users_status,omitempty"` // has defined consts, see above
Users []UserObject `json:"users,omitempty"`
Rights []UsergroupPermissionObject `json:"rights,omitempty"`
TagFilters []UsergroupTagBasedPermissionObject `json:"tag_filters,omitempty"`
// used when new usergroup created or updated
UserIDs []int `json:"userids,omitempty"`
}
// UsergroupPermissionObject struct is used to store usergroup permissions
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/usergroup/object#permission
type UsergroupPermissionObject struct {
ID int `json:"id"`
Permission int `json:"permission"` // has defined consts, see above
}
// UsergroupTagBasedPermissionObject struct is used to store usergroup tag based permission
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/usergroup/object#tag_based_permission
type UsergroupTagBasedPermissionObject struct {
GroupID int `json:"groupid,omitempty"`
Tag string `json:"tag,omitempty"`
Value string `json:"value,omitempty"`
}
// UsergroupGetParams struct is used for usergroup get requests
//
// see: https://www.zabbix.com/documentation/5.0/manual/api/reference/usergroup/get#parameters
type UsergroupGetParams struct {
GetParameters
Status []int `json:"status,omitempty"`
UserIDs []int `json:"userids,omitempty"`
UsrgrpIDs []int `json:"usrgrpids,omitempty"`
WithGuiAccess []int `json:"with_gui_access,omitempty"`
SelectTagFilters SelectQuery `json:"selectTagFilters,omitempty"`
SelectUsers SelectQuery `json:"selectUsers,omitempty"`
SelectRights SelectQuery `json:"selectRights,omitempty"`
}
// Structure to store creation result
type usergroupCreateResult struct {
UsrgrpIDs []int `json:"usrgrpids"`
}
// Structure to store updation result
type usergroupUpdateResult struct {
UsrgrpIDs []int `json:"usrgrpids"`
}
// Structure to store deletion result
type usergroupDeleteResult struct {
UsrgrpIDs []int `json:"usrgrpids"`
}
// UsergroupGet gets usergroups
func (z *Context) UsergroupGet(params UsergroupGetParams) ([]UsergroupObject, int, error) {
var result []UsergroupObject
status, err := z.request("usergroup.get", params, &result)
if err != nil {
return nil, status, err
}
return result, status, nil
}
// UsergroupCreate creates usergroups
func (z *Context) UsergroupCreate(params []UsergroupObject) ([]int, int, error) {
var result usergroupCreateResult
status, err := z.request("usergroup.create", params, &result)
if err != nil {
return nil, status, err
}
return result.UsrgrpIDs, status, nil
}
// UsergroupUpdate updates usergroups
func (z *Context) UsergroupUpdate(params []UsergroupObject) ([]int, int, error) {
var result usergroupUpdateResult
status, err := z.request("usergroup.update", params, &result)
if err != nil {
return nil, status, err
}
return result.UsrgrpIDs, status, nil
}
// UsergroupDelete deletes usergroups
func (z *Context) UsergroupDelete(usergroupIDs []int) ([]int, int, error) {
var result usergroupDeleteResult
status, err := z.request("usergroup.delete", usergroupIDs, &result)
if err != nil {
return nil, status, err
}
return result.UsrgrpIDs, status, nil
}