From 7b046451be8ddf107a01cdbd63dbb43b189ecbdb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 24 Jan 2023 03:12:36 -0800 Subject: [PATCH] actually add the file --- web3_proxy/src/pagerduty.rs | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 web3_proxy/src/pagerduty.rs diff --git a/web3_proxy/src/pagerduty.rs b/web3_proxy/src/pagerduty.rs new file mode 100644 index 00000000..de777c4d --- /dev/null +++ b/web3_proxy/src/pagerduty.rs @@ -0,0 +1,75 @@ +use crate::config::TopConfig; +use gethostname::gethostname; +use pagerduty_rs::types::{AlertTrigger, AlertTriggerPayload}; +use serde::Serialize; +use time::OffsetDateTime; + +pub fn pagerduty_event_for_config( + class: Option, + component: Option, + custom_details: Option, + group: Option, + severity: pagerduty_rs::types::Severity, + summary: String, + timestamp: Option, + top_config: TopConfig, +) -> AlertTrigger { + let chain_id = top_config.app.chain_id; + + let client_url = top_config.app.redirect_public_url.clone(); + + pagerduty_alert( + Some(chain_id), + class, + "web3-proxy".to_string(), + client_url, + component, + custom_details, + group, + severity, + None, + summary, + timestamp, + ) +} + +pub fn pagerduty_alert( + chain_id: Option, + class: Option, + client: String, + client_url: Option, + component: Option, + custom_details: Option, + group: Option, + severity: pagerduty_rs::types::Severity, + source: Option, + summary: String, + timestamp: Option, +) -> AlertTrigger { + let client = chain_id + .map(|x| format!("{} chain #{}", x, client)) + .unwrap_or_else(|| format!("{} w/o chain", client)); + + let source = + source.unwrap_or_else(|| gethostname().into_string().unwrap_or("unknown".to_string())); + + let payload = AlertTriggerPayload { + severity, + summary, + source, + timestamp, + component, + group, + class, + custom_details, + }; + + AlertTrigger { + payload, + dedup_key: None, + images: None, + links: None, + client: Some(client), + client_url: client_url, + } +}