From cc2a90d03dec569f3177f91f4fa7c95e4e6431fe Mon Sep 17 00:00:00 2001 From: BOUTELIER Sebastien <sebastien.boutelier@lis-lab.fr> Date: Mon, 30 Oct 2023 14:10:47 +0100 Subject: [PATCH] Hostname et typo --- parselog.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/parselog.rs b/parselog.rs index 0a28d5b..88d2c59 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()); -- GitLab