1pub const COMMANDS_ALL: &str = "commands.all";
2
3pub fn commands_group(name: &str) -> String {
4 format!("commands.group.{name}")
5}
6
7pub fn commands_pc(pc_id: &str) -> String {
8 format!("commands.pc.{pc_id}")
9}
10
11pub fn results(request_id: &str) -> String {
19 format!("results.{request_id}")
20}
21
22pub fn heartbeat(pc_id: &str) -> String {
23 format!("heartbeat.{pc_id}")
24}
25
26pub fn kill(exec_id: &str) -> String {
31 format!("kill.{exec_id}")
32}
33
34pub fn inventory(pc_id: &str, category: &str) -> String {
35 format!("inventory.{pc_id}.{category}")
36}
37
38pub fn events_started(exec_id: &str, pc_id: &str) -> String {
45 format!("events.started.{exec_id}.{pc_id}")
46}
47
48pub const EVENTS_STARTED_FILTER: &str = "events.started.>";
53
54pub const INVENTORY_HW: &str = "hw";
55pub const INVENTORY_SW: &str = "sw";
56pub const INVENTORY_NET: &str = "net";
57
58pub fn logs_fetch(pc_id: &str) -> String {
62 format!("logs.fetch.{pc_id}")
63}
64
65#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn commands_all_constant() {
77 assert_eq!(COMMANDS_ALL, "commands.all");
78 }
79
80 #[test]
81 fn commands_group_formats_name() {
82 assert_eq!(commands_group("canary"), "commands.group.canary");
83 assert_eq!(commands_group("wave1"), "commands.group.wave1");
84 }
85
86 #[test]
87 fn commands_pc_formats_id() {
88 assert_eq!(commands_pc("minipc"), "commands.pc.minipc");
89 assert_eq!(commands_pc("PC1234"), "commands.pc.PC1234");
90 }
91
92 #[test]
93 fn results_formats_request_id() {
94 assert_eq!(results("req-1"), "results.req-1");
95 }
96
97 #[test]
98 fn heartbeat_formats_pc_id() {
99 assert_eq!(heartbeat("minipc"), "heartbeat.minipc");
100 }
101
102 #[test]
103 fn kill_formats_exec_id() {
104 assert_eq!(kill("exec-uuid-1"), "kill.exec-uuid-1");
105 }
106
107 #[test]
108 fn logs_fetch_formats_pc_id() {
109 assert_eq!(logs_fetch("minipc"), "logs.fetch.minipc");
110 }
111
112 #[test]
113 fn events_started_formats_exec_id_and_pc_id() {
114 assert_eq!(
115 events_started("exec-uuid-1", "minipc"),
116 "events.started.exec-uuid-1.minipc",
117 );
118 }
119
120 #[test]
121 fn events_started_filter_is_narrow_wildcard() {
122 assert_eq!(EVENTS_STARTED_FILTER, "events.started.>");
123 }
124
125 #[test]
126 fn inventory_formats_pc_id_and_category() {
127 assert_eq!(inventory("minipc", "hw"), "inventory.minipc.hw");
128 assert_eq!(inventory("minipc", INVENTORY_HW), "inventory.minipc.hw");
129 assert_eq!(inventory("minipc", INVENTORY_SW), "inventory.minipc.sw");
130 assert_eq!(inventory("minipc", INVENTORY_NET), "inventory.minipc.net");
131 }
132}