-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
66 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "awstail" | ||
version = "0.3.0" | ||
version = "0.4.0" | ||
authors = ["Yoandy Rodriguez <[email protected]>"] | ||
edition = '2018' | ||
homepage = "https://github.com/yorodm/awstail" | ||
|
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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
use clap::{App, Arg}; | ||
use cmd::run; | ||
use clap::{App, Arg, ArgMatches}; | ||
use ctrlc; | ||
mod cmd; | ||
mod util; | ||
use humantime::parse_duration; | ||
use rusoto_core::Region; | ||
use rusoto_logs::CloudWatchLogsClient; | ||
use std::str::FromStr; | ||
use util::{ | ||
client_with_profile, create_filter_from_timestamp, create_filter_request, fetch_logs, | ||
list_log_groups, AWSResponse, | ||
}; | ||
|
||
fn main() { | ||
ctrlc::set_handler(move || std::process::exit(0)) | ||
.expect("Could not set Ctrl+C handler...bailing out"); | ||
let matches = App::new("awstail") | ||
.version("0.3.0") | ||
fn get_options<'a>() -> ArgMatches<'a> { | ||
return App::new("awstail") | ||
.version("0.4.0") | ||
.author("Yoandy Rodriguez <[email protected]>") | ||
.about("like tail -f for AWS Cloudwatch") | ||
.arg( | ||
|
@@ -56,7 +61,50 @@ fn main() { | |
.help("Keep watching for new logs every n seconds (defaults to 10)"), | ||
) | ||
.get_matches(); | ||
if let Err(_e) = run(matches) { | ||
std::process::exit(0); | ||
} | ||
|
||
fn main() { | ||
ctrlc::set_handler(move || std::process::exit(0)) | ||
.expect("Could not set Ctrl+C handler...bailing out"); | ||
let matches = get_options(); | ||
let region = match matches.value_of("region") { | ||
Some(m) => Region::from_str(m), | ||
None => Ok(Region::UsEast1), | ||
}; | ||
let client = match matches.value_of("profile") { | ||
Some(m) => client_with_profile(m, region.unwrap()), | ||
None => CloudWatchLogsClient::new(region.unwrap()), | ||
}; | ||
if matches.is_present("list") { | ||
list_log_groups(&client).unwrap(); | ||
} else { | ||
let group = matches.value_of("group").unwrap(); | ||
let mtime = match matches.value_of("since") { | ||
Some(m) => parse_duration(m), | ||
None => parse_duration("5m"), | ||
}; | ||
let timeout = match matches.value_of("timeout") { | ||
Some(m) => parse_duration(m), | ||
None => parse_duration("30s"), | ||
}; | ||
let sleep_for = match matches.value_of("watch") { | ||
Some(m) => parse_duration(m), | ||
None => parse_duration("10s"), | ||
}; | ||
let mut token: Option<String> = None; | ||
let mut req = create_filter_request(group, mtime.unwrap(), token); | ||
loop { | ||
match fetch_logs(&client, req, timeout.unwrap()) { | ||
AWSResponse::Token(x) => { | ||
token = Some(x); | ||
req = create_filter_request(group, mtime.unwrap(), token); | ||
} | ||
AWSResponse::LastLog(t) => { | ||
token = None; | ||
req = create_filter_from_timestamp(group, t, token); | ||
std::thread::sleep(sleep_for.unwrap()); | ||
} | ||
}; | ||
} | ||
} | ||
} |
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