Compare commits

..

No commits in common. '11790783fccef0cc40e5b81dded65776c610aeff' and '3faccc1b999a965b88fbac567fc222243c49eedd' have entirely different histories.

78
Cargo.lock generated

@ -156,7 +156,7 @@ dependencies = [
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
"num-traits", "num-traits",
"time 0.1.45", "time",
"wasm-bindgen", "wasm-bindgen",
"winapi", "winapi",
] ]
@ -224,12 +224,6 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "deranged"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.32" version = "0.8.32"
@ -637,15 +631,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "object" name = "object"
version = "0.31.1" version = "0.31.1"
@ -902,17 +887,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "simplelog"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369"
dependencies = [
"log",
"termcolor",
"time 0.3.27",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.8" version = "0.4.8"
@ -948,11 +922,9 @@ version = "0.1.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",
"log",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
"simplelog",
"toml", "toml",
] ]
@ -986,15 +958,6 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.45" version = "0.1.45"
@ -1006,36 +969,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "time"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bb39ee79a6d8de55f48f2293a830e040392f1c5f16e336bdd1788cd0aadce07"
dependencies = [
"deranged",
"itoa",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"
[[package]]
name = "time-macros"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "733d258752e9303d392b94b75230d07b0b9c489350c69b851fc6c065fde3e8f9"
dependencies = [
"time-core",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.6.0" version = "1.6.0"
@ -1314,15 +1247,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

@ -62,7 +62,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
pname = "status_cloud"; pname = "status_cloud";
version = "0.1.0"; version = "0.1.0";
buildAndTestSubdir = "status_cloud"; buildAndTestSubdir = "status_cloud";
cargoHash = "sha256-mMxHI/rU1Gd5UR+hZ+5+FnBrff8uF+SrEvGJT7wh5tI="; cargoHash = "sha256-Z5JFg9OnCOO9jM/J5T9Tr64x21HOxNf8M4qJKiXiF54=";
meta = meta // { meta = meta // {
description = "Server status saved to a nextcloud note service."; description = "Server status saved to a nextcloud note service.";
}; };
@ -88,12 +88,6 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
The file path to the toml that contains user information secrets The file path to the toml that contains user information secrets
''; '';
}; };
frequency = lib.mkOption {
type = lib.types.int;
description = lib.mdDoc ''
The number of minutes to wait between updates
'';
};
}; };
config.systemd.services.status_cloud = let config.systemd.services.status_cloud = let
cfg = config.services.status_cloud; cfg = config.services.status_cloud;
@ -115,7 +109,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
in lib.mkIf cfg.enable { in lib.mkIf cfg.enable {
wantedBy = [ "timers.target" ]; wantedBy = [ "timers.target" ];
partOf = [ "status_cloud.service" ]; partOf = [ "status_cloud.service" ];
timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ]; timerConfig.OnCalendar = [ "*:0/15" ];
}; };
}; };

@ -8,9 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
chrono = "0.4.26" chrono = "0.4.26"
clap = { version = "4.4.0", features = ["derive"] } clap = { version = "4.4.0", features = ["derive"] }
log = "0.4.20"
reqwest = { version = "0.11.18", features = ["blocking", "json"] } reqwest = { version = "0.11.18", features = ["blocking", "json"] }
serde = { version = "1.0.184", features = ["serde_derive"] } serde = { version = "1.0.184", features = ["serde_derive"] }
serde_json = "1.0.105" serde_json = "1.0.105"
simplelog = "0.12.1"
toml = "0.7.6" toml = "0.7.6"

@ -1,65 +1,71 @@
use clap::Parser;
use log::{debug, error, warn};
use reqwest::blocking::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use reqwest::blocking::Client;
use toml;
use clap::Parser;
use std::process::Command; use std::process::Command;
// TODO: logging
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = CliArgs::parse();
if args.debug { let args = CliArgs::parse();
let _ = simplelog::SimpleLogger::init(
simplelog::LevelFilter::Debug,
simplelog::Config::default(),
);
} else {
let _ = simplelog::SimpleLogger::init(
simplelog::LevelFilter::Info,
simplelog::Config::default(),
);
}
debug!("Opening Config file: {}", args.config_file); println!("Opening Config file: {}", args.config_file);
debug!( println!("File exists: {}", std::fs::metadata(args.config_file.clone()).is_ok());
"Config file exists: {}",
std::fs::metadata(args.config_file.clone()).is_ok()
);
let file_contents = match std::fs::read_to_string(args.config_file) { let file_contents = match std::fs::read_to_string(args.config_file) {
Ok(val) => val, Ok(val) => val,
Err(e) => { Err(e) => {
error!("Could not read config file: {}", e.to_string()); println!("Could not read file: {}", e.to_string());
panic!("{}", e); return Ok(());
} }
}; };
let cfg: Config = match toml::from_str(file_contents.as_str()) { let cfg: Config = match toml::from_str(file_contents.as_str()) {
Ok(val) => val, Ok(val) => val,
Err(e) => { Err(e) => {
error!("Could not parse config file: {}", e.to_string()); println!("Could not parse file: {}", e.to_string());
panic!("{}", e); return Ok(());
} }
}; };
let mut body_content: String = format!( let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S"));
"*Last Updated:* {} \n",
chrono::Local::now().format("%D - %H:%M:%S")
);
let mut drives: Vec<String> = vec![]; let mut drives: Vec<String> = vec![];
match std::fs::read_dir("/dev/") { {
Ok(paths) => { let rust_drives = match std::fs::read_dir("/dev/") {
for path in paths.flatten() { Ok(val) => val,
let tmp = path.path().to_string_lossy().to_string(); Err(e) => {
if tmp.starts_with("/dev/sd") && tmp.len() == 8 { println!("Error opening /dev/: {}", e.to_string());
return Ok(());
}
};
for path in rust_drives {
match path {
Ok(ref val) => {
let tmp = val.path().to_string_lossy().to_string();
if tmp.starts_with("/dev/sd") {
if tmp.len() == 8 {
drives.push(tmp); drives.push(tmp);
} }
} }
},
_ => {}
}
}
} }
match Command::new(args.hddtemp_executable.clone()).output() {
Ok(val) => val,
Err(e) => { Err(e) => {
error!("Error opening /dev/: {}", e.to_string()); println!("Error running hddtemp at all: {}", e.to_string());
panic!("{}", e); println!("hddtemp = {}", args.hddtemp_executable.clone());
return Ok(());
} }
}; };
@ -67,49 +73,46 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut drive_temps: Vec<String> = vec![]; let mut drive_temps: Vec<String> = vec![];
for drive in drives { for drive in drives {
let output = match Command::new(args.hddtemp_executable.clone()) let output = match Command::new(args.hddtemp_executable.clone()).arg(drive.clone()).output() {
.arg("--unit=F") Ok(val) => val,
.arg(drive.clone())
.output()
{
Ok(val) => String::from_utf8_lossy(&val.stdout).into_owned(),
Err(e) => { Err(e) => {
warn!("Error running hddtemp: {}", e.to_string()); println!("Error running hddtemp: {}", e.to_string());
warn!("Drive was: '{}'", drive); println!("Drive was: '{}'", drive);
"".to_string() return Ok(());
} }
}; };
if !output.contains("sensor") { let tmp = match std::str::from_utf8(&output.stdout) {
drive_temps.push(output.replace('\n', "")); Ok(val) => val,
Err(e) => {
println!("Error parsing hddtemp output: {}", e.to_string());
return Ok(());
}
}.to_string();
if !tmp.contains("sensor") {
drive_temps.push(tmp.replace("\n", "Not running as sudo?"));
} else { } else {
drive_temps.push(output[0..9].to_string() + " No Sensor"); drive_temps.push(tmp[0..9].to_string() + " No Sensor");
} }
} }
body_content.push_str("## Hard Drive Temps\n"); body_content.push_str("## Hard Drive Temps\n");
body_content.push_str(drive_temps.join("\n").as_str()); body_content.push_str(drive_temps.join("\n").as_str());
} }
Client::new() Client::new()
.put(format!( .put(format!("https://{}/index.php/apps/notes/api/v1/notes/{}", cfg.server_url.clone(), cfg.note_id.clone()))
"https://{}/index.php/apps/notes/api/v1/notes/{}",
cfg.server_url.clone(),
cfg.note_id.clone()
))
.header("Accept", "application/json") .header("Accept", "application/json")
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone())) .basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
.body( .body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap())
serde_json::to_string(&NoteUpdate {
content: body_content,
})
.unwrap(),
)
.send()?; .send()?;
Ok(()) Ok(())
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Note { struct Note {
id: usize, id: usize,
@ -119,7 +122,7 @@ struct Note {
title: String, title: String,
category: String, category: String,
content: String, content: String,
favorite: bool, favorite: bool
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -132,7 +135,7 @@ struct Config {
user: String, user: String,
pswd: String, pswd: String,
note_id: String, note_id: String,
server_url: String, server_url: String
} }
impl Default for Config { impl Default for Config {
@ -155,7 +158,4 @@ struct CliArgs {
#[arg(short, long)] #[arg(short, long)]
hddtemp_executable: String, hddtemp_executable: String,
#[arg(short, long)]
debug: bool,
} }

Loading…
Cancel
Save