event rcv
This commit is contained in:
14
src/main.rs
14
src/main.rs
@ -1,12 +1,16 @@
|
|||||||
mod typing;
|
mod typing;
|
||||||
|
|
||||||
use axum::{routing::{get, post}, Router, Json};
|
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
|
use axum::{
|
||||||
|
routing::{get, post},
|
||||||
|
Json, Router,
|
||||||
|
};
|
||||||
|
|
||||||
use typing::EventMessage;
|
use typing::EventMessage;
|
||||||
|
|
||||||
|
async fn event_rcv_handle(
|
||||||
async fn event_rcv_handle(Json(form_data): Json<EventMessage>) -> Result<String, (StatusCode, String)> {
|
Json(form_data): Json<EventMessage>,
|
||||||
|
) -> Result<String, (StatusCode, String)> {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
println!("收到告警,向飞书推送消息");
|
println!("收到告警,向飞书推送消息");
|
||||||
reqwest::get(format!("https://www.feishu.cn/flow/api/trigger-webhook/31f13dead0bf78fc4bdb51ba23abba9f?title={}&content={}", &form_data.method, &form_data.params.send_time)).await
|
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));
|
.route("/eventRcv", post(event_rcv_handle));
|
||||||
|
|
||||||
// run our app with hyper, listening globally on port 3000
|
// 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();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,4 @@ pub struct Params {
|
|||||||
pub struct EventMessage {
|
pub struct EventMessage {
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub params: Params,
|
pub params: Params,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user