Created
May 27, 2016 11:50
-
-
Save neilstuartcraig/fb4047d3eec19686c9b8ceec2aa2c8ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Core deps | |
const path = require("path"); | |
const fs = require("fs"); | |
// Monolith PoC | |
let HARFile = path.join(__dirname, "/data/har2.js"); | |
fs.readFile(HARFile, (err, data) => | |
{ | |
if(err) | |
{ | |
console.error("Error reading HAR file '" + HARFile + "'"); | |
console.error(err); | |
} | |
else | |
{ | |
let HARData = JSON.parse(data); | |
let resultSet = {}; | |
if("log" in HARData) | |
{ | |
if("entries" in HARData.log) | |
{ | |
HARData.log.entries.forEach(function(entry) | |
{ | |
if("request" in entry) | |
{ | |
if(entry.request.method.toUpperCase() === "POST") | |
{ | |
if(entry.request.postData instanceof Object) | |
{ | |
if(entry.request.postData.mimeType === "application/csp-report") | |
{ | |
let reportData = JSON.parse(entry.request.postData.text); | |
let keys = | |
{ | |
blockedURI: reportData["csp-report"]["blocked-uri"], | |
violatedDirective: reportData["csp-report"]["violated-directive"], | |
effectiveDirective: reportData["csp-report"]["effective-directive"] | |
}; | |
for(let k in keys) | |
{ | |
let key = k; | |
let val = keys[k]; | |
if(!(key in resultSet)) | |
{ | |
resultSet[key] = {}; | |
} | |
if(val in resultSet[key]) | |
{ | |
resultSet[key][val][entry.response.status] = resultSet[key][val][entry.response.status] + 1 || 1; | |
} | |
else | |
{ | |
resultSet[key][val] = {}; | |
resultSet[key][val][entry.response.status] = 1; | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
console.log("Entries:"); | |
console.log(JSON.stringify(resultSet, null, 2)); | |
} | |
else | |
{ | |
console.error("ERROR: No log.entries array in HAR data"); | |
} | |
} | |
else | |
{ | |
console.error("ERROR: No log object in HAR data"); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is super quick and dirty but it'll do the job in at least most/many cases