pscand-cli: error when there are no scanners configured
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Id4e5a2ffc70efb10ba37c0b203a0ac166a6a6964
This commit is contained in:
parent
16672b2ff1
commit
5850f342a1
2 changed files with 39 additions and 12 deletions
|
|
@ -42,12 +42,8 @@ interval_secs = 30 # Battery status changes slowly
|
||||||
enabled = true
|
enabled = true
|
||||||
interval_secs = 5
|
interval_secs = 5
|
||||||
|
|
||||||
# Example: Disable a scanner
|
|
||||||
[scanners.system]
|
|
||||||
enabled = false
|
|
||||||
|
|
||||||
# Example: Custom scanner with extra parameters
|
# Example: Custom scanner with extra parameters
|
||||||
[scanners.custom]
|
# [scanners.custom]
|
||||||
enabled = true
|
# enabled = true
|
||||||
interval_secs = 60
|
# interval_secs = 60
|
||||||
extra = { custom_param = "value", threshold = 100 }
|
# extra = { custom_param = "value", threshold = 100 }
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ enum Args {
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct RunArgs {
|
struct RunArgs {
|
||||||
#[arg(short, long, default_value = "/etc/pscand/pscand.toml")]
|
#[arg(short, long, default_value = "~/.config/pscand/pscand.toml")]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
|
@ -179,7 +179,16 @@ async fn run_daemon(args: RunArgs) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let config = if args.config.exists() {
|
let config = if args.config.exists() {
|
||||||
CoreConfig::load(&args.config)?
|
CoreConfig::load(&args.config)?
|
||||||
} else {
|
} else {
|
||||||
log::warn!("Config file not found, using defaults");
|
log::warn!("Config file not found at {:?}", args.config);
|
||||||
|
log::info!("Creating default config. Run with --config to specify a different path.");
|
||||||
|
|
||||||
|
// Create default config directory if it doesn't exist
|
||||||
|
if let Some(parent) = args.config.parent() {
|
||||||
|
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||||
|
log::warn!("Failed to create config directory: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CoreConfig::default()
|
CoreConfig::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -256,8 +265,18 @@ async fn run_daemon(args: RunArgs) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let scanners = load_scanners(&config, &logger).await?;
|
let scanners = load_scanners(&config, &logger).await?;
|
||||||
|
|
||||||
if scanners.is_empty() {
|
if scanners.is_empty() {
|
||||||
log::warn!("No scanners loaded!");
|
log::error!("No scanners loaded!");
|
||||||
logger.log(LogLevel::Warn, "daemon", "no_scanners", "{}".to_string());
|
log::error!("Please ensure:");
|
||||||
|
log::error!(" 1. Scanner plugins are installed in one of the configured directories");
|
||||||
|
log::error!(" 2. Scanner directories are correctly set in config file or PSCAND_SCANNER_DIRS env var");
|
||||||
|
log::error!(" 3. Scanners are not disabled in the configuration");
|
||||||
|
logger.log(
|
||||||
|
LogLevel::Error,
|
||||||
|
"daemon",
|
||||||
|
"no_scanners",
|
||||||
|
"No scanner plugins loaded".to_string(),
|
||||||
|
);
|
||||||
|
return Err("No scanners loaded. See error messages above.".into());
|
||||||
} else {
|
} else {
|
||||||
log::info!("Loaded {} scanners", scanners.len());
|
log::info!("Loaded {} scanners", scanners.len());
|
||||||
logger.log(
|
logger.log(
|
||||||
|
|
@ -423,8 +442,12 @@ async fn load_scanners(
|
||||||
) -> Result<Vec<LoadedScanner>, Box<dyn std::error::Error>> {
|
) -> Result<Vec<LoadedScanner>, Box<dyn std::error::Error>> {
|
||||||
let mut loaded = Vec::new();
|
let mut loaded = Vec::new();
|
||||||
|
|
||||||
|
let mut missing_dirs = Vec::new();
|
||||||
|
|
||||||
for dir in &config.scanner_dirs {
|
for dir in &config.scanner_dirs {
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
|
missing_dirs.push(dir.clone());
|
||||||
|
log::warn!("Scanner directory does not exist: {:?}", dir);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -521,6 +544,14 @@ async fn load_scanners(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !missing_dirs.is_empty() {
|
||||||
|
log::warn!("The following scanner directories do not exist:");
|
||||||
|
for dir in &missing_dirs {
|
||||||
|
log::warn!(" - {:?}", dir);
|
||||||
|
}
|
||||||
|
log::info!("Create these directories or update scanner_dirs in config");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(loaded)
|
Ok(loaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue