1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Catapult is a simple replacement for logstash written in Rust
//!
//! It aims at being a simple logshipper that read logs from its inputs, transforms them using its filters
//! and send them to its outputs.

#[macro_use]
extern crate nom;

#[macro_use]
extern crate log;

extern crate chrono;
extern crate hyper;
extern crate serde;
extern crate serde_json;
extern crate time;
extern crate url;

extern crate docopt;

pub mod config;
pub mod inputs;
pub mod outputs;
pub mod filters;
pub mod processor;

use docopt::Docopt;
use processor::{InputProcessor, OutputProcessor};

// Write the Docopt usage string. dfrites ?
static USAGE: &'static str = "
Usage: catapult [-c CONFIGFILE]
       catapult (--help | -h)

Options:
    -h, --help     Show this screen.
    -c CONFIGFILE  Configuration file [default: catapult.conf]
";

#[allow(dead_code)]
fn main() {
    // Parse argv and exit the program with an error message if it fails.
    let args = Docopt::new(USAGE)
        .and_then(|d| d.argv(std::env::args().into_iter()).parse())
        .unwrap_or_else(|e| e.exit());

    let config_file = args.get_str("-c");

    let configuration = config::read_config_file(config_file);
    match configuration  {
        Ok(conf) => {
            let ref input = conf.inputs[0];
            let ref datasource_name = input.0;
            let ref args = conf.inputs[0].1;
            let data_input = match datasource_name.as_ref() {
                "stdin" => inputs::stdin::Stdin::new(datasource_name.to_owned()).start(args),
                "random" => inputs::random::Random::new(datasource_name.to_owned()).start(args),
                "network" => inputs::network::Network::new(datasource_name.to_owned()).start(args),
                unsupported => { panic!("Input {} not implemented", unsupported)}
            };

            let ref output = conf.outputs[0];
            let ref dataoutput_name = output.0;
            let ref oargs = output.1;
            let data_output = match output.0.as_ref() {
                "stdout" => outputs::stdout::Stdout::new(dataoutput_name.to_owned()).start(data_input, oargs),
                "network" => outputs::network::Network::new(dataoutput_name.to_owned()).start(data_input, oargs),
                "file" => outputs::file::RotatingFile::new(dataoutput_name.to_owned()).start(data_input, oargs),
                "elasticsearch" => outputs::elasticsearch::Elasticsearch::new(dataoutput_name.to_owned()).start(data_input, oargs),
                unsupported => { panic!("Output {} not implemented", unsupported)}
            };

            let _p = data_output.unwrap().join();

        },
        Err(e) => panic!("{:?}", e)
    };


}