@Test public void testFetchVulnDistribution() throws Exception { String vulnResponse = "{\"data\":{\"response\":[{\"application\":\"PacMan\",\"applicationInfo\":[{\"environment\":\"Production\",\"vulnerabilities\":308,\"severityInfo\":[{\"severity\":\"S3\",\"vulnInstanceCount\":128,\"count\":128,\"severitylevel\":3},{\"severity\":\"S4\",\"vulnInstanceCount\":170,\"count\":170,\"severitylevel\":4},{\"severity\":\"S5\",\"vulnInstanceCount\":10,\"count\":10,\"severitylevel\":5}]},{\"environment\":\"Non Production\",\"vulnerabilities\":0,\"severityInfo\":[{\"severity\":\"S3\",\"vulnInstanceCount\":0,\"count\":0,\"severitylevel\":3},{\"severity\":\"S4\",\"vulnInstanceCount\":0,\"count\":0,\"severitylevel\":4},{\"severity\":\"S5\",\"vulnInstanceCount\":0,\"count\":0,\"severitylevel\":5}]}]}]},\"message\":\"success\"}"; when(HttpUtil.get(anyString(),anyString())).thenReturn(vulnResponse); List<Map<String, Object>> vulnDistribution = AssetGroupUtil.fetchVulnDistribution("", "",""); assertThat(vulnDistribution.get(0).get("tags.Application").toString(), is("PacMan")); assertThat(vulnDistribution.size(), is(6)); }
@SuppressWarnings("unchecked") public static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token) throws Exception { List<Map<String, Object>> vulnInfo = new ArrayList<>(); try { String typeCountJson = HttpUtil.get(api + "/vulnerabilities/distribution?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(typeCountJson); Map<String, List<Map<String, Object>>> data = (Map<String, List<Map<String, Object>>>) vulnMap.get("data"); List<Map<String, Object>> apps = data.get("response"); for (Map<String, Object> app : apps) { String application = app.get("application").toString(); List<Map<String, Object>> envs = (List<Map<String, Object>>) app.get("applicationInfo"); for (Map<String, Object> env : envs) { String environment = env.get("environment").toString(); List<Map<String, Object>> sevinfo = (List<Map<String, Object>>) env.get("severityInfo"); for (Map<String, Object> sev : sevinfo) { Map<String, Object> vuln = new HashMap<>(); vuln.put("tags.Application", application); vuln.put("tags.Environment", environment); vuln.put("severitylevel", sev.get("severitylevel")); vuln.put(SEVERITY, sev.get(SEVERITY)); vuln.put(COUNT, sev.get(COUNT)); vulnInfo.add(vuln); } } } } catch (Exception e) { LOGGER.error("Error in fetchVulnDistribution" , e); throw e; } return vulnInfo; }
AssetGroupUtil { @SuppressWarnings("unchecked") public static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token) throws Exception { List<Map<String, Object>> vulnInfo = new ArrayList<>(); try { String typeCountJson = HttpUtil.get(api + "/vulnerabilities/distribution?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(typeCountJson); Map<String, List<Map<String, Object>>> data = (Map<String, List<Map<String, Object>>>) vulnMap.get("data"); List<Map<String, Object>> apps = data.get("response"); for (Map<String, Object> app : apps) { String application = app.get("application").toString(); List<Map<String, Object>> envs = (List<Map<String, Object>>) app.get("applicationInfo"); for (Map<String, Object> env : envs) { String environment = env.get("environment").toString(); List<Map<String, Object>> sevinfo = (List<Map<String, Object>>) env.get("severityInfo"); for (Map<String, Object> sev : sevinfo) { Map<String, Object> vuln = new HashMap<>(); vuln.put("tags.Application", application); vuln.put("tags.Environment", environment); vuln.put("severitylevel", sev.get("severitylevel")); vuln.put(SEVERITY, sev.get(SEVERITY)); vuln.put(COUNT, sev.get(COUNT)); vulnInfo.add(vuln); } } } } catch (Exception e) { LOGGER.error("Error in fetchVulnDistribution" , e); throw e; } return vulnInfo; } }
AssetGroupUtil { @SuppressWarnings("unchecked") public static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token) throws Exception { List<Map<String, Object>> vulnInfo = new ArrayList<>(); try { String typeCountJson = HttpUtil.get(api + "/vulnerabilities/distribution?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(typeCountJson); Map<String, List<Map<String, Object>>> data = (Map<String, List<Map<String, Object>>>) vulnMap.get("data"); List<Map<String, Object>> apps = data.get("response"); for (Map<String, Object> app : apps) { String application = app.get("application").toString(); List<Map<String, Object>> envs = (List<Map<String, Object>>) app.get("applicationInfo"); for (Map<String, Object> env : envs) { String environment = env.get("environment").toString(); List<Map<String, Object>> sevinfo = (List<Map<String, Object>>) env.get("severityInfo"); for (Map<String, Object> sev : sevinfo) { Map<String, Object> vuln = new HashMap<>(); vuln.put("tags.Application", application); vuln.put("tags.Environment", environment); vuln.put("severitylevel", sev.get("severitylevel")); vuln.put(SEVERITY, sev.get(SEVERITY)); vuln.put(COUNT, sev.get(COUNT)); vulnInfo.add(vuln); } } } } catch (Exception e) { LOGGER.error("Error in fetchVulnDistribution" , e); throw e; } return vulnInfo; } private  AssetGroupUtil(); }
AssetGroupUtil { @SuppressWarnings("unchecked") public static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token) throws Exception { List<Map<String, Object>> vulnInfo = new ArrayList<>(); try { String typeCountJson = HttpUtil.get(api + "/vulnerabilities/distribution?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(typeCountJson); Map<String, List<Map<String, Object>>> data = (Map<String, List<Map<String, Object>>>) vulnMap.get("data"); List<Map<String, Object>> apps = data.get("response"); for (Map<String, Object> app : apps) { String application = app.get("application").toString(); List<Map<String, Object>> envs = (List<Map<String, Object>>) app.get("applicationInfo"); for (Map<String, Object> env : envs) { String environment = env.get("environment").toString(); List<Map<String, Object>> sevinfo = (List<Map<String, Object>>) env.get("severityInfo"); for (Map<String, Object> sev : sevinfo) { Map<String, Object> vuln = new HashMap<>(); vuln.put("tags.Application", application); vuln.put("tags.Environment", environment); vuln.put("severitylevel", sev.get("severitylevel")); vuln.put(SEVERITY, sev.get(SEVERITY)); vuln.put(COUNT, sev.get(COUNT)); vulnInfo.add(vuln); } } } } catch (Exception e) { LOGGER.error("Error in fetchVulnDistribution" , e); throw e; } return vulnInfo; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token); }
AssetGroupUtil { @SuppressWarnings("unchecked") public static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token) throws Exception { List<Map<String, Object>> vulnInfo = new ArrayList<>(); try { String typeCountJson = HttpUtil.get(api + "/vulnerabilities/distribution?ag=" + ag,token); Map<String, Object> vulnMap = Util.parseJson(typeCountJson); Map<String, List<Map<String, Object>>> data = (Map<String, List<Map<String, Object>>>) vulnMap.get("data"); List<Map<String, Object>> apps = data.get("response"); for (Map<String, Object> app : apps) { String application = app.get("application").toString(); List<Map<String, Object>> envs = (List<Map<String, Object>>) app.get("applicationInfo"); for (Map<String, Object> env : envs) { String environment = env.get("environment").toString(); List<Map<String, Object>> sevinfo = (List<Map<String, Object>>) env.get("severityInfo"); for (Map<String, Object> sev : sevinfo) { Map<String, Object> vuln = new HashMap<>(); vuln.put("tags.Application", application); vuln.put("tags.Environment", environment); vuln.put("severitylevel", sev.get("severitylevel")); vuln.put(SEVERITY, sev.get(SEVERITY)); vuln.put(COUNT, sev.get(COUNT)); vulnInfo.add(vuln); } } } } catch (Exception e) { LOGGER.error("Error in fetchVulnDistribution" , e); throw e; } return vulnInfo; } private  AssetGroupUtil(); @SuppressWarnings("unchecked") static Map<String, List<String>> fetchAssetGroups(String asstApiUri,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchTypeCounts(String asstApiUri, String ag,String token); static Map<String, Object> fetchPatchingCompliance(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchVulnDistribution(String api, String ag ,String token); @SuppressWarnings("unchecked") static List<Map<String, Object>> fetchComplianceInfo(String apiUrl, String ag, List<String> domains ,String token); static List<Map<String, Object>> fetchRuleComplianceInfo(String compapiuri, String ag,
            List<String> domains ,String token); static Map<String, Object> fetchVulnSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchTaggingSummary(String compapiuri, String ag ,String token); static Map<String, Object> fetchCertSummary(String compapiuri, String ag ,String token); static List<Map<String, Object>> fetchIssuesInfo(String compapiuri, String ag, List<String> domains ,String token);  }