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
//! [Connectors] allows to manage the list of [Connector].
use log::error;
use crate::config::Config;
use crate::connectors::connector::Connector;
use crate::process::ProcessRecord;
/// Struct initializing the list of connectors and managing launch events.
pub struct Connectors;
impl Connectors {
/// Initialize the list of [Connector]
///
/// Add your custom connector in the Vec array.
///
/// # Example
/// Basic usage:
/// ```
/// vec![
/// Box::new(MyConnector),
/// ]
/// ```
/// Where `MyConnector` is a struct implementing the [Connector] trait.
fn new() -> Vec<Box<dyn Connector>> {
vec![
// Box::new(Community),
// Box::new(SitinCloud),
// Box::new(MyConnector),
]
}
/// Launch on_startup method of all connectors at service startup.
pub fn on_startup(config: &Config) {
for connector in Connectors::new() {
let on_startup = connector.on_startup(config);
match on_startup {
Ok(on_startup) => on_startup,
Err(e) => {
error!("{}", e.to_string());
println!("{}", e.to_string());
// panic!("{}", e.to_string());
}
}
}
}
/// Launch on_event_kill method of all connectors at threat detection.
pub fn on_event_kill(config: &Config, proc: &ProcessRecord, prediction: f32) {
for connector in Connectors::new() {
let on_event_kill = connector.on_event_kill(config, proc, prediction);
match on_event_kill {
Ok(on_event_kill) => on_event_kill,
Err(e) => {
error!("{}", e.to_string());
println!("{}", e.to_string());
// panic!("{}", e.to_string());
}
}
}
}
}