diff options
author | Mario Krehl <mario-krehl@gmx.de> | 2017-12-10 14:24:12 +0100 |
---|---|---|
committer | Mario Krehl <mario-krehl@gmx.de> | 2017-12-10 14:24:12 +0100 |
commit | 0b7f6cd62bd821b96cc9c7bf53e08da7db7b7835 (patch) | |
tree | 95ccce3679667fb927ab0f36e72f95dcfe8e46cc | |
parent | c2d72a443f4597d6b26965904b94acd08d34afeb (diff) |
Start implementing /query
-rw-r--r-- | example_config.toml | 2 | ||||
-rw-r--r-- | src/config.rs | 22 | ||||
-rw-r--r-- | src/main.rs | 24 |
3 files changed, 44 insertions, 4 deletions
diff --git a/example_config.toml b/example_config.toml index 95cdfa9..20646b7 100644 --- a/example_config.toml +++ b/example_config.toml @@ -6,6 +6,6 @@ alias = "tempmain" [[item]] file = "/var/log/antikoerper/os.load" -regex = "(\\d+)\\s(\\d+\\.\\d\\d)\\s(\\d+\\.\\d\\d)\\s(\\d+\\.\\d\\d)\\s" +regex = "(?P<ts>\\d+)\\s(?P<load1m>\\d+\\.\\d\\d)\\s(?P<load5m>\\d+\\.\\d\\d)\\s(?P<load15m>\\d+\\.\\d\\d)\\s" alias = "load" diff --git a/src/config.rs b/src/config.rs index c2199c4..c004493 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,6 +58,8 @@ impl ConfigDeser { pub struct LogItem { file : String, regex : Regex, + alias : String, + capture_names : Vec<String>, aliases : Vec<String>, } @@ -77,7 +79,7 @@ impl LogItem { .collect(); debug!("capture names: {:?}", cnames); let mut als : Vec<String> = Vec::new(); - for name in cnames { + for name in cnames.clone() { let mut temp = String::from(lid.alias.as_str()); temp.push('.'); temp.push_str(name.as_str()); @@ -85,7 +87,15 @@ impl LogItem { } debug!("aliases: {:?}", als); - Ok(LogItem { file : lid.file, regex : l_regex, aliases : als }) + Ok( + LogItem { + file : lid.file, + regex : l_regex, + alias: lid.alias, + capture_names : cnames, + aliases : als + } + ) } pub fn file(&self) -> &String { @@ -96,6 +106,14 @@ impl LogItem { &self.regex } + pub fn alias(&self) -> &String { + &self.alias + } + + pub fn capture_names(&self) -> &Vec<String> { + &self.capture_names + } + pub fn aliases(&self) -> &Vec<String> { &self.aliases } diff --git a/src/main.rs b/src/main.rs index 1281e08..c784d7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ mod api; mod config; mod error; use api::*; -use config::Config; +use config::{Config, LogItem}; use error::*; #[get("/")] @@ -53,6 +53,28 @@ fn search(data : Json<Search>, config: State<Config>) -> Json<SearchResponse> { #[post("/query", format = "application/json", data = "<data>")] fn query(data: Json<Query>, config: State<Config>) -> Result<Json<QueryResponse>> { + debug!("handling query: {:?}", data.0); + let targets = data.0.targets; + debug!("targets: {:?}", targets); + let response : Vec<TargetData> = Vec::new(); + let target_collection : Vec<(LogItem, Vec<String>)> = Vec::new(); + let mut target_hash : std::collections::HashMap<&String, (&LogItem, &Vec<String>)> = std::collections::HashMap::new(); + for li in config.items() { + for t in targets.clone() { + if li.aliases().contains(&t.target) { + if let Some(&(_, ref mut cnames)) = target_hash.get(&li.alias()) { + cnames.push(t.target.split('.').nth(1).ok_or(Error::from("no capture name found"))?.into()); + } + else { + target_hash.insert( + li.alias(), + (&li, &vec![t.target.split('.').nth(1).ok_or(Error::from("no capture name found"))?.into()]) + ); + } + } + } + } + Err(Error::from("not implemented")) } |