-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb1d11
commit 66afddb
Showing
11 changed files
with
631 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "oxlog" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MPL-2.0" | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
camino.workspace = true | ||
chrono.workspace = true | ||
clap.workspace = true | ||
uuid.workspace = true | ||
omicron-workspace-hack.workspace = true | ||
|
||
[[bin]] | ||
name = "oxlog" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Tool for discovering oxide related logfiles on sleds | ||
use clap::{Args, Parser, Subcommand}; | ||
use oxlog::{Filter, LogFile, Zones}; | ||
|
||
#[derive(Debug, Parser)] | ||
#[command(version)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Commands { | ||
/// List all zones found on the filesystem | ||
Zones, | ||
|
||
/// List logs for a given service | ||
Logs { | ||
// The name of the zone | ||
zone: String, | ||
|
||
/// The name of the service to list logs for | ||
service: Option<String>, | ||
|
||
/// Print available metadata | ||
#[arg(short, long)] | ||
metadata: bool, | ||
|
||
#[command(flatten)] | ||
filter: FilterArgs, | ||
}, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
#[group(required = true, multiple = true)] | ||
struct FilterArgs { | ||
/// Print only the current log file | ||
#[arg(short, long)] | ||
current: bool, | ||
|
||
/// Print only the archived log files | ||
#[arg(short, long)] | ||
archived: bool, | ||
|
||
// Print only the extra log files | ||
#[arg(short, long)] | ||
extra: bool, | ||
} | ||
|
||
fn main() -> Result<(), anyhow::Error> { | ||
let cli = Cli::parse(); | ||
|
||
match cli.command { | ||
Commands::Zones => { | ||
for zone in Zones::load()?.zones.keys() { | ||
println!("{zone}"); | ||
} | ||
Ok(()) | ||
} | ||
Commands::Logs { zone, service, metadata, filter } => { | ||
let zones = Zones::load()?; | ||
let filter = Filter { | ||
current: filter.current, | ||
archived: filter.archived, | ||
extra: filter.extra, | ||
}; | ||
let print_metadata = |f: &LogFile| { | ||
println!( | ||
"{}\t{}\t{}", | ||
f.path, | ||
f.size.map_or_else(|| "-".to_string(), |s| s.to_string()), | ||
f.modified | ||
.map_or_else(|| "-".to_string(), |s| s.to_rfc3339()) | ||
); | ||
}; | ||
|
||
let logs = zones.zone_logs(&zone, filter); | ||
for (svc_name, mut svc_logs) in logs { | ||
if let Some(service) = &service { | ||
if svc_name != service.as_str() { | ||
continue; | ||
} | ||
} | ||
svc_logs.archived.sort(); | ||
if filter.current { | ||
if let Some(current) = &svc_logs.current { | ||
if metadata { | ||
print_metadata(current); | ||
} else { | ||
println!("{}", current.path); | ||
} | ||
} | ||
} | ||
if filter.archived { | ||
for f in &svc_logs.archived { | ||
if metadata { | ||
print_metadata(f); | ||
} else { | ||
println!("{}", f.path); | ||
} | ||
} | ||
} | ||
if filter.extra { | ||
for f in &svc_logs.extra { | ||
if metadata { | ||
print_metadata(f); | ||
} else { | ||
println!("{}", f.path); | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} |
Oops, something went wrong.