From 9b656a13e6e5308d2ebef23e0b259e106be3a70e Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Tue, 18 Jul 2023 18:41:53 +0000 Subject: [PATCH] add container log search via | grep --- bin/periphery/src/helpers/docker/container.rs | 5 +++++ bin/periphery/src/requests/container.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bin/periphery/src/helpers/docker/container.rs b/bin/periphery/src/helpers/docker/container.rs index 80f413a5a..1bb90ba11 100644 --- a/bin/periphery/src/helpers/docker/container.rs +++ b/bin/periphery/src/helpers/docker/container.rs @@ -23,6 +23,11 @@ pub async fn container_log(container_name: &str, tail: u64) -> Log { run_monitor_command("get container log", command).await } +pub async fn container_log_search(container_name: &str, search: &str) -> Log { + let command = format!("docker logs {container_name} | grep {search}"); + run_monitor_command("get container log grep", command).await +} + pub async fn container_stats( container_name: Option, ) -> anyhow::Result> { diff --git a/bin/periphery/src/requests/container.rs b/bin/periphery/src/requests/container.rs index e62c94a7d..77f1b22bb 100644 --- a/bin/periphery/src/requests/container.rs +++ b/bin/periphery/src/requests/container.rs @@ -47,6 +47,22 @@ impl Resolve for State { // +#[derive(Serialize, Deserialize, Debug, Clone, Request)] +#[response(Log)] +pub struct GetContainerLogSearch { + pub name: String, + pub search: String, +} + +#[async_trait::async_trait] +impl Resolve for State { + async fn resolve(&self, req: GetContainerLogSearch, _: ()) -> anyhow::Result { + Ok(docker::container_log_search(&req.name, &req.search).await) + } +} + +// + #[derive(Serialize, Deserialize, Debug, Clone, Request)] #[response(DockerContainerStats)] pub struct GetContainerStats {