From 5b32dd95e8199473fcfe862f84d5f65b1d75f15f Mon Sep 17 00:00:00 2001 From: yoloyyh <1764163852@qq.com> Date: Thu, 18 Jul 2024 20:38:08 +0800 Subject: [PATCH] heartbeat report add info field --- rasp/librasp/src/process.rs | 8 ++++++++ rasp/plugin/src/monitor.rs | 5 +++++ rasp/plugin/src/utils.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/rasp/librasp/src/process.rs b/rasp/librasp/src/process.rs index 604d482b2..d40d6c1d4 100644 --- a/rasp/librasp/src/process.rs +++ b/rasp/librasp/src/process.rs @@ -44,6 +44,7 @@ pub struct ProcessInfo { pub start_time: Option, pub try_attach_count: u16, pub attached_count: u16, + pub failed_reason:Option, } #[allow(non_camel_case_types)] @@ -219,6 +220,13 @@ impl ProcessInfo { } Ok(self.namespace_info.clone().unwrap()) } + + pub fn update_failed_reason(&mut self, reason: &String) -> AnyhowResult<()> { + if self.failed_reason.is_none() { + self.failed_reason = Some(reason.clone()); + } + Ok(()) + } pub fn get_mnt_ns(&self) -> AnyhowResult { if let Some(ref ns) = self.namespace_info { return match ns.mnt.clone() { diff --git a/rasp/plugin/src/monitor.rs b/rasp/plugin/src/monitor.rs index bb82117b2..1016872cd 100644 --- a/rasp/plugin/src/monitor.rs +++ b/rasp/plugin/src/monitor.rs @@ -486,6 +486,11 @@ fn internal_main( ) { warn!("operation thread send command to receiver err: {}, pid: {}", e, process.pid); } + let _ = process.update_failed_reason(&e.to_string()); + let mut opp = operation_process_rw.write(); + opp.insert(process.pid, process.clone()); + drop(opp); + continue; } }; diff --git a/rasp/plugin/src/utils.rs b/rasp/plugin/src/utils.rs index 095725d93..9f637e7a5 100644 --- a/rasp/plugin/src/utils.rs +++ b/rasp/plugin/src/utils.rs @@ -47,6 +47,7 @@ pub fn generate_heartbeat(watched_process: &ProcessInfo) -> HashMap<&'static str message.insert("try_attach_count", watched_process.try_attach_count.to_string()); message.insert("attached_count", watched_process.attached_count.to_string()); message.insert("probe_version", RASP_VERSION.to_string()); + message.insert("info", watched_process.failed_reason.clone().unwrap_or("".to_string())); message.insert("uptime", match count_uptime(watched_process.start_time.unwrap_or(0 as f32)) { Ok(t) => t.to_string(), Err(e) => {