Compare commits
3 Commits
f63eb19b08
...
v0.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aba5c74a9 | ||
|
|
851d71ce7f | ||
|
|
0ab64f3e7e |
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rsnmpagent"
|
||||
version = "0.3.0"
|
||||
version = "0.4.1"
|
||||
edition = "2024"
|
||||
|
||||
[profile.release]
|
||||
|
||||
10
config.yml
10
config.yml
@@ -8,4 +8,12 @@ intervals:
|
||||
processes: 60
|
||||
meminfo: 60
|
||||
bonding:
|
||||
multipath:
|
||||
multipath:
|
||||
extra_config:
|
||||
filesum:
|
||||
passwd:
|
||||
shadow:
|
||||
group:
|
||||
authorized_keys:
|
||||
multipath:
|
||||
bonding:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use diff::Result;
|
||||
use hex;
|
||||
use log::{debug, trace};
|
||||
use log::{info, trace};
|
||||
use sha3::{Digest, Sha3_256};
|
||||
use std::fs;
|
||||
use std::io::{self, Error};
|
||||
@@ -14,8 +14,8 @@ pub(crate) fn filesum_filtered(
|
||||
) -> io::Result<(bool, String)> {
|
||||
// Open file for hashing
|
||||
match re {
|
||||
Some(v) => debug!("try to open file {:?} for hashing using filter regex {}", path, v),
|
||||
None => debug!("try to open file {:?} for hashing", path),
|
||||
Some(v) => trace!("try to open file {:?} for hashing using filter regex {}", path, v),
|
||||
None => trace!("try to open file {:?} for hashing", path),
|
||||
}
|
||||
let mut hasher = Sha3_256::new();
|
||||
let mut filedata = String::with_capacity(2048);
|
||||
@@ -24,7 +24,7 @@ pub(crate) fn filesum_filtered(
|
||||
// we read only smal files, so its fast to read the whole file to memory, so we can also du a diff
|
||||
if let Ok(file_contents) = fs::read_to_string(path) {
|
||||
if let Some(re) = re {
|
||||
debug!("Filter lines with regex {:?}", re);
|
||||
trace!("Filter lines with regex {:?}", re);
|
||||
for line in file_contents.lines() {
|
||||
if re.is_match(line) {
|
||||
trace!("line {} skipped by filter regex", line);
|
||||
@@ -35,7 +35,7 @@ pub(crate) fn filesum_filtered(
|
||||
}
|
||||
} else {
|
||||
// we do not have a filter regex, so we could simply paste the file to the hasher
|
||||
debug!("Hash file without filter regex");
|
||||
trace!("Hash file without filter regex");
|
||||
filedata = file_contents;
|
||||
}
|
||||
hasher.update(format!("{}\n", filedata).as_bytes());
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn filesum_filtered(
|
||||
}
|
||||
}
|
||||
}
|
||||
debug!("Diff for {:?} is now {}", path, diff_string);
|
||||
info!("Diff for {:?} is now {}", path, diff_string);
|
||||
changed = true;
|
||||
*oldfile = filedata;
|
||||
} else if oldfile.is_empty() {
|
||||
|
||||
@@ -59,8 +59,9 @@ fn t_multipath(
|
||||
}
|
||||
let now = Utc::now().timestamp().try_into().unwrap_or(0);
|
||||
{
|
||||
debug!("try to lock mutex snmp_data to update multipath {:?}", now);
|
||||
trace!("try to lock mutex snmp_data to update multipath {:?}", now);
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update multipath snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oidt.clone(), SnmpData::Gauge(now));
|
||||
snmp_data.insert(oidc.clone(), SnmpData::Gauge(mplist.len().try_into().unwrap_or(0)));
|
||||
@@ -137,8 +138,9 @@ fn t_bonding(
|
||||
}
|
||||
let now = Utc::now().timestamp().try_into().unwrap_or(0);
|
||||
{
|
||||
debug!("try to lock mutex snmp_data to update bonding with {:?}", now);
|
||||
trace!("try to lock mutex snmp_data to update bonding with {:?}", now);
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update bonding snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oidt.clone(), SnmpData::Gauge(now));
|
||||
snmp_data.insert(oidc.clone(), SnmpData::Gauge(bl.len().try_into().unwrap_or(0)));
|
||||
@@ -231,8 +233,9 @@ fn t_filesum(
|
||||
let oid_shadow_filename = Oid::from_str("6.3.1.1.2").unwrap();
|
||||
let oid_group_filename = Oid::from_str("6.3.1.1.3").unwrap();
|
||||
let oid_authkey_filename = Oid::from_str("6.3.1.1.4").unwrap();
|
||||
debug!("try to lock mutex snmp_data to update filesum header data");
|
||||
trace!("try to lock mutex snmp_data to update filesum header data");
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update filesum snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oid_filesum_cnt, SnmpData::Gauge(4));
|
||||
snmp_data.insert(oid_passwd_filename, SnmpData::String(fn_passwd_str.clone()));
|
||||
@@ -251,7 +254,7 @@ fn t_filesum(
|
||||
hash_passwd = hash;
|
||||
is_changed = true;
|
||||
} else {
|
||||
debug!("Hash of {} is still now {}", fn_passwd_str, hash);
|
||||
trace!("Hash of {} is still now {}", fn_passwd_str, hash);
|
||||
if hash_passwd.is_empty() {
|
||||
hash_passwd = hash;
|
||||
}
|
||||
@@ -268,7 +271,7 @@ fn t_filesum(
|
||||
hash_shadow = hash;
|
||||
is_changed = true;
|
||||
} else {
|
||||
debug!("Hash of {} is still now {}", fn_shadow_str, hash);
|
||||
trace!("Hash of {} is still now {}", fn_shadow_str, hash);
|
||||
if hash_shadow.is_empty() {
|
||||
hash_shadow = hash;
|
||||
}
|
||||
@@ -285,7 +288,7 @@ fn t_filesum(
|
||||
hash_group = hash;
|
||||
is_changed = true;
|
||||
} else {
|
||||
debug!("Hash of {} is still now {}", fn_group_str, hash);
|
||||
trace!("Hash of {} is still now {}", fn_group_str, hash);
|
||||
if hash_group.is_empty() {
|
||||
hash_group = hash;
|
||||
}
|
||||
@@ -302,7 +305,7 @@ fn t_filesum(
|
||||
hash_authkey = hash;
|
||||
is_changed = true;
|
||||
} else {
|
||||
debug!("Hash of {} is still now {}", fn_authkey_str, hash);
|
||||
trace!("Hash of {} is still now {}", fn_authkey_str, hash);
|
||||
if hash_authkey.is_empty() {
|
||||
hash_authkey = hash;
|
||||
}
|
||||
@@ -314,11 +317,12 @@ fn t_filesum(
|
||||
}
|
||||
let now = Utc::now().timestamp().try_into().unwrap_or(0);
|
||||
{
|
||||
debug!(
|
||||
trace!(
|
||||
"try to lock mutex snmp_data to update filesum data, timestamp {:?}",
|
||||
now
|
||||
);
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update filesum snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oid_filesum_time.clone(), SnmpData::Gauge(now));
|
||||
if is_changed {
|
||||
@@ -411,11 +415,12 @@ fn t_processes(t_quit: Arc<(Mutex<bool>, Condvar)>, t_check_interval: u64, snmp_
|
||||
}
|
||||
let now = Utc::now().timestamp().try_into().unwrap_or(0);
|
||||
{
|
||||
debug!(
|
||||
trace!(
|
||||
"try to lock mutex snmp_data to update processdata with {:#?} => {:?}",
|
||||
now, proc_data
|
||||
);
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update processdata snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oidt.clone(), SnmpData::Gauge(now));
|
||||
snmp_data.insert(oidz.clone(), SnmpData::Gauge(proc_data.zombie));
|
||||
@@ -461,13 +466,13 @@ fn t_meminfo(t_quit: Arc<(Mutex<bool>, Condvar)>, t_check_interval: u64, snmp_da
|
||||
if let Ok(meminfo_contents) = fs::read_to_string(&fpath) {
|
||||
trace!("Read /prod/meminfo, contents: {:#?}", meminfo_contents);
|
||||
if let Some(m) = re.captures(&meminfo_contents) {
|
||||
debug!("regex mached {:?}", m);
|
||||
trace!("regex mached {:?}", m);
|
||||
if let Some(m) = m.get(1) {
|
||||
freekb += m.as_str().parse().unwrap_or(0);
|
||||
debug!("freekb via regex parsed as {:#?}", freekb);
|
||||
}
|
||||
} else if let Some(m) = re_old.captures(&meminfo_contents) {
|
||||
debug!("old regex mached {:#?}", m);
|
||||
trace!("old regex mached {:#?}", m);
|
||||
if let Some(m) = m.get(1) {
|
||||
freekb += m.as_str().parse().unwrap_or(0);
|
||||
}
|
||||
@@ -478,11 +483,12 @@ fn t_meminfo(t_quit: Arc<(Mutex<bool>, Condvar)>, t_check_interval: u64, snmp_da
|
||||
}
|
||||
let now = Utc::now().timestamp().try_into().unwrap_or(0);
|
||||
{
|
||||
debug!(
|
||||
trace!(
|
||||
"try to lock mutex snmp_data to update meminfo with {:#?} => {:#?}",
|
||||
now, freekb
|
||||
);
|
||||
let mut guard = snmp_data.lock().unwrap();
|
||||
trace!("mutex for update meminfo snmp_data now locked");
|
||||
let snmp_data = &mut guard.data;
|
||||
snmp_data.insert(oidt.clone(), SnmpData::Gauge(now));
|
||||
//snmp_data.insert(oidm.clone(), SnmpData::String(freekb.to_string()));
|
||||
@@ -517,7 +523,7 @@ fn log_debug_watcher(
|
||||
match t_marker.try_exists() {
|
||||
Ok(v) => {
|
||||
if v != last {
|
||||
debug!("marker file {} is now readable: {:?}", t_marker.display(), v);
|
||||
trace!("marker file {} is now readable: {:?}", t_marker.display(), v);
|
||||
let r = match v {
|
||||
true => log.parse_and_push_temp_spec("trace"),
|
||||
false => {
|
||||
@@ -526,7 +532,7 @@ fn log_debug_watcher(
|
||||
}
|
||||
};
|
||||
match r {
|
||||
Ok(_) => info!(
|
||||
Ok(_) => warn!(
|
||||
"Log config changed to {}",
|
||||
log.current_max_level()
|
||||
.expect("Retrive the current log level not possible")
|
||||
@@ -587,7 +593,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start log_debug_watcher thread: {:#?}", e);
|
||||
eprintln!("Unable to start log_debug_watcher thread: {:#?}", e);
|
||||
//eprintln!("Unable to start log_debug_watcher thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -608,7 +614,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start meminfo thread: {:#?}", e);
|
||||
eprintln!("Unable to start meminfo thread: {:#?}", e);
|
||||
//eprintln!("Unable to start meminfo thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -632,7 +638,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start processes thread: {:#?}", e);
|
||||
eprintln!("Unable to start processes thread: {:#?}", e);
|
||||
//eprintln!("Unable to start processes thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -654,7 +660,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start filesum thread: {:#?}", e);
|
||||
eprintln!("Unable to start filesum thread: {:#?}", e);
|
||||
//eprintln!("Unable to start filesum thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -679,7 +685,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start multipath thread: {:#?}", e);
|
||||
eprintln!("Unable to start multipath thread: {:#?}", e);
|
||||
//eprintln!("Unable to start multipath thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -701,7 +707,7 @@ pub fn start_workers(
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Unable to start bonding thread: {:#?}", e);
|
||||
eprintln!("Unable to start bonding thread: {:#?}", e);
|
||||
//eprintln!("Unable to start bonding thread: {:#?}", e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user