-
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.
This still needs a bit of work before it is ready to go.
- Loading branch information
1 parent
0528456
commit 40c9538
Showing
5 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
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,18 @@ | ||
[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 | ||
|
||
# Disable doc builds by default for our binaries to work around issue | ||
# rust-lang/cargo#8373. These docs would not be very useful anyway. | ||
[[bin]] | ||
name = "oxlog" | ||
doc = false |
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,116 @@ | ||
// 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::{Parser, Subcommand}; | ||
use oxlog::{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, | ||
|
||
/// Print only the current log file | ||
#[arg(short, long)] | ||
current: bool, | ||
|
||
/// Print only the archive 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, | ||
current, | ||
archived, | ||
extra, | ||
} => { | ||
let zones = Zones::load()?; | ||
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); | ||
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 current { | ||
if let Some(current) = &svc_logs.current { | ||
if metadata { | ||
print_metadata(current); | ||
} else { | ||
println!("{}", current.path); | ||
} | ||
} | ||
} | ||
if archived { | ||
for f in &svc_logs.archived { | ||
if metadata { | ||
print_metadata(f); | ||
} else { | ||
println!("{}", f.path); | ||
} | ||
} | ||
} | ||
if extra { | ||
for f in &svc_logs.extra { | ||
if metadata { | ||
print_metadata(f); | ||
} else { | ||
println!("{}", f.path); | ||
} | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} |
Oops, something went wrong.