add container log search via | grep

This commit is contained in:
mbecker20
2023-07-18 18:41:53 +00:00
parent e95fe8f410
commit 9b656a13e6
2 changed files with 21 additions and 0 deletions

View File

@@ -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<String>,
) -> anyhow::Result<Vec<DockerContainerStats>> {

View File

@@ -47,6 +47,22 @@ impl Resolve<GetContainerLog> 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<GetContainerLogSearch> for State {
async fn resolve(&self, req: GetContainerLogSearch, _: ()) -> anyhow::Result<Log> {
Ok(docker::container_log_search(&req.name, &req.search).await)
}
}
//
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
#[response(DockerContainerStats)]
pub struct GetContainerStats {