@SuppressWarnings("unchecked") @Test public void testUploadAssetGroupCountStats() throws Exception{ PowerMockito.mockStatic(AssetGroupUtil.class); List<Map<String, Object>> typeCounts = new ArrayList<>(); Map<String, Object> typeCount = new HashMap<>(); typeCount.put("type", "ec2"); typeCount.put("count", 125l); typeCounts.add(typeCount); when(AssetGroupUtil.fetchTypeCounts(anyString(),anyString(),anyString())).thenReturn(typeCounts); Map<String, Map<String, Map<String, Object>>> currentInfo = new HashMap<>(); Map<String, Object> minMax = new HashMap<>(); minMax.put("min", 100); minMax.put("max", 120); Map<String, Map<String, Object>> typeMap = new HashMap<>(); typeMap.put("ec2", minMax); currentInfo.put("pacman", typeMap); PowerMockito.mockStatic(ESManager.class); when(ESManager.fetchCurrentCountStatsForAssetGroups(anyString())).thenReturn(currentInfo); doNothing().when(ESManager.class); ESManager.uploadData(anyString(), anyString(), anyList(), anyString(), anyBoolean()); Map<String, List<String>> assetGroups = new HashMap<>(); List<String> domains = new ArrayList<>(); domains.add("infra"); assetGroups.put("pacman", domains); assetGroupStatsCollector.uploadAssetGroupCountStats(Arrays.asList("pacman")); }
public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception { log.info(" Start Collecing Asset count"); Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager .fetchCurrentCountStatsForAssetGroups(CURR_DATE); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken()); Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag); typeCounts.forEach(typeCount -> { String type = typeCount.get("type").toString(); long count = Long.valueOf(typeCount.get("count").toString()); long min; long max; if (currInfoMap != null) { Map<String, Object> _minMax = currInfoMap.get(type); long _min; long _max; if (_minMax != null) { _min = Long.valueOf(_minMax.get("min").toString()); _max = Long.valueOf(_minMax.get("max").toString()); } else { _min = count; _max = count; } min = count < _min ? count : _min; max = count > _max ? count : _max; } else { min = count; max = count; } Map<String, Object> doc = new HashMap<>(); doc.put("ag", ag); doc.put("type", type); doc.put("min", min); doc.put("max", max); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE)); docs.add(doc); }); } catch (Exception e) { log.error("Exception in uploadAssetGroupCountStats" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false); log.info(" End Collecing Asset count"); }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception { log.info(" Start Collecing Asset count"); Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager .fetchCurrentCountStatsForAssetGroups(CURR_DATE); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken()); Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag); typeCounts.forEach(typeCount -> { String type = typeCount.get("type").toString(); long count = Long.valueOf(typeCount.get("count").toString()); long min; long max; if (currInfoMap != null) { Map<String, Object> _minMax = currInfoMap.get(type); long _min; long _max; if (_minMax != null) { _min = Long.valueOf(_minMax.get("min").toString()); _max = Long.valueOf(_minMax.get("max").toString()); } else { _min = count; _max = count; } min = count < _min ? count : _min; max = count > _max ? count : _max; } else { min = count; max = count; } Map<String, Object> doc = new HashMap<>(); doc.put("ag", ag); doc.put("type", type); doc.put("min", min); doc.put("max", max); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE)); docs.add(doc); }); } catch (Exception e) { log.error("Exception in uploadAssetGroupCountStats" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false); log.info(" End Collecing Asset count"); } }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception { log.info(" Start Collecing Asset count"); Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager .fetchCurrentCountStatsForAssetGroups(CURR_DATE); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken()); Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag); typeCounts.forEach(typeCount -> { String type = typeCount.get("type").toString(); long count = Long.valueOf(typeCount.get("count").toString()); long min; long max; if (currInfoMap != null) { Map<String, Object> _minMax = currInfoMap.get(type); long _min; long _max; if (_minMax != null) { _min = Long.valueOf(_minMax.get("min").toString()); _max = Long.valueOf(_minMax.get("max").toString()); } else { _min = count; _max = count; } min = count < _min ? count : _min; max = count > _max ? count : _max; } else { min = count; max = count; } Map<String, Object> doc = new HashMap<>(); doc.put("ag", ag); doc.put("type", type); doc.put("min", min); doc.put("max", max); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE)); docs.add(doc); }); } catch (Exception e) { log.error("Exception in uploadAssetGroupCountStats" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false); log.info(" End Collecing Asset count"); }  }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception { log.info(" Start Collecing Asset count"); Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager .fetchCurrentCountStatsForAssetGroups(CURR_DATE); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken()); Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag); typeCounts.forEach(typeCount -> { String type = typeCount.get("type").toString(); long count = Long.valueOf(typeCount.get("count").toString()); long min; long max; if (currInfoMap != null) { Map<String, Object> _minMax = currInfoMap.get(type); long _min; long _max; if (_minMax != null) { _min = Long.valueOf(_minMax.get("min").toString()); _max = Long.valueOf(_minMax.get("max").toString()); } else { _min = count; _max = count; } min = count < _min ? count : _min; max = count > _max ? count : _max; } else { min = count; max = count; } Map<String, Object> doc = new HashMap<>(); doc.put("ag", ag); doc.put("type", type); doc.put("min", min); doc.put("max", max); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE)); docs.add(doc); }); } catch (Exception e) { log.error("Exception in uploadAssetGroupCountStats" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false); log.info(" End Collecing Asset count"); }  List<Map<String, String>> collectAssetGroupStats(); void uploadAssetGroupTagCompliance(List<String> assetGroups); void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCountStats(List<String> assetGroups); void uploadAssetGroupIssues(Map<String, List<String>> assetGroups); void uploadAssetGroupVulnCompliance(List<String> assetGroups); }
AssetGroupStatsCollector implements Constants { public void uploadAssetGroupCountStats(List<String> assetGroups) throws Exception { log.info(" Start Collecing Asset count"); Map<String, Map<String, Map<String, Object>>> currentInfo = ESManager .fetchCurrentCountStatsForAssetGroups(CURR_DATE); List<Map<String, Object>> docs = new ArrayList<>(); for (String ag : assetGroups) { try { List<Map<String, Object>> typeCounts = AssetGroupUtil.fetchTypeCounts(ASSET_API_URL, ag,getToken()); Map<String, Map<String, Object>> currInfoMap = currentInfo.get(ag); typeCounts.forEach(typeCount -> { String type = typeCount.get("type").toString(); long count = Long.valueOf(typeCount.get("count").toString()); long min; long max; if (currInfoMap != null) { Map<String, Object> _minMax = currInfoMap.get(type); long _min; long _max; if (_minMax != null) { _min = Long.valueOf(_minMax.get("min").toString()); _max = Long.valueOf(_minMax.get("max").toString()); } else { _min = count; _max = count; } min = count < _min ? count : _min; max = count > _max ? count : _max; } else { min = count; max = count; } Map<String, Object> doc = new HashMap<>(); doc.put("ag", ag); doc.put("type", type); doc.put("min", min); doc.put("max", max); doc.put("date", CURR_DATE); doc.put("@id", Util.getUniqueID(ag + type + CURR_DATE)); docs.add(doc); }); } catch (Exception e) { log.error("Exception in uploadAssetGroupCountStats" , e); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Exception in uploadAssetGroupCountStats for Asset Group"+ag); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); synchronized(errorList){ errorList.add(errorMap); } } } ESManager.uploadData(AG_STATS, "count_type", docs, "@id", false); log.info(" End Collecing Asset count"); }  List<Map<String, String>> collectAssetGroupStats(); void uploadAssetGroupTagCompliance(List<String> assetGroups); void uploadAssetGroupRuleCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCompliance(Map<String, List<String>> assetGroups); void uploadAssetGroupCountStats(List<String> assetGroups); void uploadAssetGroupIssues(Map<String, List<String>> assetGroups); void uploadAssetGroupVulnCompliance(List<String> assetGroups);  }