Skip to content

Commit 42c21bf

Browse files
authored
Merge pull request #62 from ddbnl/master
Add Azure Log Analytics interface
2 parents 4223ea6 + a1117b4 commit 42c21bf

17 files changed

+298
-25
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Release/Linux/OfficeAuditLogCollector filter=lfs diff=lfs merge=lfs -text
2+
Release/Windows/OfficeAuditLogCollector.exe filter=lfs diff=lfs merge=lfs -text

.github/FUNDING.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
4+
buy_me_a_coffee: ddbnl

Cargo.lock

+111-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ serde_derive = "1.0.136"
1919
clap = { version = "4.5.2", features = ["derive"] }
2020
csv = "1.3.0"
2121
poston = "0.7.8"
22+
base64 = "0.22.0"
23+
hmac = "0.12.1"
24+
sha2 = "0.10.8"
25+
async-trait = "0.1.77"
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
collect:
2+
contentTypes:
3+
Audit.General: True
4+
Audit.AzureActiveDirectory: True
5+
Audit.Exchange: True
6+
Audit.SharePoint: True
7+
DLP.All: True
8+
output:
9+
azureLogAnalytics:
10+
workspaceId: 11111111-1111-1111-1111-1111111111111
11+
# Get shared key through AZ CLI:
12+
# az monitor log-analytics workspace get-shared-keys --resource-group my-rg --workspace-name my-oms --query "primarySharedKey"
13+
# Then run collector with:
14+
# OfficeAuditLogCollector [...] --oms-key '12345'

Release/Linux/OfficeAuditLogCollector

190 KB
Binary file not shown.
4.85 MB
Binary file not shown.

src/collector.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::api_connection;
1313
use crate::api_connection::ApiConnection;
1414
use crate::config::{Config, ContentTypesSubConfig};
1515
use crate::data_structures::{ArbitraryJson, Caches, CliArgs, ContentToRetrieve, JsonList};
16+
use crate::interfaces::azure_oms_interface::OmsInterface;
1617
use crate::interfaces::interface::Interface;
1718
use crate::interfaces::file_interface::FileInterface;
1819
use crate::interfaces::fluentd_interface::FluentdInterface;
@@ -55,6 +56,9 @@ impl Collector {
5556
if config.output.graylog.is_some() {
5657
interfaces.push(Box::new(GraylogInterface::new(config.clone())));
5758
}
59+
if config.output.oms.is_some() {
60+
interfaces.push(Box::new(OmsInterface::new(config.clone(), args.oms_key.clone())));
61+
}
5862

5963
// Initialize collector threads
6064
let api = api_connection::get_api_connection(
@@ -94,7 +98,7 @@ impl Collector {
9498

9599
/// Monitor all started content retrieval threads, processing results and terminating
96100
/// when all content has been retrieved (signalled by a final run stats message).
97-
pub fn monitor(&mut self) {
101+
pub async fn monitor(&mut self) {
98102

99103
let start = Instant::now();
100104
loop {
@@ -106,12 +110,12 @@ impl Collector {
106110
}
107111
// Run stats are only returned when all content has been retrieved,
108112
// therefore this signals the end of the run.
109-
if self.check_stats() {
113+
if self.check_stats().await {
110114
break
111115
}
112116

113117
// Check if a log came in.
114-
self.check_results();
118+
self.check_results().await;
115119
}
116120
self.end_run();
117121
}
@@ -120,25 +124,25 @@ impl Collector {
120124
self.config.save_known_blobs(&self.known_blobs);
121125
}
122126

123-
fn check_results(&mut self) {
127+
async fn check_results(&mut self) {
124128

125129
if let Ok(Some((msg, content))) = self.result_rx.try_next() {
126-
self.handle_content(msg, content);
130+
self.handle_content(msg, content).await;
127131
}
128132
}
129133

130-
fn handle_content(&mut self, msg: String, content: ContentToRetrieve) {
134+
async fn handle_content(&mut self, msg: String, content: ContentToRetrieve) {
131135
self.known_blobs.insert(content.content_id.clone(), content.expiration.clone());
132136
if let Ok(logs) = serde_json::from_str::<JsonList>(&msg) {
133137
for log in logs {
134-
self.handle_log(log, &content);
138+
self.handle_log(log, &content).await;
135139
}
136140
} else {
137141
warn!("Skipped log that could not be parsed: {}", content.content_id)
138142
}
139143
}
140144

141-
fn handle_log(&mut self, mut log: ArbitraryJson, content: &ContentToRetrieve) {
145+
async fn handle_log(&mut self, mut log: ArbitraryJson, content: &ContentToRetrieve) {
142146

143147
if let Some(filters) = self.filters.get(&content.content_type) {
144148
for (k, v) in filters.iter() {
@@ -154,17 +158,17 @@ impl Collector {
154158
self.cache.insert(log, &content.content_type);
155159
self.saved += 1;
156160
if self.cache.full() {
157-
self.output();
161+
self.output().await;
158162
}
159163
}
160-
fn check_stats(&mut self) -> bool {
164+
async fn check_stats(&mut self) -> bool {
161165

162166
if let Ok(Some((found,
163167
successful,
164168
retried,
165169
failed))) = self.stats_rx.try_next() {
166170

167-
self.output();
171+
self.output().await;
168172
let output = self.get_output_string(
169173
found,
170174
successful,
@@ -180,15 +184,15 @@ impl Collector {
180184
}
181185
}
182186

183-
fn output(&mut self) {
187+
async fn output(&mut self) {
184188

185189
let mut cache = Caches::new(self.cache.size);
186190
swap(&mut self.cache, &mut cache);
187191
if self.interfaces.len() == 1 {
188-
self.interfaces.get_mut(0).unwrap().send_logs(cache);
192+
self.interfaces.get_mut(0).unwrap().send_logs(cache).await;
189193
} else {
190194
for interface in self.interfaces.iter_mut() {
191-
interface.send_logs(cache.clone());
195+
interface.send_logs(cache.clone()).await;
192196
}
193197
}
194198
}
@@ -287,7 +291,7 @@ fn initialize_channels(
287291
retries: config.collect.retries.unwrap_or(3),
288292
kill_rx,
289293
};
290-
return (blob_config, content_config, message_loop_config, blobs_rx, content_rx, result_rx,
294+
(blob_config, content_config, message_loop_config, blobs_rx, content_rx, result_rx,
291295
stats_rx, kill_tx)
292296
}
293297

0 commit comments

Comments
 (0)