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 host_perf(pc_id: &str) -> String {
33 format!("host_perf.{pc_id}")
34}
35
36pub fn kill(exec_id: &str) -> String {
41 format!("kill.{exec_id}")
42}
43
44pub fn inventory(pc_id: &str, category: &str) -> String {
45 format!("inventory.{pc_id}.{category}")
46}
47
48pub fn events_started(exec_id: &str, pc_id: &str) -> String {
55 format!("events.started.{exec_id}.{pc_id}")
56}
57
58pub const EVENTS_STARTED_FILTER: &str = "events.started.>";
63
64pub const INVENTORY_HW: &str = "hw";
65pub const INVENTORY_SW: &str = "sw";
66pub const INVENTORY_NET: &str = "net";
67
68pub fn logs_fetch(pc_id: &str) -> String {
72 format!("logs.fetch.{pc_id}")
73}
74
75pub fn ping(pc_id: &str) -> String {
82 format!("agents.{pc_id}.ping")
83}
84
85#[cfg(test)]
92mod tests {
93 use super::*;
94
95 #[test]
96 fn commands_all_constant() {
97 assert_eq!(COMMANDS_ALL, "commands.all");
98 }
99
100 #[test]
101 fn commands_group_formats_name() {
102 assert_eq!(commands_group("canary"), "commands.group.canary");
103 assert_eq!(commands_group("wave1"), "commands.group.wave1");
104 }
105
106 #[test]
107 fn commands_pc_formats_id() {
108 assert_eq!(commands_pc("minipc"), "commands.pc.minipc");
109 assert_eq!(commands_pc("PC1234"), "commands.pc.PC1234");
110 }
111
112 #[test]
113 fn results_formats_request_id() {
114 assert_eq!(results("req-1"), "results.req-1");
115 }
116
117 #[test]
118 fn heartbeat_formats_pc_id() {
119 assert_eq!(heartbeat("minipc"), "heartbeat.minipc");
120 }
121
122 #[test]
123 fn host_perf_formats_pc_id() {
124 assert_eq!(host_perf("minipc"), "host_perf.minipc");
125 assert_eq!(host_perf("PC1234"), "host_perf.PC1234");
126 }
127
128 #[test]
129 fn kill_formats_exec_id() {
130 assert_eq!(kill("exec-uuid-1"), "kill.exec-uuid-1");
131 }
132
133 #[test]
134 fn logs_fetch_formats_pc_id() {
135 assert_eq!(logs_fetch("minipc"), "logs.fetch.minipc");
136 }
137
138 #[test]
139 fn ping_formats_pc_id() {
140 assert_eq!(ping("minipc"), "agents.minipc.ping");
141 }
142
143 #[test]
144 fn events_started_formats_exec_id_and_pc_id() {
145 assert_eq!(
146 events_started("exec-uuid-1", "minipc"),
147 "events.started.exec-uuid-1.minipc",
148 );
149 }
150
151 #[test]
152 fn events_started_filter_is_narrow_wildcard() {
153 assert_eq!(EVENTS_STARTED_FILTER, "events.started.>");
154 }
155
156 #[test]
157 fn inventory_formats_pc_id_and_category() {
158 assert_eq!(inventory("minipc", "hw"), "inventory.minipc.hw");
159 assert_eq!(inventory("minipc", INVENTORY_HW), "inventory.minipc.hw");
160 assert_eq!(inventory("minipc", INVENTORY_SW), "inventory.minipc.sw");
161 assert_eq!(inventory("minipc", INVENTORY_NET), "inventory.minipc.net");
162 }
163}