event type string

This commit is contained in:
quantulr
2024-01-19 17:29:12 +08:00
parent 595f9e9670
commit 6a9a732150
3 changed files with 16 additions and 1 deletions

1
Cargo.lock generated
View File

@ -328,6 +328,7 @@ dependencies = [
"axum",
"reqwest",
"serde",
"serde_json",
"tokio",
"tower",
]

View File

@ -11,3 +11,4 @@ reqwest = { version = "0.11.23", features = [] }
tokio = { version = "1.35.1", features = ["full"] }
tower = "0.4.13"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"

View File

@ -3,6 +3,7 @@ use axum::{
routing::{get, post},
Json, Router,
};
use serde_json::Value;
use crate::event_type::get_event_type_map;
use typing::EventMessage;
@ -27,12 +28,24 @@ async fn event_rcv_handle(
Ok(String::from("success"))
}
async fn event_rcv_handle_v2(
Json(form_data): Json<Value>,
) -> Result<String, (StatusCode, String)> {
println!("{}", form_data.to_string());
tokio::spawn(async move {
println!("收到告警,向飞书推送消息");
let _ = reqwest::get(format!("https://www.feishu.cn/flow/api/trigger-webhook/31f13dead0bf78fc4bdb51ba23abba9f?title={}&content={}", "收到告警", "告警内容")).await;
});
Ok(String::from("success"))
}
#[tokio::main]
async fn main() {
// build our application with a single route
let app = Router::new()
.route("/", get(|| async { "Hello, World!" }))
.route("/eventRcv", post(event_rcv_handle));
.route("/eventRcv", post(event_rcv_handle))
.route("/eventRcv2", post(event_rcv_handle_v2));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:13000")