event rcv

This commit is contained in:
quantulr
2024-01-18 16:49:18 +08:00
parent c1cd8b348a
commit 1b62a3f33e
2 changed files with 11 additions and 5 deletions

View File

@ -1,12 +1,16 @@
mod typing;
use axum::{routing::{get, post}, Router, Json};
use axum::http::StatusCode;
use axum::{
routing::{get, post},
Json, Router,
};
use typing::EventMessage;
async fn event_rcv_handle(Json(form_data): Json<EventMessage>) -> Result<String, (StatusCode, String)> {
async fn event_rcv_handle(
Json(form_data): Json<EventMessage>,
) -> Result<String, (StatusCode, String)> {
tokio::spawn(async move {
println!("收到告警,向飞书推送消息");
reqwest::get(format!("https://www.feishu.cn/flow/api/trigger-webhook/31f13dead0bf78fc4bdb51ba23abba9f?title={}&content={}", &form_data.method, &form_data.params.send_time)).await
@ -22,6 +26,8 @@ async fn main() {
.route("/eventRcv", post(event_rcv_handle));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:13000")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}