public static SimulationExerciseResult GetSimulationExerciseResult(string results) { SimulationExerciseResult simulationresult = new SimulationExerciseResult(); simulationresult.playbookresults = new List <SimulationPlaybookResult>(); string[] lines = results.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string strip = ""; if (lines[i].Contains("Running Playbook")) { SimulationPlaybookResult playbookresult = new SimulationPlaybookResult(); List <PlaybookTaskResult> taskresults = new List <PlaybookTaskResult>(); PlaybookTaskResult taskresult = new PlaybookTaskResult(); List <TaskDebugMsg> debugmsgs = new List <TaskDebugMsg>(); strip = lines[i].Substring(lines[i].LastIndexOf("]") + 1).Replace("Running Playbook", "").Trim(); playbookresult.name = strip; bool finished = false; int skipped = 0; for (int k = i + 1; finished == false; k++) { if (lines[k].Contains("Starting")) { taskresult.timestamp = lines[i].Substring(0, lines[i].IndexOf('[')).Trim(); strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Starting ", "").Replace("Simulation on ", "").Trim(); taskresult.technique = strip.Split(' ')[0]; playbookresult.host = strip.Split(' ')[1]; } else if (lines[k].Contains("Simulator")) { strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "|").Replace("as ", "|").Trim(); playbookresult.simprocess = strip.Split('|')[0].TrimEnd(); playbookresult.simprocessid = Int32.Parse(strip.Split('|')[1]); playbookresult.user = strip.Split('|')[2]; } else if (lines[k].Contains("Simulation Finished")) { //finished = true; taskresult.success = true; taskresult.debugmsgs = debugmsgs; taskresults.Add(taskresult); //playbookresult.taskresults = taskresults; taskresult = new PlaybookTaskResult(); debugmsgs = new List <TaskDebugMsg>(); } else if (lines[k].Contains("Simulation Failed")) { //finished = true; taskresult.success = false; taskresult.debugmsgs = debugmsgs; taskresults.Add(taskresult); //playbookresult.taskresults = taskresults; taskresult = new PlaybookTaskResult(); debugmsgs = new List <TaskDebugMsg>(); } else if (lines[k].Contains("Playbook Finished")) { finished = true; } else { TaskDebugMsg debugmsg = new TaskDebugMsg(); debugmsg.msg = lines[k]; debugmsgs.Add(debugmsg); } skipped += 1; } i += skipped; playbookresult.taskresults = taskresults; simulationresult.playbookresults.Add(playbookresult); } } return(simulationresult); }
public static void WriteJsonSimulationResults(SimulationExerciseResult engagementResult, string outputfile) { File.WriteAllText(outputfile, JsonConvert.SerializeObject(engagementResult)); }
public static void WriteJsonPlaybookResults(SimulationExerciseResult engagementResult) { File.WriteAllText("result.json", JsonConvert.SerializeObject(engagementResult)); }