WIP
This commit is contained in:
commit
740941861f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
140
Cargo.lock
generated
Normal file
140
Cargo.lock
generated
Normal file
@ -0,0 +1,140 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom-regex"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72e5c7731c4c1370b61604ed52a2475e861aac9e08dec9f23903d4ddfdc91c18"
|
||||
dependencies = [
|
||||
"nom",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rslog"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rsyslog",
|
||||
"sqlite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rsyslog"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f5963755808e34aea5b05a720a0044e2f10f39f61d69bbed56ecbb3369a1541"
|
||||
dependencies = [
|
||||
"nom",
|
||||
"nom-regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "sqlite"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfe6fb16f2bee6452feeb4d12bfa404fbcd3cfc121b2950e501d1ae9cae718e"
|
||||
dependencies = [
|
||||
"sqlite3-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-src"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "174d4a6df77c27db281fb23de1a6d968f3aaaa4807c2a1afa8056b971f947b4a"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-sys"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3901ada7090c3c3584dc92ec7ef1b7091868d13bfe6d7de9f0bcaffee7d0ade5"
|
||||
dependencies = [
|
||||
"sqlite3-src",
|
||||
]
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rslog"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rsyslog = "0.1.5"
|
||||
sqlite = "0.36.1"
|
49
src/lib.rs
Normal file
49
src/lib.rs
Normal file
@ -0,0 +1,49 @@
|
||||
pub mod rslog {
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Severity {
|
||||
Emerg = 0,
|
||||
Alert = 1,
|
||||
Crit = 2,
|
||||
Err = 3,
|
||||
Warn = 4,
|
||||
Notice = 5,
|
||||
Info = 6,
|
||||
Debug = 7
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Facility {
|
||||
Kern = 0,
|
||||
User = 1,
|
||||
Mail = 2,
|
||||
Daemon = 3,
|
||||
Auth = 4,
|
||||
Syslog = 5,
|
||||
Lpr = 6,
|
||||
News = 7,
|
||||
Uucp = 8,
|
||||
Cron = 9,
|
||||
Authpriv = 10,
|
||||
Ftp = 11,
|
||||
Ntp = 12,
|
||||
Security = 13,
|
||||
Console = 14,
|
||||
Sched = 15,
|
||||
Local0 = 16,
|
||||
Local1 = 17,
|
||||
Local2 = 18,
|
||||
Local3 = 19,
|
||||
Local4 = 20,
|
||||
Local5 = 21,
|
||||
Local6 = 22,
|
||||
Local7 = 23
|
||||
}
|
||||
|
||||
//<13>1 2025-01-23T13:29:45.058591+01:00 justine-ppc731260 justine - - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="897000"] test
|
||||
//<Priority>Version timestamp hostname Applicationname PID MessageID [Structured Data] text
|
||||
pub struct Message {
|
||||
pub severity: Severity,
|
||||
pub facility: Facility,
|
||||
}
|
||||
}
|
29
src/main.rs
Normal file
29
src/main.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use std::net::UdpSocket;
|
||||
use rsyslog::Message;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:5140")?; // Bind to the standard syslog port
|
||||
let mut buf = [0; 1024];
|
||||
let mut storage: Vec<(String,Message)> = vec!();
|
||||
|
||||
loop {
|
||||
//Gather the message
|
||||
let (size, src) = socket.recv_from(&mut buf)?;
|
||||
//Get its origin and remove the port
|
||||
let orig = src.ip().to_string();
|
||||
//Parse the message
|
||||
let msg = String::from_utf8_lossy(&buf[..size]);
|
||||
let fmsg: Message = Message::parse(&msg).unwrap();
|
||||
//Print
|
||||
println!("{}:\t {:#?}", orig, fmsg);
|
||||
}
|
||||
}
|
||||
|
||||
//Init an sqlite DB and store messages in it.
|
||||
//Later run regexes on messages and show in a web interface.
|
||||
fn store_db(msg: &Message) -> std::io::Result<()> {
|
||||
let connection = sqlite::open(":memory:").unwrap();
|
||||
//See https://docs.rs/sqlite/latest/sqlite/index.html
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user