-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PagerDuty alert integration for the case when epoch registr…
…ation fails after maximum retries. (#1367)
- Loading branch information
1 parent
8815582
commit 30dfade
Showing
7 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use reqwest::Client; | ||
use serde::Serialize; | ||
use std::time::Duration; | ||
|
||
#[derive(Debug, Serialize)] | ||
struct PagerDutyPayload { | ||
routing_key: String, | ||
event_action: String, | ||
payload: PagerDutyAlertPayload, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
struct PagerDutyAlertPayload { | ||
summary: String, | ||
severity: String, | ||
source: String, | ||
} | ||
|
||
pub async fn send_pagerduty_alert( | ||
routing_key: &str, | ||
summary: &str, | ||
severity: &str, | ||
source: &str, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let client = Client::builder().timeout(Duration::from_secs(10)).build()?; | ||
|
||
let payload = PagerDutyPayload { | ||
routing_key: routing_key.to_string(), | ||
event_action: "trigger".to_string(), | ||
payload: PagerDutyAlertPayload { | ||
summary: summary.to_string(), | ||
severity: severity.to_string(), | ||
source: source.to_string(), | ||
}, | ||
}; | ||
|
||
let response = client | ||
.post("https://events.pagerduty.com/v2/enqueue") | ||
.json(&payload) | ||
.send() | ||
.await?; | ||
|
||
if !response.status().is_success() { | ||
return Err(format!( | ||
"Failed to send PagerDuty alert. Status: {}, Body: {}", | ||
response.status(), | ||
response.text().await? | ||
) | ||
.into()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.