pagerduty-api 0.1.0

An API client for the Pagerduty API
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
//! Types for our Pagerduty API client.

use chrono::{DateTime, Utc};
use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// A list of services.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ServiceListResponse {
    /// The list of services.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub services: Vec<Service>,
    /// Echoes limit pagination property.
    #[serde(default)]
    pub limit: i64,
    /// Echoes offset pagination property.
    #[serde(default)]
    pub offset: i64,
    /// Indicates if there are additional records to return.
    #[serde(default)]
    pub more: bool,
}

/// A service object.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ServiceObject {
    /// The service.
    #[serde(default)]
    pub service: Service,
}

/// A service.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Service {
    /// The ID.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub id: String,
    /// The name of the service.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub name: String,
    /// The description of the service.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub description: String,
    /// Time in seconds that an incident is automatically resolved if left open for that long. Value is null if the feature is disabled. Value must not be negative. Setting this field to 0, null (or unset in POST request) will disable the feature.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub auto_resolve_timeout: Option<i64>,
    /// Time in seconds that an incident changes to the Triggered State after being Acknowledged. Value is null if the feature is disabled. Value must not be negative. Setting this field to 0, null (or unset in POST request) will disable the feature.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub acknowledgement_timeout: Option<i64>,
    /// The current state of the Service. Valid statuses are:
    ///
    /// - `active`: The service is enabled and has no open incidents. This is the only status a service can be created with.
    /// - `warning`: The service is enabled and has one or more acknowledged incidents.
    /// - `critical`: The service is enabled and has one or more triggered incidents.
    /// - `maintenance`: The service is under maintenance, no new incidents will be triggered during maintenance mode.
    /// - `disabled`: The service is disabled and will not have any new triggered incidents.
    #[serde(default)]
    pub status: Status,
    /// Escalation policy.
    #[serde(default)]
    pub escalation_policy: EscalationPolicy,
    /// Incident urgency rule.
    #[serde(default)]
    pub incident_urgency_rule: IncidentUrgencyRule,
    /// Support Hours.
    #[serde(default)]
    pub support_hours: Option<SupportHours>,
    /// An array containing scheduled actions for the service.
    #[serde(default)]
    pub scheduled_actions: Vec<ScheduledAction>,
    /// Whether a service creates only incidents, or both alerts and incidents. A service must create alerts in order to enable incident merging.
    ///
    /// - `create_incidents` - The service will create one incident and zero alerts for each incoming event.
    /// - `create_alerts_and_incidents` - The service will create one incident and one associated alert for each incoming event.
    #[serde(default)]
    pub alert_creation: AlertCreation,
    /// Defines how alerts on this service will be automatically grouped into incidents. Note that the alert grouping features are available only on certain plans.
    #[serde(default)]
    pub alert_grouping_parameters: AlertGroupingParameters,
    /// Defines how alerts on this service are automatically suspended for a period of time before triggering, when identified as likely being transient. Note that automatically pausing notifications is only available on certain plans.
    #[serde(default)]
    pub auto_pause_notifications_parameters: AutoPauseNotificationsParameters,

    /// An API link to itself.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize",
        rename = "self"
    )]
    pub self_: String,
    /// An HTML link to itself.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub html_url: String,
    /// The date/time when this service was created.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub created_at: Option<DateTime<Utc>>,
    /// The date/time when the most recent incident was created for this service.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_incident_timestamp: Option<DateTime<Utc>>,
}

/// The state of the service.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum Status {
    /// Active.
    Active,
    /// Warning.
    Warning,
    /// Critical.
    Critical,
    /// Maintenance.
    Maintenance,
    /// Disabled.
    Disabled,
}

impl Default for Status {
    fn default() -> Self {
        Status::Active
    }
}

/// How a service creates incidents.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum AlertCreation {
    /// Create incidents.
    CreateIncidents,
    /// Create alerts and incidents.
    CreateAlertsAndIncidents,
}

impl Default for AlertCreation {
    fn default() -> Self {
        AlertCreation::CreateAlertsAndIncidents
    }
}

/// An escalation policy.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct EscalationPolicy {
    /// The ID.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub id: String,
    /// The type.
    #[serde(default, skip_serializing_if = "Option::is_none", rename = "type")]
    pub type_: Option<EscalationPolicyType>,
    /// The summary.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub summary: String,
    /// The name.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub name: String,
    /// The description.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub description: String,
    /// An API link to itself.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize",
        rename = "self"
    )]
    pub self_: String,
    /// An HTML link to itself.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub html_url: String,
}

/// The type of escalation_policy.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum EscalationPolicyType {
    /// A reference to an escalation policy.
    EscalationPolicyReference,
    /// An escalation policy object.
    EscalationPolicy,
}

impl Default for EscalationPolicyType {
    fn default() -> Self {
        EscalationPolicyType::EscalationPolicyReference
    }
}

/// An incident urgency rule.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct IncidentUrgencyRule {
    /// The type.
    #[serde(default, rename = "type")]
    pub type_: IncidentUrgencyRuleType,
    /// The urgency.
    #[serde(default)]
    pub urgency: Option<Urgency>,
    /// The rule to use during support hours.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub during_support_hours: Option<Box<IncidentUrgencyRule>>,
    /// The rule to use outside support hours.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub outside_support_hours: Option<Box<IncidentUrgencyRule>>,
}

impl Default for IncidentUrgencyRule {
    fn default() -> Self {
        IncidentUrgencyRule {
            type_: IncidentUrgencyRuleType::Constant,
            urgency: Some(Urgency::High),
            during_support_hours: None,
            outside_support_hours: None,
        }
    }
}

/// The type of incident urgency rule.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum IncidentUrgencyRuleType {
    /// Constant.
    Constant,
    /// Use support hours.
    UseSupportHours,
}

impl Default for IncidentUrgencyRuleType {
    fn default() -> Self {
        IncidentUrgencyRuleType::Constant
    }
}

/// The incidents' urgency, if type is constant.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum Urgency {
    /// Low.
    Low,
    /// High.
    High,
    /// Severity based.
    SeverityBased,
}

impl Default for Urgency {
    fn default() -> Self {
        Urgency::High
    }
}

/// The support hours.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct SupportHours {
    /// The type.
    #[serde(default, rename = "type")]
    pub type_: SupportHoursType,
    /// The time zone for the support hours.
    #[serde(
        default,
        skip_serializing_if = "String::is_empty",
        deserialize_with = "deserialize_null_string::deserialize"
    )]
    pub time_zone: String,
    /// The support hours' starting time of day (date portion is ignored).
    #[serde(
        deserialize_with = "serde_naive_time::deserialize",
        serialize_with = "serde_naive_time::serialize"
    )]
    pub start_time: chrono::NaiveTime,
    /// The support hours' ending time of day (date portion is ignored).
    #[serde(
        deserialize_with = "serde_naive_time::deserialize",
        serialize_with = "serde_naive_time::serialize"
    )]
    pub end_time: chrono::NaiveTime,
    /// The days of the week.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub days_of_week: Vec<i32>,
}

/// The type of support hours.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum SupportHoursType {
    /// Fixed time per day.
    FixedTimePerDay,
}

impl Default for SupportHoursType {
    fn default() -> Self {
        SupportHoursType::FixedTimePerDay
    }
}

/// A scheduled action.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ScheduledAction {
    /// The type.
    #[serde(default, rename = "type")]
    pub type_: ScheduledActionType,
    /// Represents when scheduled action will occur.
    #[serde(default)]
    pub at: ScheduledActionAt,
    /// Urgency level. Must be set to high.
    #[serde(default)]
    pub to_urgency: Urgency,
}

/// The type of scheduled action.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum ScheduledActionType {
    /// Urgency change.
    UrgencyChange,
}

impl Default for ScheduledActionType {
    fn default() -> Self {
        ScheduledActionType::UrgencyChange
    }
}

/// Represents when scheduled action will occur.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ScheduledActionAt {
    /// The type.
    #[serde(default, rename = "type")]
    pub type_: ScheduledActionAtType,
    /// Designates either the start or the end of support hours.
    #[serde(default)]
    pub name: ScheduledActionAtName,
}

/// The type of scheduled action at.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum ScheduledActionAtType {
    /// Named time.
    NamedTime,
}

impl Default for ScheduledActionAtType {
    fn default() -> Self {
        ScheduledActionAtType::NamedTime
    }
}

/// Designates either the start or the end of support hours.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum ScheduledActionAtName {
    /// Support hours start.
    SupportHoursStart,
    /// Support hours end.
    SupportHoursEnd,
}

impl Default for ScheduledActionAtName {
    fn default() -> Self {
        ScheduledActionAtName::SupportHoursStart
    }
}

/// Defines how alerts on this service will be automatically grouped into incidents. Note that the alert grouping features are available only on certain plans.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct AlertGroupingParameters {
    /// The type.
    #[serde(default, rename = "type")]
    pub type_: Option<AlertGroupingType>,
}

/// The type of alert grouping.
#[derive(Display, FromStr, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone)]
#[display(style = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum AlertGroupingType {
    /// Time.
    Time,
    /// Intelligent.
    Intelligent,
    /// Content based.
    ContentBased,
}

impl Default for AlertGroupingType {
    fn default() -> Self {
        AlertGroupingType::Intelligent
    }
}

/// Defines how alerts on this service are automatically suspended for a period of time before triggering, when identified as likely being transient. Note that automatically pausing notifications is only available on certain plans.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct AutoPauseNotificationsParameters {
    /// Indicates whether alerts should be automatically suspended when identified as transient.
    #[serde(default)]
    pub enabled: bool,
    /// Indicates in seconds how long alerts should be suspended before triggering.
    /// Allowed values: 120, 180, 300, 600, 900
    #[serde(default)]
    pub timeout: Option<i64>,
}

/// A list of escalation policies.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct EscalationPolicyListResponse {
    /// The list of services.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub escalation_policies: Vec<EscalationPolicy>,
    /// Echoes limit pagination property.
    #[serde(default)]
    pub limit: i64,
    /// Echoes offset pagination property.
    #[serde(default)]
    pub offset: i64,
    /// Indicates if there are additional records to return.
    #[serde(default)]
    pub more: bool,
}

/// A module for deserializing a null string.
pub mod deserialize_null_string {
    use serde::Deserialize;

    /// Deserialize a null string as an empty string.
    pub fn deserialize<'de, D>(deserializer: D) -> Result<String, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer).unwrap_or_default();

        Ok(s)
    }
}

/// A module for deserializing a null string.
pub mod serde_naive_time {
    use chrono::NaiveTime;
    use serde::{Deserialize, Serializer};

    /// Deserialize a time to the right format.
    pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveTime, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = NaiveTime::deserialize(deserializer)?;

        Ok(s)
    }

    /// Serialize a time to the right format.
    pub fn serialize<S>(time: &NaiveTime, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let s = format!("{}", time.format("%H:%M:%S"));
        serializer.serialize_str(&s)
    }
}