komodo_client 2.0.0

Client for the Komodo build and deployment system
Documentation
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
use std::path::PathBuf;

use serde::{Deserialize, Serialize};
use strum::{Display, EnumDiscriminants, EnumString};
use typeshare::typeshare;

use crate::entities::{I64, MongoId};

use super::{
  _Serror, ResourceTarget, ResourceTargetVariant, Version,
  deployment::DeploymentState, stack::StackState,
};

/// Representation of an alert in the system.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[cfg_attr(
  feature = "mongo",
  derive(mongo_indexed::derive::MongoIndexed)
)]
#[cfg_attr(feature = "mongo", doc_index({ "data.type": 1 }))]
#[cfg_attr(feature = "mongo", doc_index({ "target.type": 1 }))]
#[cfg_attr(feature = "mongo", doc_index({ "target.id": 1 }))]
pub struct Alert {
  /// The Mongo ID of the alert.
  /// This field is de/serialized from/to JSON as
  /// `{ "_id": { "$oid": "..." }, ...(rest of serialized Alert) }`
  #[serde(
    default,
    rename = "_id",
    skip_serializing_if = "String::is_empty",
    with = "bson::serde_helpers::hex_string_as_object_id"
  )]
  pub id: MongoId,

  /// Unix timestamp in milliseconds the alert was opened
  #[cfg_attr(feature = "mongo", index)]
  pub ts: I64,

  /// Whether the alert is already resolved
  #[cfg_attr(feature = "mongo", index)]
  pub resolved: bool,

  /// The severity of the alert
  #[cfg_attr(feature = "mongo", index)]
  pub level: SeverityLevel,

  /// The target of the alert
  pub target: ResourceTarget,

  /// The data attached to the alert
  pub data: AlertData,

  /// The timestamp of alert resolution
  pub resolved_ts: Option<I64>,
}

/// The variants of data related to the alert.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, EnumDiscriminants)]
#[strum_discriminants(name(AlertDataVariant))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[cfg_attr(
  not(feature = "utoipa"),
  strum_discriminants(derive(Serialize, Deserialize, Hash))
)]
#[cfg_attr(
  feature = "utoipa",
  strum_discriminants(derive(
    Serialize,
    Deserialize,
    Hash,
    utoipa::ToSchema
  ))
)]
#[serde(tag = "type", content = "data")]
pub enum AlertData {
  /// A null alert
  None {},

  /// The user triggered a test of the
  /// Alerter configuration.
  Test {
    /// The id of the alerter
    id: String,
    /// The name of the alerter
    name: String,
  },

  /// A server could not be reached.
  SwarmUnhealthy {
    /// The id of the swarm
    id: String,
    /// The name of the swarm
    name: String,
    /// The error data
    err: Option<String>,
  },

  /// A server could not be reached.
  ServerUnreachable {
    /// The id of the server
    id: String,
    /// The name of the server
    name: String,
    /// The region of the server
    region: Option<String>,
    /// The error data
    err: Option<_Serror>,
  },

  /// A server has high CPU usage.
  ServerCpu {
    /// The id of the server
    id: String,
    /// The name of the server
    name: String,
    /// The region of the server
    region: Option<String>,
    /// The cpu usage percentage
    percentage: f64,
  },

  /// A server has high memory usage.
  ServerMem {
    /// The id of the server
    id: String,
    /// The name of the server
    name: String,
    /// The region of the server
    region: Option<String>,
    /// The used memory
    used_gb: f64,
    /// The total memory
    total_gb: f64,
  },

  /// A server has high disk usage.
  ServerDisk {
    /// The id of the server
    id: String,
    /// The name of the server
    name: String,
    /// The region of the server
    region: Option<String>,
    /// The mount path of the disk
    #[cfg_attr(feature = "utoipa", schema(value_type = String))]
    path: PathBuf,
    /// The used portion of the disk in GB
    used_gb: f64,
    /// The total size of the disk in GB
    total_gb: f64,
  },

  /// A server has a version mismatch with the core.
  ServerVersionMismatch {
    /// The id of the server
    id: String,
    /// The name of the server
    name: String,
    /// The region of the server
    region: Option<String>,
    /// The actual server version
    server_version: String,
    /// The core version
    core_version: String,
  },

  /// A container's state has changed unexpectedly.
  /// For swarms, this refers to swarm service.
  ContainerStateChange {
    /// The id of the deployment
    id: String,
    /// The name of the deployment
    name: String,
    /// The server id of server that the deployment is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the deployment is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// The previous container state
    from: DeploymentState,
    /// The current container state
    to: DeploymentState,
  },

  /// A Deployment has an image update available
  DeploymentImageUpdateAvailable {
    /// The id of the deployment
    id: String,
    /// The name of the deployment
    name: String,
    /// The server id of server that the deployment is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the deployment is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// The image with update
    image: String,
  },

  /// A Deployment has an image update available
  DeploymentAutoUpdated {
    /// The id of the deployment
    id: String,
    /// The name of the deployment
    name: String,
    /// The server id of server that the deployment is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the deployment is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// The updated image
    image: String,
  },

  /// A stack's state has changed unexpectedly.
  StackStateChange {
    /// The id of the stack
    id: String,
    /// The name of the stack
    name: String,
    /// The server id of server that the stack is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the stack is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// The previous stack state
    from: StackState,
    /// The current stack state
    to: StackState,
  },

  /// A Stack has an image update available
  StackImageUpdateAvailable {
    /// The id of the stack
    id: String,
    /// The name of the stack
    name: String,
    /// The server id of server that the stack is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the stack is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// The service name to update
    service: String,
    /// The image with update
    image: String,
  },

  /// A Stack was auto updated
  StackAutoUpdated {
    /// The id of the stack
    id: String,
    /// The name of the stack
    name: String,
    /// The server id of server that the stack is on
    server_id: Option<String>,
    /// The server name
    server_name: Option<String>,
    /// The swarm id of swarm that the stack is on
    swarm_id: Option<String>,
    /// The swarm name
    swarm_name: Option<String>,
    /// One or more images that were updated
    images: Vec<String>,
  },

  /// An AWS builder failed to terminate.
  AwsBuilderTerminationFailed {
    /// The id of the aws instance which failed to terminate
    instance_id: String,
    /// A reason for the failure
    message: String,
  },

  /// A resource sync has pending updates
  ResourceSyncPendingUpdates {
    /// The id of the resource sync
    id: String,
    /// The name of the resource sync
    name: String,
  },

  /// A build has failed
  BuildFailed {
    /// The id of the build
    id: String,
    /// The name of the build
    name: String,
    /// The version that failed to build
    version: Version,
  },

  /// A repo has failed
  RepoBuildFailed {
    /// The id of the repo
    id: String,
    /// The name of the repo
    name: String,
  },

  /// A procedure has failed
  ProcedureFailed {
    /// The id of the procedure
    id: String,
    /// The name of the procedure
    name: String,
  },

  /// An action has failed
  ActionFailed {
    /// The id of the action
    id: String,
    /// The name of the action
    name: String,
  },

  /// A schedule was run
  ScheduleRun {
    /// Procedure or Action
    resource_type: ResourceTargetVariant,
    /// The resource id
    id: String,
    /// The resource name
    name: String,
  },

  /// Custom header / body.
  /// Produced using `/execute/SendAlert`
  Custom {
    /// The alert message.
    message: String,
    /// Message details. May be empty string.
    #[serde(default)]
    details: String,
  },
}

impl Default for AlertData {
  fn default() -> Self {
    AlertData::None {}
  }
}

#[allow(clippy::derivable_impls)]
impl Default for AlertDataVariant {
  fn default() -> Self {
    AlertDataVariant::None
  }
}

/// Severity level of problem.
#[typeshare]
#[derive(
  Serialize,
  Deserialize,
  Debug,
  Clone,
  Copy,
  PartialEq,
  Eq,
  PartialOrd,
  Default,
  Display,
  EnumString,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "UPPERCASE")]
#[strum(serialize_all = "UPPERCASE")]
pub enum SeverityLevel {
  /// No problem.
  ///
  /// Aliases: ok, low, l
  #[default]
  #[strum(serialize = "ok", serialize = "low", serialize = "l")]
  Ok,
  /// Problem is imminent.
  ///
  /// Aliases: warning, w, medium, m
  #[strum(
    serialize = "warning",
    serialize = "w",
    serialize = "medium",
    serialize = "m"
  )]
  Warning,
  /// Problem fully realized.
  ///
  /// Aliases: critical, c, high, h
  #[strum(
    serialize = "critical",
    serialize = "c",
    serialize = "high",
    serialize = "h"
  )]
  Critical,
}