1use datadog_protos::events::EventsPayload;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
6pub struct Event {
7 title: String,
8 text: String,
9 alert_type: String,
10 aggregation_key: String,
11 hostname: String,
12 priority: String,
13 source_type_name: String,
14 tags: Vec<String>,
15 pub timestamp: i64,
20}
21
22impl Event {
23 pub fn title(&self) -> &str {
25 &self.title
26 }
27
28 pub fn text(&self) -> &str {
30 &self.text
31 }
32
33 pub fn alert_type(&self) -> &str {
35 &self.alert_type
36 }
37
38 pub fn aggregation_key(&self) -> &str {
40 &self.aggregation_key
41 }
42
43 pub fn hostname(&self) -> &str {
45 &self.hostname
46 }
47
48 pub fn priority(&self) -> &str {
50 &self.priority
51 }
52
53 pub fn source_type_name(&self) -> &str {
55 &self.source_type_name
56 }
57
58 pub fn tags(&self) -> &[String] {
60 &self.tags
61 }
62
63 pub fn timestamp(&self) -> i64 {
65 self.timestamp
66 }
67
68 pub fn from_events_payload(payload: EventsPayload) -> Vec<Self> {
70 payload
71 .events
72 .into_iter()
73 .map(|e| {
74 let mut tags: Vec<String> = e.tags().iter().map(|t| t.to_string()).collect();
75 tags.sort_unstable();
76
77 Event {
78 title: e.title().to_string(),
79 text: e.text().to_string(),
80 alert_type: e.alert_type().to_string(),
81 aggregation_key: e.aggregation_key().to_string(),
82 hostname: e.host().to_string(),
83 priority: e.priority().to_string(),
84 source_type_name: e.source_type_name().to_string(),
85 tags,
86 timestamp: e.ts(),
87 }
88 })
89 .collect()
90 }
91
92 #[allow(clippy::too_many_arguments)]
94 pub fn from_intake_event(
95 title: String, text: String, alert_type: String, aggregation_key: String, hostname: String, priority: String,
96 source_type_name: String, mut tags: Vec<String>, timestamp: i64,
97 ) -> Self {
98 tags.sort_unstable();
99 Event {
100 title,
101 text,
102 alert_type,
103 aggregation_key,
104 hostname,
105 priority,
106 source_type_name,
107 tags,
108 timestamp,
109 }
110 }
111}