nouvelle version
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use axum::{
|
||||
body::Bytes,
|
||||
extract::{Form, State},
|
||||
response::{IntoResponse, Redirect},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use tower_sessions::Session;
|
||||
use form_urlencoded;
|
||||
|
||||
use crate::routes::{flash, get_and_clear_flash, render_html, AppState, AuthUser};
|
||||
|
||||
@@ -179,32 +181,30 @@ pub async fn test_smtp(
|
||||
Redirect::to("/settings")
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ProcessesForm {
|
||||
#[serde(rename = "proc_name[]")]
|
||||
pub proc_name: Option<Vec<String>>,
|
||||
#[serde(rename = "proc_pattern[]")]
|
||||
pub proc_pattern: Option<Vec<String>>,
|
||||
#[serde(rename = "proc_mem_threshold[]")]
|
||||
pub proc_mem_threshold: Option<Vec<String>>,
|
||||
#[serde(rename = "proc_enabled[]")]
|
||||
pub proc_enabled: Option<Vec<String>>,
|
||||
#[serde(rename = "proc_alert_down[]")]
|
||||
pub proc_alert_down: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
pub async fn update_processes(
|
||||
_auth: AuthUser,
|
||||
session: Session,
|
||||
State(state): State<AppState>,
|
||||
Form(form): Form<ProcessesForm>,
|
||||
body: Bytes,
|
||||
) -> impl IntoResponse {
|
||||
use crate::config::ProcessConfig;
|
||||
let names = form.proc_name.unwrap_or_default();
|
||||
let patterns = form.proc_pattern.unwrap_or_default();
|
||||
let mem_thresholds = form.proc_mem_threshold.unwrap_or_default();
|
||||
let enableds = form.proc_enabled.unwrap_or_default();
|
||||
let alert_downs = form.proc_alert_down.unwrap_or_default();
|
||||
|
||||
let mut names: Vec<String> = Vec::new();
|
||||
let mut patterns: Vec<String> = Vec::new();
|
||||
let mut mem_thresholds: Vec<String> = Vec::new();
|
||||
let mut enableds: Vec<String> = Vec::new();
|
||||
let mut alert_downs: Vec<String> = Vec::new();
|
||||
|
||||
for (key, value) in form_urlencoded::parse(body.as_ref()) {
|
||||
match key.as_ref() {
|
||||
"proc_name[]" => names.push(value.into_owned()),
|
||||
"proc_pattern[]" => patterns.push(value.into_owned()),
|
||||
"proc_mem_threshold[]" => mem_thresholds.push(value.into_owned()),
|
||||
"proc_enabled[]" => enableds.push(value.into_owned()),
|
||||
"proc_alert_down[]" => alert_downs.push(value.into_owned()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let mut processes = Vec::new();
|
||||
for (i, name) in names.iter().enumerate() {
|
||||
|
||||
Reference in New Issue
Block a user