add webhook
This commit is contained in:
parent
6b16402126
commit
a91d8eebf4
5 changed files with 56 additions and 3 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -282,7 +282,7 @@ version = "0.2.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi",
|
"hermit-abi 0.1.19",
|
||||||
"libc",
|
"libc",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
@ -601,6 +601,12 @@ version = "0.3.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.28"
|
version = "0.3.28"
|
||||||
|
@ -620,9 +626,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -692,6 +701,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
|
@ -1021,6 +1036,16 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi 0.3.9",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.32.1"
|
version = "0.32.1"
|
||||||
|
@ -1559,6 +1584,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
|
"num_cpus",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
|
|
|
@ -15,7 +15,7 @@ gnupg-rs = "0.1.0"
|
||||||
web-base = "0.2"
|
web-base = "0.2"
|
||||||
serde = {version = "1.0.147", features = ["derive"] }
|
serde = {version = "1.0.147", features = ["derive"] }
|
||||||
serde_json = "1.0.87"
|
serde_json = "1.0.87"
|
||||||
reqwest = "0.11"
|
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
||||||
maud = "0.24.0"
|
maud = "0.24.0"
|
||||||
tokio = { version = "1", features = ["sync"] }
|
tokio = { version = "1", features = ["sync"] }
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
- `secret_key` : Secret Key for Flask
|
- `secret_key` : Secret Key for Flask
|
||||||
- `xmr_address` : Monero Receive Address
|
- `xmr_address` : Monero Receive Address
|
||||||
- `notify` : Notification Object
|
- `notify` : Notification Object
|
||||||
|
- - `webhook`: Webhook Notification
|
||||||
- - `gotify`: Gotify Object
|
- - `gotify`: Gotify Object
|
||||||
- - - `token` : Gotify Token
|
- - - `token` : Gotify Token
|
||||||
- - - `host` : Gotify Host/Domain name
|
- - - `host` : Gotify Host/Domain name
|
||||||
|
|
|
@ -77,4 +77,14 @@ impl Config {
|
||||||
let token = settings.get("token")?.as_str()?.to_string();
|
let token = settings.get("token")?.as_str()?.to_string();
|
||||||
Some(GotifySettings { host, token })
|
Some(GotifySettings { host, token })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn webhook_config(&self) -> Option<String> {
|
||||||
|
Some(
|
||||||
|
self.root
|
||||||
|
.get("notify")?
|
||||||
|
.get("webhook")?
|
||||||
|
.as_str()?
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,28 @@
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::{self, Data};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
pub async fn notify(msg: &str, title: &str, config: Data<Config>) {
|
pub async fn notify(msg: &str, title: &str, config: Data<Config>) {
|
||||||
if let Some(gotify) = config.gotify_config() {
|
if let Some(gotify) = config.gotify_config() {
|
||||||
gotify_notification(msg, title, gotify).await;
|
gotify_notification(msg, title, gotify).await;
|
||||||
}
|
}
|
||||||
|
if let Some(webhook) = config.webhook_config() {
|
||||||
|
info!("Sending webhook notification");
|
||||||
|
let request =
|
||||||
|
serde_json::json!({
|
||||||
|
"instance": config.name(),
|
||||||
|
"title": title,
|
||||||
|
"msg": msg
|
||||||
|
});
|
||||||
|
|
||||||
|
let client = reqwest::blocking::Client::new();
|
||||||
|
client
|
||||||
|
.post(webhook)
|
||||||
|
.json(&request)
|
||||||
|
.send()
|
||||||
|
.expect("Failed to send webhook request");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn gotify_notification(msg: &str, title: &str, config: config::GotifySettings) {
|
async fn gotify_notification(msg: &str, title: &str, config: config::GotifySettings) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue