1extern crate repsheet_etl;
2use std::collections::HashMap;
3use std::collections::hash_map::Entry::{Vacant, Occupied};
4
5fn lookup_or_zero(hash: &mut HashMap<String, i64>, key: &str) -> i64 {
6 match hash.entry(key.to_string()) {
7 Occupied(v) => return *v.get(),
8 Vacant(_) => return 0,
9 }
10}
11
12fn apply_ruleset(actors: &mut HashMap<String, repsheet_etl::actor::Actor>) {
13 for (address, actor) in actors {
14 if lookup_or_zero(&mut actor.responses, "404") > 50 {
15 println!("Blacklisting {}. Too many 404s", address);
16 }
17 }
18}
19
20fn main() {
21 let _ = match repsheet_etl::process("access.log") {
22 Ok(mut actors) => { apply_ruleset(&mut actors) },
23 Err(e) => println!("{}", e),
24 };
25}