Skip to content

Commit

Permalink
Merge pull request #466 from jnioche/456
Browse files Browse the repository at this point in the history
Add -summary option to estimate command
  • Loading branch information
demeringo authored Mar 15, 2024
2 parents f63af6d + 7349ccd commit 4823009
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cloud-scanner-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub async fn get_impacts_as_json_string(
api_url: &str,
verbose: bool,
include_block_storage: bool,
summary_only: bool,
) -> Result<String> {
let inventory_with_impacts = estimate_impacts(
use_duration_hours,
Expand All @@ -76,6 +77,18 @@ pub async fn get_impacts_as_json_string(
.await
.context("Cannot perform standard scan")?;

if summary_only {
let usage_location: UsageLocation = UsageLocation::try_from(aws_region)?;
let summary: ImpactsSummary = ImpactsSummary::new(
String::from(aws_region),
usage_location.iso_country_code,
&inventory_with_impacts.clone(),
(*use_duration_hours).into(),
);

return Ok(serde_json::to_string(&summary)?);
}

Ok(serde_json::to_string(&inventory_with_impacts)?)
}

Expand Down Expand Up @@ -125,6 +138,7 @@ pub async fn print_default_impacts_as_json(
api_url: &str,
verbose: bool,
include_storage: bool,
summary_only: bool,
) -> Result<()> {
let j = get_impacts_as_json_string(
use_duration_hours,
Expand All @@ -133,6 +147,7 @@ pub async fn print_default_impacts_as_json(
api_url,
verbose,
include_storage,
summary_only,
)
.await?;
println!("{}", j);
Expand Down
6 changes: 6 additions & 0 deletions cloud-scanner-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ enum SubCommand {
/// Returns results as OpenMetrics (Prometheus) instead of json
#[arg(short = 'm', long)]
as_metrics: bool,

/// Returns only the summary of the impacts as json
#[arg(short = 's', long)]
summary_only: bool,
},
/// List instances and their average cpu load for the last 5 minutes (without returning impacts)
Inventory {
Expand Down Expand Up @@ -103,6 +107,7 @@ async fn main() -> Result<()> {
include_block_storage,
output_verbose_json,
as_metrics,
summary_only,
} => {
if as_metrics {
cloud_scanner_cli::print_default_impacts_as_metrics(
Expand All @@ -121,6 +126,7 @@ async fn main() -> Result<()> {
&api_url,
output_verbose_json,
include_block_storage,
summary_only,
)
.await?
}
Expand Down

0 comments on commit 4823009

Please sign in to comment.