diff --git a/parselog.rs b/parselog.rs index 0a28d5b4ac31e205d209fd4ed05c75ac04c9e95f..88d2c59e62507999f56a662afccbae40bdb76dbb 100644 --- a/parselog.rs +++ b/parselog.rs @@ -5,10 +5,12 @@ use std::env; use regex::Regex; use syslog::{Facility, Formatter3164}; use std::sync::OnceLock; +use gethostname::gethostname; mod hashmap; static LOGHOST: OnceLock<String> = OnceLock::new(); +static HOSTNAME: OnceLock<Option<String>> = OnceLock::new(); static REGEXP_CLOSE: OnceLock<Regex> = OnceLock::new(); static REGEXP_CMD: OnceLock<Regex> = OnceLock::new(); static REGEXP_CONNECT: OnceLock<Regex> = OnceLock::new(); @@ -156,8 +158,8 @@ fn com_default(line: String){ fn sendlog(line: String){ let formatter = Formatter3164 { facility: Facility::LOG_USER, - hostname: None, - process: "sldapd".into(), + hostname: HOSTNAME.get().unwrap().clone(), + process: "slapd".into(), pid: 6666, }; @@ -222,6 +224,8 @@ fn main() { let loghost = getloghost().unwrap(); let _ = LOGHOST.set(loghost); let port = getport().unwrap(); + let hostname = Some(gethostname().into_string().unwrap()); + let _ = HOSTNAME.set(hostname); let _ = REGEXP_LAUNCH.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ (?<con>\S+) (?<op>\S+) (?<command>\S+)").unwrap()); let _ = REGEXP_OTHERLOG.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ (?<log>.+)").unwrap()); let _ = REGEXP_RESULT.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) op=(?<op>[0-9]+)( SEARCH)? RESULT \S+ (?<err>\S+)( nentries=(?<nentries>[0-9]+))?").unwrap());