1
0
mirror of https://github.com/pcvolkmer/checkbar.git synced 2025-04-19 19:16:50 +00:00

Add optional config file argument

This commit is contained in:
Paul-Christian Volkmer 2022-04-07 10:19:37 +02:00
parent a893d7a6f0
commit 16b68bdaca
2 changed files with 15 additions and 5 deletions

View File

@ -33,6 +33,12 @@ You can optionally specify `check_type`:
* `Html`: Default value, checks if a request is succeessful and returns HTTP OK - 200. * `Html`: Default value, checks if a request is succeessful and returns HTTP OK - 200.
* `Actuator`: Like `Html`, but checks if _Actuator_ shows that the application is up and running. * `Actuator`: Like `Html`, but checks if _Actuator_ shows that the application is up and running.
To use more than one configuration, pass the config file location as first argument to the application.
----
$ checkbar /etc/checkbar_example.toml
----
=== Colors === Colors
To change the colors, use the following configuration. As an example the colors of the default configuration are shown. To change the colors, use the following configuration. As an example the colors of the default configuration are shown.

View File

@ -1,5 +1,6 @@
use serde::Deserialize; use serde::Deserialize;
use std::fmt::{Display, Formatter, Result}; use std::fmt::{Display, Formatter, Result};
use std::env;
use std::fs; use std::fs;
use std::process; use std::process;
use std::time::Duration; use std::time::Duration;
@ -122,12 +123,15 @@ async fn print_states(check_configs: &[CheckConfig]) {
println!("{}],", entries.join(",")); println!("{}],", entries.join(","));
} }
fn get_config_file() -> String {
match env::args().nth(1) {
Some(config_file) => config_file,
None => format!("{}/.checkbar.toml", dirs::home_dir().unwrap().to_str().unwrap_or(""))
}
}
fn get_config() -> Config { fn get_config() -> Config {
let home_dir = dirs::home_dir().unwrap(); match fs::read_to_string(get_config_file()) {
match fs::read_to_string(format!(
"{}/.checkbar.toml",
home_dir.to_str().unwrap_or("")
)) {
Ok(config) => match toml::from_str(config.as_str()) { Ok(config) => match toml::from_str(config.as_str()) {
Ok(config) => config, Ok(config) => config,
Err(_e) => Config { Err(_e) => Config {