Skip to content

Commit

Permalink
Improve result output (#26)
Browse files Browse the repository at this point in the history
* Added a 'no results' status to the comparisons on the status page in GUI.

* Adds summary file for cli collect output. If there are no results there is no output files so this clarifies why that would be the case.
  • Loading branch information
gfs committed Mar 31, 2019
1 parent c69f5cb commit 61680c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
5 changes: 2 additions & 3 deletions AttackSurfaceAnalyzer.sln
Expand Up @@ -2,19 +2,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2037
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerGui", "Gui\AttackSurfaceAnalyzerGui.csproj", "{2B0AC364-0713-406C-8B07-795574F15EC6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttackSurfaceAnalyzerGui", "Gui\AttackSurfaceAnalyzerGui.csproj", "{2B0AC364-0713-406C-8B07-795574F15EC6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerLib", "Lib\AttackSurfaceAnalyzerLib.csproj", "{5069C7AB-2264-4768-AB42-358251B0863A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AttackSurfaceAnalyzerCli", "Cli\AttackSurfaceAnalyzerCli.csproj", "{431FFEB4-57C2-4C5B-B329-DDF6ED229C3A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AttackSurfaceAnalyzerCli", "Cli\AttackSurfaceAnalyzerCli.csproj", "{431FFEB4-57C2-4C5B-B329-DDF6ED229C3A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0E30E3FA-AECD-4BF3-9EAA-9D6C16D5E991}"
ProjectSection(SolutionItems) = preProject
BUILD.md = BUILD.md
CONTRIBUTING.md = CONTRIBUTING.md
global.json = global.json
LICENSE = LICENSE
NOTICE.txt = NOTICE.txt
PRIVACY.md = PRIVACY.md
README.md = README.md
version.json = version.json
Expand Down
28 changes: 21 additions & 7 deletions Cli/Program.cs
Expand Up @@ -249,11 +249,18 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId
string GET_SERIALIZED_RESULTS = "select serialized from @table_name where row_key = @row_key and run_id = @run_id";

List<RESULT_TYPE> ToExport = new List<RESULT_TYPE> { (RESULT_TYPE)ResultType };

Dictionary<RESULT_TYPE, int> actualExported = new Dictionary<RESULT_TYPE, int>();
JsonSerializer serializer = new JsonSerializer
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
if (ExportAll)
{
ToExport = new List<RESULT_TYPE> { RESULT_TYPE.FILE, RESULT_TYPE.CERTIFICATE, RESULT_TYPE.PORT, RESULT_TYPE.REGISTRY, RESULT_TYPE.SERVICES, RESULT_TYPE.USER };
}


foreach (RESULT_TYPE ExportType in ToExport)
{
List<CompareResult> records = new List<CompareResult>();
Expand Down Expand Up @@ -356,17 +363,13 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId
records.Add(obj);
}
}
actualExported.Add(ExportType, records.Count());


if (records.Count > 0)
{
//telemetry.GetMetric("ResultsExported").TrackValue(records.Count);

JsonSerializer serializer = new JsonSerializer
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};

serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());

using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, Helpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_" + ExportType.ToString() + ".json.txt")))) //lgtm[cs/path-injection]
Expand All @@ -378,6 +381,17 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId
}
}
}

serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());

using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, Helpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_summary.json.txt")))) //lgtm[cs/path-injection]
{
using (JsonWriter writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer, actualExported);
}
}

}

private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts)
Expand Down
14 changes: 12 additions & 2 deletions Gui/wwwroot/js/Analyze.js
Expand Up @@ -190,12 +190,22 @@ function GetResultTypes() {

function UpdateNumResults(total, offset, requested, actual) {
$('#CountStatus').empty();
$("#CountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records.");
if (actual == 0){
$("#CountStatus").append("No difference detected.");
}
else{
$("#CountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records.");
}
}

function UpdateMonitorNumResults(total, offset, requested, actual) {
$('#MonitorCountStatus').empty();
$("#MonitorCountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records.");
if (actual == 0){
$("#CountStatus").append("No difference detected.");
}
else{
$("#MonitorCountStatus").append("Showing " + (offset + 1) + " to " + (offset + actual) + " results. " + total + " total records.");
}
}

function GetResults(type, offset, number) {
Expand Down

0 comments on commit 61680c5

Please sign in to comment.