bigpanda_rs/alert.rs
1use crate::{BigPandaError, Client, POST};
2use hyper::Body;
3use serde::Serialize;
4use std::collections::HashMap;
5
6const ALERT_URL: &str = "https://api.bigpanda.io/data/v2/alerts";
7
8#[derive(Serialize, Debug)]
9#[serde(rename_all = "lowercase")]
10pub enum AlertStatus {
11 Acknowledged,
12 Critical,
13 Ok,
14 Warning,
15}
16
17/// Alert Payload
18/// See https://docs.bigpanda.io/reference#alerts for more details.
19#[derive(Serialize, Debug)]
20pub struct Alert {
21 /// Application key.
22 pub app_key: String,
23
24 /// Status of the alert. One of [ ok, critical, warning, acknowledged ].
25 pub status: AlertStatus,
26
27 /// Main object that caused the alert. Can be the associated host or,
28 /// if a host isn't relevant, a service or an application. If you want to include
29 /// more than one of these fields, consider specifying the primary and secondary properties.
30 pub host: String,
31
32 /// (Optional) Time that the alert occurred in Unix format (UTC timezone).
33 /// If the time is not specified, the value defaults to the current time.
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub timestamp: Option<i64>,
36
37 /// (Optional) Secondary object or sub-item that caused the alert (often shown as an incident subtitle in BigPanda).
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub check: Option<String>,
40
41 /// (Optional) Brief summary (max. 2048 characters) of the alert for certain monitoring tools.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub description: Option<String>,
44
45 /// (Optional) Server cluster or logical host-group from which the alert was sent.
46 /// This value is used to correlate alerts into high-level incidents.
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub cluster: Option<String>,
49
50 /// (Optional) BigPanda uses the primary property to construct the title of an incident.
51 /// By default, the primary property is defined as one of the following fields: host, service, application, or device.
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub primary_property: Option<String>,
54
55 /// (Optional) BigPanda uses the secondary property to construct the subtitle of an incident.
56 /// By default, the secondary property is defined as one of the following fields: check or sensor.
57 #[serde(skip_serializing_if = "Option::is_none")]
58 pub secondary_property: Option<String>,
59
60 ///(Optional) Additional information you want to have available in BigPanda.
61 /// You can add any number of custom JSON attributes with a string value to the payload.
62 #[serde(skip_serializing_if = "Option::is_none")]
63 #[serde(flatten)]
64 pub additional: Option<HashMap<String, String>>,
65}
66
67impl Client {
68 pub async fn send_alert(&self, alert: Alert) -> Result<(), BigPandaError> {
69 self.send_request(
70 POST,
71 ALERT_URL,
72 Body::from(serde_json::to_string(&alert).unwrap()),
73 )
74 .await
75 }
76}