7d830c4e3b
displays a preset list of hosts and their response state Updates format of input file to CSV with <host ip>,<host name> as the format. UI now has red/green for down/up hosts duration_to_string now in lib improves display of how long ago change happened log events are now displayed on the monitoring page to show when a host comes up/goes down Modularize ui better Adds ability to return to monitoring or quit from editing page table in place for displaying hosts WIP: start of being able to go up/down through the list of hosts to eventually edit them.
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use std::time::Duration;
|
|
|
|
pub mod manager;
|
|
pub mod ping_request;
|
|
pub mod ping_result;
|
|
pub mod target_state;
|
|
pub mod tui;
|
|
pub mod app_settings;
|
|
|
|
pub const SECONDS_BETWEEN_DISPLAY: u32 = 1;
|
|
pub const SECONDS_BETWEEN_PING: u32 = 2;
|
|
|
|
const SECONDS_IN_MINUTE: u32 = 60;
|
|
const SECONDS_IN_HOUR: u32 = SECONDS_IN_MINUTE * 60;
|
|
const SECONDS_IN_DAY: u32 = SECONDS_IN_HOUR * 24;
|
|
|
|
|
|
pub fn duration_to_string(to_convert: Duration) -> String {
|
|
let mut total_seconds = to_convert.as_secs() as u32;
|
|
let mut working_string = String::new();
|
|
|
|
if total_seconds > 86400 {
|
|
// days
|
|
let num_days = (total_seconds / SECONDS_IN_DAY) as u32;
|
|
working_string = format!("{} days", num_days);
|
|
total_seconds = total_seconds - (num_days * SECONDS_IN_DAY);
|
|
}
|
|
|
|
if total_seconds > 3600 {
|
|
// hours
|
|
let num_hours = (total_seconds / SECONDS_IN_HOUR) as u32;
|
|
if num_hours > 0 {
|
|
working_string = format!("{} {} hours", working_string, num_hours);
|
|
total_seconds = total_seconds - (num_hours * SECONDS_IN_HOUR);
|
|
}
|
|
}
|
|
if total_seconds > 60 {
|
|
let num_minutes = (total_seconds / SECONDS_IN_MINUTE) as u32;
|
|
if num_minutes > 0 {
|
|
working_string = format!("{} {} minutes", working_string, num_minutes);
|
|
total_seconds = total_seconds - (num_minutes * SECONDS_IN_MINUTE);
|
|
}
|
|
// minutes
|
|
}
|
|
|
|
|
|
working_string = format!("{} {} seconds", working_string, total_seconds);
|
|
|
|
working_string
|
|
}
|
|
|