add apprise_notify format
This commit is contained in:
parent
8e1e6f5e32
commit
887adf5f2c
|
@ -0,0 +1,10 @@
|
||||||
|
use askama::Template;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Template)]
|
||||||
|
#[template(path="apprise_notify.txt", escape="none")]
|
||||||
|
pub struct Notification {
|
||||||
|
pub title: String,
|
||||||
|
pub message: String,
|
||||||
|
pub r#type: String,
|
||||||
|
}
|
17
src/main.rs
17
src/main.rs
|
@ -11,15 +11,18 @@ use serde::Deserialize;
|
||||||
|
|
||||||
mod jabber;
|
mod jabber;
|
||||||
mod prometheus_alert;
|
mod prometheus_alert;
|
||||||
|
mod apprise_notify;
|
||||||
|
|
||||||
enum Payload {
|
enum Payload {
|
||||||
Prometheus(prometheus_alert::Payload),
|
Prometheus(prometheus_alert::Payload),
|
||||||
|
Apprise(apprise_notify::Notification),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Payload {
|
impl Payload {
|
||||||
fn render(&self) -> Result<String, askama::Error> {
|
fn render(&self) -> Result<String, askama::Error> {
|
||||||
match self {
|
match self {
|
||||||
Payload::Prometheus(payload) => payload.render(),
|
Payload::Prometheus(payload) => payload.render(),
|
||||||
|
Payload::Apprise(notification) => notification.render(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +49,7 @@ impl Payload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn alerts(
|
async fn prometheus_alerts(
|
||||||
State(jabber): State<jabber::Handle>,
|
State(jabber): State<jabber::Handle>,
|
||||||
Json(payload): Json<prometheus_alert::Payload>,
|
Json(payload): Json<prometheus_alert::Payload>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
|
@ -55,6 +58,15 @@ async fn alerts(
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn apprise_notification(
|
||||||
|
State(jabber): State<jabber::Handle>,
|
||||||
|
Json(notification): Json<apprise_notify::Notification>,
|
||||||
|
) -> Response {
|
||||||
|
Payload::Apprise(notification)
|
||||||
|
.handle_payload(jabber)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
listen_port: u16,
|
listen_port: u16,
|
||||||
|
@ -78,7 +90,8 @@ async fn main() {
|
||||||
|
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/alert", post(alerts))
|
.route("/alert", post(prometheus_alerts))
|
||||||
|
.route("/notify", post(apprise_notification))
|
||||||
.with_state(jabber);
|
.with_state(jabber);
|
||||||
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], config.listen_port));
|
let addr = SocketAddr::from(([127, 0, 0, 1], config.listen_port));
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[{{ type|upper }}] {{ title }}
|
||||||
|
> {{ message }}
|
Loading…
Reference in New Issue