-
Notifications
You must be signed in to change notification settings - Fork 4
/
classicapi_computer_history.go
336 lines (274 loc) · 16.1 KB
/
classicapi_computer_history.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// classicapi_computer_history.go
// Jamf Pro Classic Api - Computer History
// api reference: https://developer.jamf.com/jamf-pro/reference/computerhistory
// Classic API requires the structs to support an XML data structure.
package jamfpro
import "fmt"
const uriComputerHistory = "/JSSResource/computerhistory"
// ResourceComputerHistory represents the root structure of the computer history resource.
type ResourceComputerHistory struct {
General ComputerHistorySubsetGeneralInfo `json:"general" xml:"general"`
ComputerUsageLogs []ComputerHistorySubsetUsageLog `json:"computer_usage_logs,omitempty" xml:"computer_usage_logs,omitempty"`
Audits []ComputerHistorySubsetAudit `json:"audits,omitempty" xml:"audits,omitempty"`
PolicyLogs []ComputerHistorySubsetPolicyLog `json:"policy_logs,omitempty" xml:"policy_logs,omitempty"`
CasperRemoteLogs []ComputerHistorySubsetCasperRemote `json:"casper_remote_logs,omitempty" xml:"casper_remote_logs,omitempty"`
ScreenSharingLogs []ComputerHistorySubsetScreenSharing `json:"screen_sharing_logs,omitempty" xml:"screen_sharing_logs,omitempty"`
CasperImagingLogs []ComputerHistorySubsetCasperImaging `json:"casper_imaging_logs,omitempty" xml:"casper_imaging_logs,omitempty"`
Commands ComputerHistorySubsetCommands `json:"commands,omitempty" xml:"commands,omitempty"`
UserLocation []ComputerHistorySubsetLocation `json:"user_location,omitempty" xml:"user_location,omitempty"`
MacAppStoreApps ComputerHistorySubsetAppStoreApps `json:"mac_app_store_applications,omitempty" xml:"mac_app_store_applications,omitempty"`
}
// ComputerHistorySubsetGeneralInfo stores general information about the computer.
type ComputerHistorySubsetGeneralInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
UDID string `json:"udid,omitempty" xml:"udid,omitempty"`
SerialNumber string `json:"serial_number,omitempty" xml:"serial_number,omitempty"`
MacAddress string `json:"mac_address,omitempty" xml:"mac_address,omitempty"`
}
// ComputerHistorySubsetUsageLog stores logs related to computer usage.
type ComputerHistorySubsetUsageLog struct {
UsageLog ComputerHistorySubsetEventDetails `json:"usage_log,omitempty" xml:"usage_log,omitempty"`
}
// ComputerHistorySubsetAudit stores audit logs.
type ComputerHistorySubsetAudit struct {
Audit ComputerHistorySubsetEventDetails `json:"audit,omitempty" xml:"audit,omitempty"`
}
// ComputerHistorySubsetPolicyLog stores logs related to policies.
type ComputerHistorySubsetPolicyLog struct {
PolicyLog ComputerHistorySubsetPolicyDetails `json:"policy_log,omitempty" xml:"policy_log,omitempty"`
}
// ComputerHistorySubsetCasperRemote stores logs for Casper remote actions.
type ComputerHistorySubsetCasperRemote struct {
CasperRemoteLog ComputerHistorySubsetEventStatus `json:"casper_remote_log" xml:"casper_remote_log"`
}
// ComputerHistorySubsetScreenSharing stores logs related to screen sharing.
type ComputerHistorySubsetScreenSharing struct {
ScreenSharingLog ComputerHistorySubsetScreenSharingDetails `json:"screen_sharing_log,omitempty" xml:"screen_sharing_log,omitempty"`
}
// ComputerHistorySubsetCasperImaging stores logs for Casper imaging actions.
type ComputerHistorySubsetCasperImaging struct {
CasperImagingLog ComputerHistorySubsetEventStatus `json:"casper_imaging_log,omitempty" xml:"casper_imaging_log,omitempty"`
}
// ComputerHistorySubsetCommands groups completed, pending, and failed commands.
type ComputerHistorySubsetCommands struct {
Completed []ComputerHistorySubsetCommand `json:"completed,omitempty" xml:"completed,omitempty"`
Pending []ComputerHistorySubsetCommand `json:"pending,omitempty" xml:"pending,omitempty"`
Failed []ComputerHistorySubsetCommand `json:"failed,omitempty" xml:"failed,omitempty"`
}
// ComputerHistorySubsetLocation stores location data related to a user.
type ComputerHistorySubsetLocation struct {
Location ComputerHistorySubsetUserLocation `json:"location,omitempty" xml:"location,omitempty"`
}
// ComputerHistorySubsetAppStoreApps groups installed, pending, and failed applications from the Mac App Store.
type ComputerHistorySubsetAppStoreApps struct {
Installed []ComputerHistorySubsetApp `json:"installed,omitempty" xml:"installed,omitempty"`
Pending []ComputerHistorySubsetApp `json:"pending,omitempty" xml:"pending,omitempty"`
Failed []ComputerHistorySubsetApp `json:"failed,omitempty" xml:"failed,omitempty"`
}
// ComputerHistorySubsetEventDetails defines the structure for logging events with timestamps and user information.
type ComputerHistorySubsetEventDetails struct {
Event string `json:"event,omitempty" xml:"event,omitempty"`
Username string `json:"username,omitempty" xml:"username,omitempty"`
DateTime string `json:"date_time,omitempty" xml:"date_time,omitempty"`
DateTimeEpoch int64 `json:"date_time_epoch,omitempty" xml:"date_time_epoch,omitempty"`
DateTimeUTC string `json:"date_time_utc,omitempty" xml:"date_time_utc,omitempty"`
}
// ComputerHistorySubsetPolicyDetails defines the details for policy logs.
type ComputerHistorySubsetPolicyDetails struct {
PolicyID int `json:"policy_id,omitempty" xml:"policy_id,omitempty"`
PolicyName string `json:"policy_name,omitempty" xml:"policy_name,omitempty"`
Username string `json:"username,omitempty" xml:"username,omitempty"`
DateTime string `json:"date_time,omitempty" xml:"date_time,omitempty"`
DateTimeEpoch int64 `json:"date_time_epoch,omitempty" xml:"date_time_epoch,omitempty"`
DateTimeUTC string `json:"date_time_utc,omitempty" xml:"date_time_utc,omitempty"`
Status string `json:"status,omitempty" xml:"status,omitempty"`
}
// ComputerHistorySubsetEventStatus defines a simple structure for logs with status and timestamps.
type ComputerHistorySubsetEventStatus struct {
DateTime string `json:"date_time,omitempty" xml:"date_time,omitempty"`
DateTimeEpoch int64 `json:"date_time_epoch,omitempty" xml:"date_time_epoch,omitempty"`
DateTimeUTC string `json:"date_time_utc,omitempty" xml:"date_time_utc,omitempty"`
Status string `json:"status,omitempty" xml:"status,omitempty"`
}
// ComputerHistorySubsetScreenSharingDetails extends event status with details specific to screen sharing.
type ComputerHistorySubsetScreenSharingDetails struct {
ComputerHistorySubsetEventStatus
Details string `json:"details,omitempty" xml:"details,omitempty"`
}
// ComputerHistorySubsetCommand details a command with its issue and completion status.
type ComputerHistorySubsetCommand struct {
Name string `json:"name,omitempty" xml:"name,omitempty"`
Status string `json:"status,omitempty" xml:"status,omitempty"`
Issued string `json:"issued,omitempty" xml:"issued,omitempty"`
IssuedEpoch int64 `json:"issued_epoch,omitempty" xml:"issued_epoch,omitempty"`
IssuedUTC string `json:"issued_utc,omitempty" xml:"issued_utc,omitempty"`
LastPush string `json:"last_push,omitempty" xml:"last_push,omitempty"`
LastPushEpoch int64 `json:"last_push_epoch,omitempty" xml:"last_push_epoch,omitempty"`
LastPushUTC string `json:"last_push_utc,omitempty" xml:"last_push_utc,omitempty"`
Username string `json:"username,omitempty" xml:"username,omitempty"`
Completed string `json:"completed,omitempty" xml:"completed,omitempty"`
CompletedEpoch int64 `json:"completed_epoch,omitempty" xml:"completed_epoch,omitempty"`
CompletedUTC string `json:"completed_utc,omitempty" xml:"completed_utc,omitempty"`
Failed string `json:"failed,omitempty" xml:"failed,omitempty"`
FailedEpoch int64 `json:"failed_epoch,omitempty" xml:"failed_epoch,omitempty"`
FailedUTC string `json:"failed_utc,omitempty" xml:"failed_utc,omitempty"`
}
// ComputerHistorySubsetUserLocation defines the detailed information about a user's location.
type ComputerHistorySubsetUserLocation struct {
DateTime string `json:"date_time,omitempty" xml:"date_time,omitempty"`
DateTimeEpoch int64 `json:"date_time_epoch,omitempty" xml:"date_time_epoch,omitempty"`
DateTimeUTC string `json:"date_time_utc,omitempty" xml:"date_time_utc,omitempty"`
Username string `json:"username,omitempty" xml:"username,omitempty"`
FullName string `json:"full_name,omitempty" xml:"full_name,omitempty"`
EmailAddress string `json:"email_address,omitempty" xml:"email_address,omitempty"`
PhoneNumber string `json:"phone_number,omitempty" xml:"phone_number,omitempty"`
Department string `json:"department,omitempty" xml:"department,omitempty"`
Building string `json:"building,omitempty" xml:"building,omitempty"`
Room int `json:"room,omitempty" xml:"room,omitempty"`
Position string `json:"position,omitempty" xml:"position,omitempty"`
}
// ComputerHistorySubsetApp defines the structure for application details in the Mac App Store context.
type ComputerHistorySubsetApp struct {
Name string `json:"name,omitempty" xml:"name,omitempty"`
Version string `json:"version,omitempty" xml:"version,omitempty"`
SizeMB int `json:"size_mb,omitempty" xml:"size_mb,omitempty"`
Status string `json:"status,omitempty" xml:"status,omitempty"`
Deployed string `json:"deployed,omitempty" xml:"deployed,omitempty"`
DeployedEpoch int64 `json:"deployed_epoch,omitempty" xml:"deployed_epoch,omitempty"`
DeployedUTC string `json:"deployed_utc,omitempty" xml:"deployed_utc,omitempty"`
LastUpdate string `json:"last_update,omitempty" xml:"last_update,omitempty"`
LastUpdateEpoch int64 `json:"last_update_epoch,omitempty" xml:"last_update_epoch,omitempty"`
LastUpdateUTC string `json:"last_update_utc,omitempty" xml:"last_update_utc,omitempty"`
}
// CRUD Methods
// GetComputerHistoryByComputerID retrieves the historical information of a computer given its ID.
func (c *Client) GetComputerHistoryByComputerID(id int) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriComputerHistory, id)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer histroy", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerIDAndDataSubset retrieves a subset of the historical information of a computer given its ID and subset name.
func (c *Client) GetComputerHistoryByComputerIDAndDataSubset(id int, subset string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/id/%d/subset/%s", uriComputerHistory, id, subset)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer history with data subset", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerName retrieves the historical information of a computer given its name.
func (c *Client) GetComputerHistoryByComputerName(name string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriComputerHistory, name)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf("failed to retrieve computer history by computer name '%s': %v", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerNameAndDataSubset retrieves a subset of the historical information of a computer given its name and subset name.
func (c *Client) GetComputerHistoryByComputerNameAndDataSubset(name string, subset string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/name/%s/subset/%s", uriComputerHistory, name, subset)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer history with data subset", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerUDID retrieves the historical information of a computer by it's UDID.
func (c *Client) GetComputerHistoryByComputerUDID(udid string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/udid/%s", uriComputerHistory, udid)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf("failed to retrieve computer history by computer udid '%s': %v", udid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerUDIDAndDataSubset retrieves a subset of the historical information of a computer given its udid and subset name.
func (c *Client) GetComputerHistoryByComputerUDIDAndDataSubset(udid string, subset string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/udid/%s/subset/%s", uriComputerHistory, udid, subset)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf("failed to retrieve computer history by computer udid '%s': %v", udid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerSerialNumber retrieves the historical information of a computer by it's serial number
func (c *Client) GetComputerHistoryByComputerSerialNumber(serial string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/serialnumber/%s", uriComputerHistory, serial)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer history with computer serial number", serial, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerSerialNumberAndDataSubset retrieves a subset of the historical information of a computer by it's serial number and data subset name.
func (c *Client) GetComputerHistoryByComputerSerialNumberAndDataSubset(udid string, subset string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/serialnumber/%s/subset/%s", uriComputerHistory, udid, subset)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf("failed to retrieve computer history by computer serial number '%s': %v", udid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerMACAddress retrieves the historical information of a computer by it's MAC Address
func (c *Client) GetComputerHistoryByComputerMACAddress(MACAddress string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/macaddress/%s", uriComputerHistory, MACAddress)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer history with computer MAC Address", MACAddress, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}
// GetComputerHistoryByComputerMACAddressAndDataSubset retrieves a subset of the historical information of a computer by it's serial number and data subset name.
func (c *Client) GetComputerHistoryByComputerMACAddressAndDataSubset(MACAddress string, subset string) (*ResourceComputerHistory, error) {
endpoint := fmt.Sprintf("%s/macaddress/%s/subset/%s", uriComputerHistory, MACAddress, subset)
var computerHistory ResourceComputerHistory
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &computerHistory)
if err != nil {
return nil, fmt.Errorf("failed to retrieve computer history by computer MAC Address '%s': %v", MACAddress, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &computerHistory, nil
}