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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// Provides an interface for obtaining diagnostic information on a host
/// (e.g.
///
/// generating and retrieving support logs on the host, reading audit
/// records).
/// For VirtualCenter, this includes the log files for the server daemon.
/// For an ESX Server host, this includes detailed log files for the VMkernel.
#[derive(Clone)]
pub struct DiagnosticManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl DiagnosticManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Issue a "mark" to syslog and the audit trail.
///
/// The specified message string will be written to syslog and the audit
/// trail. The "mark" audit record will contain the message string in
/// its comment parameter.
///
/// ***Since:*** vSphere API Release 8.0.0.2
///
/// ***Required privileges:*** Global.Diagnostics
///
/// ## Parameters:
///
/// ### message
/// The string to be used.
pub async fn emit_syslog_mark(&self, message: &str) -> Result<()> {
let input = EmitSyslogMarkRequestType {message, };
self.client.invoke_void("", "DiagnosticManager", &self.mo_id, "EmitSyslogMark", Some(&input)).await
}
/// Retrieve audit records from their storage on the specified host.
///
/// Audit records are stored on the host in a (large) FIFO. The FIFO is
/// continuously being written to due to system activities. It is the
/// responsibility of the caller to issue reads fast enough to keep ahead
/// of the write traffic.
///
/// ***Since:*** vSphere API Release 7.0.3.0
///
/// ***Required privileges:*** Global.Diagnostics
///
/// ## Parameters:
///
/// ### token
/// The token to be used for the operation. The first call must
/// be made without a token. All subsequent calls use the token
/// returned in AuditRecordStatus.
///
/// ## Errors:
///
/// ***InvalidState***: The reader has failed to keep up with the write
/// data rate. Data has been lost. It is up to the
/// caller to decide how to react to this. One
/// possibility is to "start again from the beginning"
/// with a call with no token.
///
/// ***SystemError***: One more more errors (on the host) have occurred.
/// One or more error strings are available to detail
/// the issues.
pub async fn fetch_audit_records(&self, token: Option<&str>) -> Result<crate::types::structs::DiagnosticManagerAuditRecordResult> {
let input = FetchAuditRecordsRequestType {token, };
let bytes = self.client.invoke("", "DiagnosticManager", &self.mo_id, "FetchAuditRecords", Some(&input)).await?;
let result: crate::types::structs::DiagnosticManagerAuditRecordResult = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Returns part of a log file.
///
/// Log entries are always returned chronologically, typically with the
/// newest event last.
///
/// ***Required privileges:*** Global.Diagnostics
///
/// ## Parameters:
///
/// ### host
/// Specifies the host. If not specified, then it defaults
/// to the default server. For example, if called on
/// VirtualCenter, then the value defaults to VirtualCenter
/// logs.
///
/// Refers instance of *HostSystem*.
///
/// ### key
/// A string key specifying the key for the log file to
/// browse. Keys can be obtained using the queryDescriptions
/// method.
///
/// ### start
/// The line number for the first entry to be returned. If the
/// parameter is not specified, then the operation returns
/// with lines starting from the top of the log.
///
/// ### lines
/// The number of lines to return. If not specified, then
/// all lines are returned from the start value to the end of
/// the file.
///
/// ## Returns:
///
/// A LogHeader that includes the log lines. Sometimes fewer log
/// lines are returned than were requested. For example, fewer lines
/// are returned than expected if the client requests lines that do
/// not exist or if the server limits the number of lines that it
/// returns. If zero lines are returned, then the end of the log
/// file may have been reached.
///
/// ## Errors:
///
/// ***InvalidArgument***: if the key refers to a nonexistent log file or
/// the log file is not of type "plain".
///
/// ***CannotAccessFile***: if the key refers to a file that cannot be
/// accessed at the present time.
pub async fn browse_diagnostic_log(&self, host: Option<&crate::types::structs::ManagedObjectReference>, key: &str, start: Option<i32>, lines: Option<i32>) -> Result<crate::types::structs::DiagnosticManagerLogHeader> {
let input = BrowseDiagnosticLogRequestType {host, key, start, lines, };
let bytes = self.client.invoke("", "DiagnosticManager", &self.mo_id, "BrowseDiagnosticLog", Some(&input)).await?;
let result: crate::types::structs::DiagnosticManagerLogHeader = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Deprecated since version 5.0 M/N it is recommended to use the CGI
/// interface for the host bundles, use the address instead:
/// `https://<<ESX_name>>/cgi-bin/vm-support.cgi`
/// for the VC bundles, use
/// `https://<<VC_name>>/appliance/support-bundle`
///
/// The caller can download the bundles using an HTTP GET operation
/// for each returned URL. Bundles are usually available for at least 24
/// hours, but the caller should not assume that the returned URLs are
/// valid indefinitely. Servers often automatically delete generated
/// diagnostic bundles after some given period of time.
///
/// Instructs the server to generate diagnostic bundles.
///
/// A diagnostic bundle includes log files and other configuration
/// information that can be used to investigate potential server issues.
/// Virtual machine and guest operation system state is excluded from
/// diagnostic bundles.
///
/// ***Required privileges:*** Global.Diagnostics
///
/// ## Parameters:
///
/// ### include_default
/// Specifies if the bundle should include the
/// default server. If called on a VirtualCenter
/// server, then this means the VirtualCenter
/// diagnostic files. If called directly on a host,
/// then includeDefault must be set to true.
///
/// ### host
/// Lists hosts that are included. This is only used
/// when called on VirtualCenter. If called directly
/// on a host, then this parameter must be empty.
///
/// Refers instances of *HostSystem*.
///
/// ## Returns:
///
/// This method returns a *Task* object with which to
/// monitor the operation. Upon success, the
/// *info.result* property in the
/// *Task* contains a list of
/// *DiagnosticManagerBundleInfo* objects for each
/// diagnostic bundle that has been generated.
///
/// Refers instance of *Task*.
///
/// ## Errors:
///
/// ***LogBundlingFailed***: if generation of support bundle failed.
///
/// ***TaskInProgress***: if there is a pending request to generate a
/// support bundle.
pub async fn generate_log_bundles_task(&self, include_default: bool, host: Option<&[crate::types::structs::ManagedObjectReference]>) -> Result<crate::types::structs::ManagedObjectReference> {
let input = GenerateLogBundlesRequestType {include_default, host, };
let bytes = self.client.invoke("", "DiagnosticManager", &self.mo_id, "GenerateLogBundles_Task", Some(&input)).await?;
let result: crate::types::structs::ManagedObjectReference = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Returns a list of diagnostic files for a given system.
///
/// ***Required privileges:*** Global.Diagnostics
///
/// ## Parameters:
///
/// ### host
/// Specifies the host. If not specified, then it defaults
/// to the server itself. For example, if called on
/// VirtualCenter, then the value defaults to VirtualCenter
/// logs. When called on an ESX server host, the host should
/// not be specified.
///
/// Refers instance of *HostSystem*.
pub async fn query_descriptions(&self, host: Option<&crate::types::structs::ManagedObjectReference>) -> Result<Option<Vec<crate::types::structs::DiagnosticManagerLogDescriptor>>> {
let input = QueryDescriptionsRequestType {host, };
let bytes_opt = self.client.invoke_optional("", "DiagnosticManager", &self.mo_id, "QueryDescriptions", Some(&input)).await?;
match bytes_opt {
Some(ref b) => Ok(Some(crate::core::client::unmarshal_array(self.client.transport(), b)?)),
None => Ok(None),
}
}
}
struct EmitSyslogMarkRequestType<'a> {
message: &'a str,
}
impl<'a> miniserde::Serialize for EmitSyslogMarkRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(EmitSyslogMarkRequestTypeSer { data: self, seq: 0 }))
}
}
struct EmitSyslogMarkRequestTypeSer<'b, 'a> {
data: &'b EmitSyslogMarkRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for EmitSyslogMarkRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"EmitSyslogMarkRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("message"), &self.data.message as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct FetchAuditRecordsRequestType<'a> {
token: Option<&'a str>,
}
impl<'a> miniserde::Serialize for FetchAuditRecordsRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(FetchAuditRecordsRequestTypeSer { data: self, seq: 0 }))
}
}
struct FetchAuditRecordsRequestTypeSer<'b, 'a> {
data: &'b FetchAuditRecordsRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for FetchAuditRecordsRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"FetchAuditRecordsRequestType")),
1 => {
let Some(ref val) = self.data.token else { continue; };
return Some((std::borrow::Cow::Borrowed("token"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct BrowseDiagnosticLogRequestType<'a> {
host: Option<&'a crate::types::structs::ManagedObjectReference>,
key: &'a str,
start: Option<i32>,
lines: Option<i32>,
}
impl<'a> miniserde::Serialize for BrowseDiagnosticLogRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(BrowseDiagnosticLogRequestTypeSer { data: self, seq: 0 }))
}
}
struct BrowseDiagnosticLogRequestTypeSer<'b, 'a> {
data: &'b BrowseDiagnosticLogRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for BrowseDiagnosticLogRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"BrowseDiagnosticLogRequestType")),
1 => {
let Some(ref val) = self.data.host else { continue; };
return Some((std::borrow::Cow::Borrowed("host"), val as &dyn miniserde::Serialize));
}
2 => return Some((std::borrow::Cow::Borrowed("key"), &self.data.key as &dyn miniserde::Serialize)),
3 => {
let Some(ref val) = self.data.start else { continue; };
return Some((std::borrow::Cow::Borrowed("start"), val as &dyn miniserde::Serialize));
}
4 => {
let Some(ref val) = self.data.lines else { continue; };
return Some((std::borrow::Cow::Borrowed("lines"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct GenerateLogBundlesRequestType<'a> {
include_default: bool,
host: Option<&'a [crate::types::structs::ManagedObjectReference]>,
}
impl<'a> miniserde::Serialize for GenerateLogBundlesRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(GenerateLogBundlesRequestTypeSer { data: self, seq: 0 }))
}
}
struct GenerateLogBundlesRequestTypeSer<'b, 'a> {
data: &'b GenerateLogBundlesRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for GenerateLogBundlesRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"GenerateLogBundlesRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("includeDefault"), &self.data.include_default as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.host else { continue; };
return Some((std::borrow::Cow::Borrowed("host"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct QueryDescriptionsRequestType<'a> {
host: Option<&'a crate::types::structs::ManagedObjectReference>,
}
impl<'a> miniserde::Serialize for QueryDescriptionsRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(QueryDescriptionsRequestTypeSer { data: self, seq: 0 }))
}
}
struct QueryDescriptionsRequestTypeSer<'b, 'a> {
data: &'b QueryDescriptionsRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for QueryDescriptionsRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"QueryDescriptionsRequestType")),
1 => {
let Some(ref val) = self.data.host else { continue; };
return Some((std::borrow::Cow::Borrowed("host"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}