Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
puffyCid committed Dec 25, 2024
1 parent 7b9521e commit 8492c5e
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 145 deletions.
4 changes: 3 additions & 1 deletion core/src/artifacts/os/linux/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub(crate) fn output_data(
#[cfg(test)]
#[cfg(target_os = "linux")]
mod tests {
use serde_json::json;

use crate::artifacts::os::linux::artifacts::{journals, logons, output_data, sudo_logs_linux};
use crate::structs::artifacts::os::linux::{JournalOptions, LinuxSudoOptions, LogonOptions};
use crate::structs::toml::Output;
Expand Down Expand Up @@ -129,7 +131,7 @@ mod tests {
let start_time = time::time_now();

let name = "test";
let mut data = serde_json::Value::String(String::from("test"));
let mut data = json!({"test":"test"});
let status = output_data(&mut data, name, &mut output, &start_time, &&false).unwrap();
assert_eq!(status, ());
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/artifacts/os/macos/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ mod tests {
},
utils::time,
};
use serde_json::json;

fn output_options(name: &str, output: &str, directory: &str, compress: bool) -> Output {
Output {
Expand Down Expand Up @@ -539,7 +540,7 @@ mod tests {
let start_time = time::time_now();

let name = "test";
let data = serde_json::Value::String(String::from("test"));
let mut data = json!({"test":"test"});
let status = output_data(&data, name, &mut output, &start_time, &&false).unwrap();
assert_eq!(status, ());
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/artifacts/os/unix/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod tests {
structs::toml::Output,
utils::time,
};
use serde_json::json;

fn output_options(name: &str, output: &str, directory: &str, compress: bool) -> Output {
Output {
Expand Down Expand Up @@ -194,7 +195,7 @@ mod tests {
let start_time = time::time_now();

let name = "test";
let mut data = serde_json::Value::String(String::from("test"));
let mut data = json!({"test":"test"});
let status = output_data(&mut data, name, &mut output, &start_time, &false).unwrap();
assert_eq!(status, ());
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/artifacts/os/windows/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ mod tests {
},
utils::time,
};
use serde_json::json;
use std::path::PathBuf;

fn output_options(name: &str, format: &str, directory: &str, compress: bool) -> Output {
Expand Down Expand Up @@ -863,7 +864,7 @@ mod tests {
let start_time = time::time_now();

let name = "test";
let data = serde_json::Value::String(String::from("test"));
let mut data = json!({"test":"test"});
let status = output_data(&data, name, &mut output, &start_time, &false).unwrap();
assert_eq!(status, ());
}
Expand Down
26 changes: 23 additions & 3 deletions core/src/output/formats/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,33 @@ pub(crate) fn json_format(
// Get small amount of system metadata
let info = get_info_metadata();
let uuid = generate_uuid();
for values in serde_data.as_array_mut().unwrap_or(&mut Vec::new()) {
values["collection_metadata"] = json![{

let complete = unixepoch_to_iso(&(time_now() as i64));
if serde_data.is_array() {
for values in serde_data.as_array_mut().unwrap_or(&mut Vec::new()) {
if values.is_object() {
values["collection_metadata"] = json![{
"endpoint_id": output.endpoint_id,
"uuid": uuid,
"id": output.collection_id,
"artifact_name": output_name,
"complete_time": complete,
"start_time": unixepoch_to_iso(&(*start_time as i64)),
"hostname": info.hostname,
"os_version": info.os_version,
"platform": info.platform,
"kernel_version": info.kernel_version,
"load_performance": info.performance
}];
}
}
} else if serde_data.is_object() {
serde_data["collection_metadata"] = json![{
"endpoint_id": output.endpoint_id,
"uuid": uuid,
"id": output.collection_id,
"artifact_name": output_name,
"complete_time": unixepoch_to_iso(&(time_now() as i64)),
"complete_time": complete,
"start_time": unixepoch_to_iso(&(*start_time as i64)),
"hostname": info.hostname,
"os_version": info.os_version,
Expand Down
Loading

0 comments on commit 8492c5e

Please sign in to comment.