mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Added all configuration parameters to nix flake
This commit is contained in:
@@ -16,6 +16,11 @@ in {
|
|||||||
Whether to run the oott service
|
Whether to run the oott service
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
database.path = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
description = "Full path to store the database at";
|
||||||
|
default = "/var/lib/oott.db";
|
||||||
|
};
|
||||||
networking.interface = mkOption {
|
networking.interface = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "Network interface to use for scans";
|
description = "Network interface to use for scans";
|
||||||
@@ -26,6 +31,41 @@ in {
|
|||||||
description = "Log level for the oott service";
|
description = "Log level for the oott service";
|
||||||
default = "info";
|
default = "info";
|
||||||
};
|
};
|
||||||
|
timings.wait_between_scans = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Wait time between scans. This does not include the scan time.";
|
||||||
|
default = "15m";
|
||||||
|
};
|
||||||
|
timings.arp_sender_timeout = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "If the ARP sender process takes longer than this it will be stopped (for a class C network - 254 IPs - it should take less than a minute).";
|
||||||
|
default = "1m";
|
||||||
|
};
|
||||||
|
timings.arp_scan_duration = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "How long to wait for response packets on each scan (5m to 10m is a good timeframe for a class B or C network).";
|
||||||
|
default = "10m";
|
||||||
|
};
|
||||||
|
notifications.method = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "For now just pushover, you can set this to none to avoid sending notifications (it will just log).";
|
||||||
|
default = "pushover";
|
||||||
|
};
|
||||||
|
notifications.notify_when_not_seen_for = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Send a notification if a device comes back online after not being seen for this timeframe.";
|
||||||
|
default = "1w";
|
||||||
|
};
|
||||||
|
notifications.pushover.token = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "Your pushover token goes here, just copy&paste from their website after creating the app.";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
notifications.pushover.user_key = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "User key goes here, this is the account wide code for pushover.";
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Service implementation
|
# Service implementation
|
||||||
@@ -36,11 +76,10 @@ in {
|
|||||||
wantedBy = ["multi-user.target"];
|
wantedBy = ["multi-user.target"];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.oott}/bin/oott ${
|
ExecStart = "${pkgs.oott}/bin/oott --config ${
|
||||||
builtins.toFile "oott.json"
|
builtins.toFile "oott.json"
|
||||||
(generators.toJSON {} cfg)
|
(generators.toJSON {} cfg)
|
||||||
}";
|
}";
|
||||||
# ExecStart = "${pkgs.oott}/bin/oott";
|
|
||||||
ProtectHome = "read-only";
|
ProtectHome = "read-only";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
Type = "exec";
|
Type = "exec";
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
[database]
|
||||||
|
path = "./oott.db" # Database path. Make sure it's writeable for the user running this process
|
||||||
|
|
||||||
[networking]
|
[networking]
|
||||||
interface = "eno1" # Network interface to use for scans
|
interface = "eno1" # Network interface to use for scans
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use rusqlite_migration::Migrations;
|
|||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
use crate::settings;
|
||||||
|
|
||||||
static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/database_migrations");
|
static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/database_migrations");
|
||||||
|
|
||||||
// Define migrations. These are applied atomically.
|
// Define migrations. These are applied atomically.
|
||||||
@@ -14,25 +16,35 @@ static MIGRATIONS: LazyLock<Migrations<'static>> =
|
|||||||
LazyLock::new(|| Migrations::from_directory(&MIGRATIONS_DIR).unwrap());
|
LazyLock::new(|| Migrations::from_directory(&MIGRATIONS_DIR).unwrap());
|
||||||
|
|
||||||
pub fn init_db() -> Result<Connection, String> {
|
pub fn init_db() -> Result<Connection, String> {
|
||||||
debug!("Opening database.");
|
if settings::CONFIG.database.path.is_empty() {
|
||||||
let mut conn = match Connection::open("./oott.db") {
|
error!("Database path not set. Make sure to define database.path in your config file.");
|
||||||
Ok(value) => value,
|
Err(format!(
|
||||||
Err(error) => {
|
"Database path not set. Make sure to define database.path in your config file."
|
||||||
error!("Error opening database (oott.db): {error}");
|
))
|
||||||
return Err(format!("Error opening database (oott.db): {error}"));
|
} else {
|
||||||
}
|
debug!("Opening database at {}.", settings::CONFIG.database.path);
|
||||||
};
|
|
||||||
|
|
||||||
debug!("Database open, executing migrations if needed.");
|
let database_path = settings::CONFIG.database.path.clone();
|
||||||
// Update the database schema, atomically
|
|
||||||
match MIGRATIONS.to_latest(&mut conn) {
|
let mut conn = match Connection::open(database_path) {
|
||||||
Ok(_) => {
|
Ok(value) => value,
|
||||||
debug!("Database up to date.");
|
Err(error) => {
|
||||||
Ok(conn)
|
error!("Error opening database (oott.db): {error}");
|
||||||
}
|
return Err(format!("Error opening database (oott.db): {error}"));
|
||||||
Err(error) => {
|
}
|
||||||
error!("Error updating database: {error}");
|
};
|
||||||
Err(format!("Error updating database: {error}"))
|
|
||||||
|
debug!("Database open, executing migrations if needed.");
|
||||||
|
// Update the database schema, atomically
|
||||||
|
match MIGRATIONS.to_latest(&mut conn) {
|
||||||
|
Ok(_) => {
|
||||||
|
debug!("Database up to date.");
|
||||||
|
Ok(conn)
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
error!("Error updating database: {error}");
|
||||||
|
Err(format!("Error updating database: {error}"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ use serde::Deserialize;
|
|||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Configuration structure
|
// Configuration structure
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
pub struct Database {
|
||||||
|
pub path: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Networking {
|
pub struct Networking {
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
@@ -40,6 +45,7 @@ pub struct Notifications {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
pub database: Database,
|
||||||
pub networking: Networking,
|
pub networking: Networking,
|
||||||
pub log: Log,
|
pub log: Log,
|
||||||
pub timings: Timings,
|
pub timings: Timings,
|
||||||
|
|||||||
Reference in New Issue
Block a user