1pub mod aws;
2pub mod azure;
3pub(crate) mod common;
4pub mod enrichment;
5pub mod err;
6pub mod maxmind;
7pub mod o365;
8pub mod tasks;
9
10#[cfg(test)]
11mod tst {
12
13 use usiem::prelude::{geo_ip::GeoIpDataset, SiemIp};
14
15 use crate::maxmind::{
16 download_maxmind_geo_litle2_asn, download_maxmind_geo_litle2_city,
17 download_maxmind_geo_litle2_country, extract_zip_db, join_path_files,
18 process_maxmind_geo_lite2_csv,
19 };
20
21 #[ignore]
22 #[test]
23 fn should_load_geoip() {
24 let now = std::time::Instant::now();
25 #[cfg(not(feature = "slow_geoip"))]
26 let dataset = GeoIpDataset::new();
27 #[cfg(feature = "slow_geoip")]
28 let dataset = GeoIpDataset::new("./slow_geo_ip");
29 println!("Duration {}", now.elapsed().as_secs_f32());
30 let res = dataset
31 .get(&SiemIp::from_ip_str("1.0.0.0").unwrap())
32 .unwrap();
33 println!("{:?}", res);
34 let res = dataset
35 .get(&SiemIp::from_ip_str("1.0.4.0").unwrap())
36 .unwrap();
37 println!("{:?}", res);
38 let now = std::time::Instant::now();
39 for i in 0..1_000_000 {
40 let _res = dataset.get(&SiemIp::V4(i));
41 }
42 println!("Duration {}", now.elapsed().as_secs_f32());
43 }
44 #[ignore]
45 #[tokio::test]
46 async fn should_update_geo_ip() {
47 let now = std::time::Instant::now();
48 let asn_path = download_maxmind_geo_litle2_asn(
49 &std::env::var("MAXMIND_API").expect("Should exists var"),
50 )
51 .await
52 .unwrap();
53 let city_path = download_maxmind_geo_litle2_city(
54 &std::env::var("MAXMIND_API").expect("Should exists var"),
55 )
56 .await
57 .unwrap();
58 let country_path = download_maxmind_geo_litle2_country(
59 &std::env::var("MAXMIND_API").expect("Should exists var"),
60 )
61 .await
62 .unwrap();
63 let city_path = extract_zip_db(&city_path).await.unwrap();
64 let country_path = extract_zip_db(&country_path).await.unwrap();
65 let asn_path = extract_zip_db(&asn_path).await.unwrap();
66 println!("{:?}", city_path);
67 println!("{:?}", country_path);
68 println!("{:?}", asn_path);
69 let new_path = join_path_files(vec![city_path, country_path, asn_path])
70 .await
71 .unwrap();
72 println!("{:?}", new_path);
73 #[cfg(not(feature = "slow_geoip"))]
74 let res = process_maxmind_geo_lite2_csv("/tmp/geoip_501122574_db", true, "en")
75 .await
76 .unwrap();
77 #[cfg(feature = "slow_geoip")]
78 let res = process_maxmind_geo_lite2_csv("/tmp/geoip_501122574_db", true, "en", "./slow_geo_ip")
79 .await
80 .unwrap();
81 println!("Duration {}", now.elapsed().as_secs_f32());
82 let _geoip = res.get(&SiemIp::from_ip_str("1.0.0.0").unwrap()).unwrap();
83 let now = std::time::Instant::now();
84 for i in 0..1_000_000 {
85 let _res = res.get(&SiemIp::V4(i));
86 }
87 println!("Duration {}", now.elapsed().as_secs_f32());
88 }
89}