Repository navigation
Expand file tree
/
Copy pathsplunk_hec.rs
More file actions
763 lines (630 loc) · 23.5 KB
/
Copy pathsplunk_hec.rs
File metadata and controls
763 lines (630 loc) · 23.5 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
use crate::{
config::{log_schema, DataType, SinkConfig, SinkContext, SinkDescription},
event::{Event, LogEvent, Value},
http::HttpClient,
internal_events::{
SplunkEventEncodeError, SplunkEventSent, SplunkSourceMissingKeys,
SplunkSourceTypeMissingKeys,
},
sinks::util::{
encoding::{EncodingConfigWithDefault, EncodingConfiguration},
http::{BatchedHttpSink, HttpSink},
BatchConfig, BatchSettings, Buffer, Compression, Concurrency, TowerRequestConfig,
},
template::Template,
tls::{TlsOptions, TlsSettings},
};
use futures::{FutureExt, SinkExt};
use http::{Request, StatusCode, Uri};
use hyper::Body;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use serde_json::json;
use snafu::{ResultExt, Snafu};
use std::convert::TryFrom;
#[derive(Debug, Snafu)]
pub enum BuildError {
#[snafu(display("Host must include a scheme (https:// or http://)"))]
UriMissingScheme,
}
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(deny_unknown_fields)]
pub struct HecSinkConfig {
pub token: String,
// Deprecated name
#[serde(alias = "host")]
pub endpoint: String,
#[serde(default = "default_host_key")]
pub host_key: String,
#[serde(default)]
pub indexed_fields: Vec<String>,
pub index: Option<String>,
pub sourcetype: Option<Template>,
pub source: Option<Template>,
#[serde(
skip_serializing_if = "crate::serde::skip_serializing_if_default",
default
)]
pub encoding: EncodingConfigWithDefault<Encoding>,
#[serde(default)]
pub compression: Compression,
#[serde(default)]
pub batch: BatchConfig,
#[serde(default)]
pub request: TowerRequestConfig,
pub tls: Option<TlsOptions>,
}
lazy_static! {
static ref REQUEST_DEFAULTS: TowerRequestConfig = TowerRequestConfig {
concurrency: Concurrency::Fixed(10),
rate_limit_num: Some(10),
..Default::default()
};
}
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Derivative)]
#[serde(rename_all = "snake_case")]
#[derivative(Default)]
pub enum Encoding {
#[derivative(Default)]
Text,
Json,
}
fn default_host_key() -> String {
crate::config::LogSchema::default().host_key().to_string()
}
inventory::submit! {
SinkDescription::new::<HecSinkConfig>("splunk_hec")
}
impl_generate_config_from_default!(HecSinkConfig);
#[async_trait::async_trait]
#[typetag::serde(name = "splunk_hec")]
impl SinkConfig for HecSinkConfig {
async fn build(
&self,
cx: SinkContext,
) -> crate::Result<(super::VectorSink, super::Healthcheck)> {
validate_host(&self.endpoint)?;
let batch = BatchSettings::default()
.bytes(bytesize::mib(1u64))
.timeout(1)
.parse_config(self.batch)?;
let request = self.request.unwrap_with(&REQUEST_DEFAULTS);
let tls_settings = TlsSettings::from_options(&self.tls)?;
let client = HttpClient::new(tls_settings)?;
let sink = BatchedHttpSink::new(
self.clone(),
Buffer::new(batch.size, self.compression),
request,
batch.timeout,
client.clone(),
cx.acker(),
)
.sink_map_err(|error| error!(message = "Fatal splunk_hec sink error.", %error));
let healthcheck = healthcheck(self.clone(), client).boxed();
Ok((super::VectorSink::Sink(Box::new(sink)), healthcheck))
}
fn input_type(&self) -> DataType {
DataType::Log
}
fn sink_type(&self) -> &'static str {
"splunk_hec"
}
}
#[async_trait::async_trait]
impl HttpSink for HecSinkConfig {
type Input = Vec<u8>;
type Output = Vec<u8>;
fn encode_event(&self, event: Event) -> Option<Self::Input> {
let sourcetype = self.sourcetype.as_ref().and_then(|sourcetype| {
sourcetype
.render_string(&event)
.map_err(|missing_keys| {
emit!(SplunkSourceTypeMissingKeys {
keys: &missing_keys
});
})
.ok()
});
let source = self.source.as_ref().and_then(|source| {
source
.render_string(&event)
.map_err(|missing_keys| {
emit!(SplunkSourceMissingKeys {
keys: &missing_keys
});
})
.ok()
});
let mut event = event.into_log();
let host = event.get(self.host_key.to_owned()).cloned();
let timestamp = match event.remove(log_schema().timestamp_key()) {
Some(Value::Timestamp(ts)) => ts,
_ => chrono::Utc::now(),
};
let timestamp = (timestamp.timestamp_millis() as f64) / 1000f64;
let fields = self
.indexed_fields
.iter()
.filter_map(|field| event.get(field).map(|value| (field, value.clone())))
.collect::<LogEvent>();
let mut event = Event::Log(event);
self.encoding.apply_rules(&mut event);
let event = event.into_log();
let event = match self.encoding.codec() {
Encoding::Json => json!(event),
Encoding::Text => json!(event
.get(log_schema().message_key())
.map(|v| v.to_string_lossy())
.unwrap_or_else(|| "".into())),
};
let mut body = json!({
"event": event,
"fields": fields,
"time": timestamp
});
if let Some(host) = host {
let host = host.to_string_lossy();
body["host"] = json!(host);
}
if let Some(index) = &self.index {
body["index"] = json!(index);
}
if let Some(source) = source {
body["source"] = json!(source);
}
if let Some(sourcetype) = &sourcetype {
body["sourcetype"] = json!(sourcetype);
}
match serde_json::to_vec(&body) {
Ok(value) => {
emit!(SplunkEventSent {
byte_size: value.len()
});
Some(value)
}
Err(e) => {
emit!(SplunkEventEncodeError { error: e });
None
}
}
}
async fn build_request(&self, events: Self::Output) -> crate::Result<Request<Vec<u8>>> {
let uri =
build_uri(&self.endpoint, "/services/collector/event").expect("Unable to parse URI");
let mut builder = Request::post(uri)
.header("Content-Type", "application/json")
.header("Authorization", format!("Splunk {}", self.token));
if let Some(ce) = self.compression.content_encoding() {
builder = builder.header("Content-Encoding", ce);
}
builder.body(events).map_err(Into::into)
}
}
#[derive(Debug, Snafu)]
enum HealthcheckError {
#[snafu(display("Invalid HEC token"))]
InvalidToken,
#[snafu(display("Queues are full"))]
QueuesFull,
}
pub async fn healthcheck(config: HecSinkConfig, client: HttpClient) -> crate::Result<()> {
let uri = build_uri(&config.endpoint, "/services/collector/health/1.0")
.context(super::UriParseError)?;
let request = Request::get(uri)
.header("Authorization", format!("Splunk {}", config.token))
.body(Body::empty())
.unwrap();
let response = client.send(request).await?;
match response.status() {
StatusCode::OK => Ok(()),
StatusCode::BAD_REQUEST => Err(HealthcheckError::InvalidToken.into()),
StatusCode::SERVICE_UNAVAILABLE => Err(HealthcheckError::QueuesFull.into()),
other => Err(super::HealthcheckError::UnexpectedStatus { status: other }.into()),
}
}
pub fn validate_host(host: &str) -> crate::Result<()> {
let uri = Uri::try_from(host).context(super::UriParseError)?;
match uri.scheme() {
Some(_) => Ok(()),
None => Err(Box::new(BuildError::UriMissingScheme)),
}
}
fn build_uri(host: &str, path: &str) -> Result<Uri, http::uri::InvalidUri> {
format!("{}{}", host.trim_end_matches('/'), path).parse::<Uri>()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::event::Event;
use crate::sinks::util::{http::HttpSink, test::load_sink};
use chrono::Utc;
use serde::Deserialize;
use std::collections::BTreeMap;
#[test]
fn generate_config() {
crate::test_util::test_generate_config::<HecSinkConfig>();
}
#[derive(Deserialize, Debug)]
struct HecEventJson {
time: f64,
event: BTreeMap<String, String>,
fields: BTreeMap<String, String>,
source: Option<String>,
}
#[derive(Deserialize, Debug)]
struct HecEventText {
time: f64,
event: String,
fields: BTreeMap<String, String>,
}
#[test]
fn splunk_encode_event_json() {
let mut event = Event::from("hello world");
event.as_mut_log().insert("key", "value");
event.as_mut_log().insert("magic", "vector");
let (config, _cx) = load_sink::<HecSinkConfig>(
r#"
host = "test.com"
token = "alksjdfo"
host_key = "host"
indexed_fields = ["key"]
source = "{{ magic }}"
[encoding]
codec = "json"
except_fields = ["magic"]
"#,
)
.unwrap();
let bytes = config.encode_event(event).unwrap();
let hec_event = serde_json::from_slice::<HecEventJson>(&bytes[..]).unwrap();
let event = &hec_event.event;
let kv = event.get(&"key".to_string()).unwrap();
assert_eq!(kv, &"value".to_string());
assert_eq!(
event[&log_schema().message_key().to_string()],
"hello world".to_string()
);
assert!(event
.get(&log_schema().timestamp_key().to_string())
.is_none());
assert!(!event.contains_key("magic"));
assert_eq!(hec_event.source, Some("vector".to_string()));
assert_eq!(
hec_event.fields.get("key").map(|s| s.as_str()),
Some("value")
);
let now = Utc::now().timestamp_millis() as f64 / 1000f64;
assert!(
(hec_event.time - now).abs() < 0.2,
format!("hec_event.time = {}, now = {}", hec_event.time, now)
);
assert_eq!((hec_event.time * 1000f64).fract(), 0f64);
}
#[test]
fn splunk_encode_event_text() {
let mut event = Event::from("hello world");
event.as_mut_log().insert("key", "value");
let (config, _cx) = load_sink::<HecSinkConfig>(
r#"
host = "test.com"
token = "alksjdfo"
host_key = "host"
indexed_fields = ["key"]
[encoding]
codec = "text"
"#,
)
.unwrap();
let bytes = config.encode_event(event).unwrap();
let hec_event = serde_json::from_slice::<HecEventText>(&bytes[..]).unwrap();
assert_eq!(hec_event.event.as_str(), "hello world");
assert_eq!(
hec_event.fields.get("key").map(|s| s.as_str()),
Some("value")
);
let now = Utc::now().timestamp_millis() as f64 / 1000f64;
assert!(
(hec_event.time - now).abs() < 0.2,
format!("hec_event.time = {}, now = {}", hec_event.time, now)
);
assert_eq!((hec_event.time * 1000f64).fract(), 0f64);
}
#[test]
fn splunk_validate_host() {
let valid = "http://localhost:8888".to_string();
let invalid_scheme = "localhost:8888".to_string();
let invalid_uri = "iminvalidohnoes".to_string();
assert!(validate_host(&valid).is_ok());
assert!(validate_host(&invalid_scheme).is_err());
assert!(validate_host(&invalid_uri).is_err());
}
#[test]
fn splunk_build_uri() {
let uri = build_uri("http://test.com/", "/a");
assert!(uri.is_ok());
assert_eq!(format!("{}", uri.unwrap()), "http://test.com/a");
}
}
#[cfg(test)]
#[cfg(feature = "splunk-integration-tests")]
mod integration_tests {
use super::*;
use crate::test_util::retry_until;
use crate::{
assert_downcast_matches,
config::{SinkConfig, SinkContext},
sinks,
test_util::{random_lines_with_stream, random_string},
Event,
};
use futures::stream;
use serde_json::Value as JsonValue;
use std::{future::ready, net::SocketAddr};
use tokio::time::{delay_for, Duration};
use warp::Filter;
const USERNAME: &str = "admin";
const PASSWORD: &str = "password";
// It usually takes ~1 second for the event to show up in search, so poll until
// we see it.
async fn find_entry(message: &str) -> serde_json::value::Value {
for _ in 0..20usize {
match recent_entries(None)
.await
.into_iter()
.find(|entry| entry["_raw"].as_str().unwrap_or("").contains(&message))
{
Some(value) => return value,
None => std::thread::sleep(std::time::Duration::from_millis(100)),
}
}
panic!("Didn't find event in Splunk");
}
#[tokio::test]
async fn splunk_insert_message() {
let cx = SinkContext::new_test();
let config = config(Encoding::Text, vec![]).await;
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let event = Event::from(message.clone());
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(message, entry["_raw"].as_str().unwrap());
assert!(entry.get("message").is_none());
}
#[tokio::test]
async fn splunk_insert_source() {
let cx = SinkContext::new_test();
let mut config = config(Encoding::Text, vec![]).await;
config.source = Template::try_from("/var/log/syslog".to_string()).ok();
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let event = Event::from(message.clone());
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(entry["source"].as_str(), Some("/var/log/syslog"));
}
#[tokio::test]
async fn splunk_insert_index() {
let cx = SinkContext::new_test();
let mut config = config(Encoding::Text, vec![]).await;
config.index = Some("custom_index".to_string());
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let event = Event::from(message.clone());
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(entry["index"].as_str().unwrap(), "custom_index");
}
#[tokio::test]
async fn splunk_insert_many() {
let cx = SinkContext::new_test();
let config = config(Encoding::Text, vec![]).await;
let (sink, _) = config.build(cx).await.unwrap();
let (messages, events) = random_lines_with_stream(100, 10);
sink.run(events).await.unwrap();
let mut found_all = false;
for _ in 0..20 {
let entries = recent_entries(None).await;
found_all = messages.iter().all(|message| {
entries
.iter()
.any(|entry| entry["_raw"].as_str().unwrap() == message)
});
if found_all {
break;
}
delay_for(Duration::from_millis(100)).await;
}
assert!(found_all);
}
#[tokio::test]
async fn splunk_custom_fields() {
let cx = SinkContext::new_test();
let indexed_fields = vec!["asdf".into()];
let config = config(Encoding::Json, indexed_fields).await;
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let mut event = Event::from(message.clone());
event.as_mut_log().insert("asdf", "hello");
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(message, entry["message"].as_str().unwrap());
let asdf = entry["asdf"].as_array().unwrap()[0].as_str().unwrap();
assert_eq!("hello", asdf);
}
#[tokio::test]
async fn splunk_hostname() {
let cx = SinkContext::new_test();
let indexed_fields = vec!["asdf".into()];
let config = config(Encoding::Json, indexed_fields).await;
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let mut event = Event::from(message.clone());
event.as_mut_log().insert("asdf", "hello");
event.as_mut_log().insert("host", "example.com:1234");
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(message, entry["message"].as_str().unwrap());
let asdf = entry["asdf"].as_array().unwrap()[0].as_str().unwrap();
assert_eq!("hello", asdf);
let host = entry["host"].as_array().unwrap()[0].as_str().unwrap();
assert_eq!("example.com:1234", host);
}
#[tokio::test]
async fn splunk_sourcetype() {
let cx = SinkContext::new_test();
let indexed_fields = vec!["asdf".to_string()];
let mut config = config(Encoding::Json, indexed_fields).await;
config.sourcetype = Template::try_from("_json".to_string()).ok();
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let mut event = Event::from(message.clone());
event.as_mut_log().insert("asdf", "hello");
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(message, entry["message"].as_str().unwrap());
let asdf = entry["asdf"].as_array().unwrap()[0].as_str().unwrap();
assert_eq!("hello", asdf);
let sourcetype = entry["sourcetype"].as_str().unwrap();
assert_eq!("_json", sourcetype);
}
#[tokio::test]
async fn splunk_configure_hostname() {
let cx = SinkContext::new_test();
let config = HecSinkConfig {
host_key: "roast".into(),
..config(Encoding::Json, vec!["asdf".to_string()]).await
};
let (sink, _) = config.build(cx).await.unwrap();
let message = random_string(100);
let mut event = Event::from(message.clone());
event.as_mut_log().insert("asdf", "hello");
event.as_mut_log().insert("host", "example.com:1234");
event.as_mut_log().insert("roast", "beef.example.com:1234");
sink.run(stream::once(ready(event))).await.unwrap();
let entry = find_entry(message.as_str()).await;
assert_eq!(message, entry["message"].as_str().unwrap());
let asdf = entry["asdf"].as_array().unwrap()[0].as_str().unwrap();
assert_eq!("hello", asdf);
let host = entry["host"].as_array().unwrap()[0].as_str(
8
).unwrap
BA10
();
assert_eq!("beef.example.com:1234", host);
}
#[tokio::test]
async fn splunk_healthcheck() {
let config_to_healthcheck = move |config: HecSinkConfig| {
let tls_settings = TlsSettings::from_options(&config.tls).unwrap();
let client = HttpClient::new(tls_settings).unwrap();
sinks::splunk_hec::healthcheck(config, client)
};
// OK
{
let config = config(Encoding::Text, vec![]).await;
let healthcheck = config_to_healthcheck(config);
healthcheck.await.unwrap();
}
// Server not listening at address
{
let config = HecSinkConfig {
endpoint: "http://localhost:1111".to_string(),
..config(Encoding::Text, vec![]).await
};
let healthcheck = config_to_healthcheck(config);
healthcheck.await.unwrap_err();
}
// Invalid token
// The HEC REST docs claim that the healthcheck endpoint will validate the auth token,
// but my local testing server returns 200 even with a bad token.
// {
// let healthcheck = sinks::splunk::healthcheck(
// "wrong".to_string(),
// "http://localhost:8088".to_string(),
// )
// .unwrap();
// assert_eq!(rt.block_on(healthcheck).unwrap_err(), "Invalid HEC token");
// }
// Unhealthy server
{
let config = HecSinkConfig {
endpoint: "http://localhost:5503".to_string(),
..config(Encoding::Text, vec![]).await
};
let unhealthy = warp::any()
.map(|| warp::reply::with_status("i'm sad", StatusCode::SERVICE_UNAVAILABLE));
let server = warp::serve(unhealthy).bind("0.0.0.0:5503".parse::<SocketAddr>().unwrap());
tokio::spawn(server);
let healthcheck = config_to_healthcheck(config);
assert_downcast_matches!(
healthcheck.await.unwrap_err(),
HealthcheckError,
HealthcheckError::QueuesFull
);
}
}
async fn recent_entries(index: Option<&str>) -> Vec<JsonValue> {
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
// https://docs.splunk.com/Documentation/Splunk/7.2.1/RESTREF/RESTsearch#search.2Fjobs
let search_query = match index {
Some(index) => format!("search index={}", index),
None => "search *".into(),
};
let res = client
.post("https://localhost:8089/services/search/jobs?output_mode=json")
.form(&vec![
("search", &search_query[..]),
("exec_mode", "oneshot"),
("f", "*"),
])
.basic_auth(USERNAME, Some(PASSWORD))
.send()
.await
.unwrap();
let json: JsonValue = res.json().await.unwrap();
println!("output: {:?}", json);
json["results"].as_array().unwrap().clone()
}
async fn config(
encoding: impl Into<EncodingConfigWithDefault<Encoding>>,
indexed_fields: Vec<String>,
) -> HecSinkConfig {
HecSinkConfig {
endpoint: "http://localhost:8088/".into(),
token: get_token().await,
host_key: "host".into(),
compression: Compression::None,
encoding: encoding.into(),
batch: BatchConfig {
max_events: Some(1),
..Default::default()
},
indexed_fields,
..Default::default()
}
}
async fn get_token() -> String {
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
let res = retry_until(
|| {
client
.get("https://localhost:8089/services/data/inputs/http?output_mode=json")
.basic_auth(USERNAME, Some(PASSWORD))
.send()
},
Duration::from_millis(500),
Duration::from_secs(30),
)
.await;
let json: JsonValue = res.json().await.unwrap();
let entries = json["entry"].as_array().unwrap().clone();
if entries.is_empty() {
// TODO: create one automatically
panic!("You don't have any HTTP Event Collector inputs set up in Splunk");
}
entries[0]["content"]["token"].as_str().unwrap().to_owned()
}
}