diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractImExportServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractImExportServiceImpl.java index c857a151395..96f74812f95 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractImExportServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractImExportServiceImpl.java @@ -61,12 +61,12 @@ public void importConfig(InputStream is) { .map(this::convert) .collect(Collectors.toUnmodifiableList()); if (!CollectionUtils.isEmpty(formList)) { - formList.forEach(it -> { - monitorService.validate(it, false); - if (it.isDetected()) { - monitorService.detectMonitor(it.getMonitor(), it.getParams(), it.getCollector()); + formList.forEach(monitorDto -> { + monitorService.validate(monitorDto, false); + if (monitorDto.isDetected()) { + monitorService.detectMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector()); } - monitorService.addMonitor(it.getMonitor(), it.getParams(), it.getCollector()); + monitorService.addMonitor(monitorDto.getMonitor(), monitorDto.getParams(), monitorDto.getCollector()); }); } } @@ -116,6 +116,7 @@ private ExportMonitorDTO convert(MonitorDto dto) { .collect(Collectors.toUnmodifiableList())); exportMonitor.setMetrics(dto.getMetrics()); exportMonitor.setDetected(false); + exportMonitor.getMonitor().setCollector(dto.getCollector()); return exportMonitor; } @@ -130,6 +131,7 @@ private MonitorDto convert(ExportMonitorDTO exportMonitor) { filter(tag -> !(tag.getName().equals(CommonConstants.TAG_MONITOR_ID) || tag.getName().equals(CommonConstants.TAG_MONITOR_NAME))) .collect(Collectors.toList())); monitorDto.setMonitor(monitor); + monitorDto.setCollector(exportMonitor.getMonitor().getCollector()); monitorDto.setMetrics(exportMonitor.metrics); monitorDto.setParams(exportMonitor.params.stream() .map(it -> { @@ -181,6 +183,8 @@ protected static class MonitorDTO { private String description; @Excel(name = "Tags") private List tags; + @Excel(name = "Collector") + private String collector; } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/ExcelImExportServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/ExcelImExportServiceImpl.java index efa78097492..deffdb5993d 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/ExcelImExportServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/ExcelImExportServiceImpl.java @@ -77,12 +77,12 @@ public List parseImport(InputStream is) { ExportMonitorDTO exportMonitor = new ExportMonitorDTO(); exportMonitor.setMonitor(monitor); monitors.add(exportMonitor); - String metrics = getCellValueAsString(row.getCell(10)); + String metrics = getCellValueAsString(row.getCell(11)); if (StringUtils.hasText(metrics)) { List metricList = Arrays.stream(metrics.split(",")).collect(Collectors.toList()); exportMonitor.setMetrics(metricList); } - boolean detected = getCellValueAsBoolean(row.getCell(11)); + boolean detected = getCellValueAsBoolean(row.getCell(12)); exportMonitor.setDetected(detected); } } @@ -133,17 +133,19 @@ private MonitorDTO extractMonitorDataFromRow(Row row) { .collect(Collectors.toList()); monitor.setTags(tags); } + monitor.setCollector(getCellValueAsString(row.getCell(7))); + return monitor; } private ParamDTO extractParamDataFromRow(Row row) { - String fieldName = getCellValueAsString(row.getCell(7)); + String fieldName = getCellValueAsString(row.getCell(8)); if (StringUtils.hasText(fieldName)) { ParamDTO param = new ParamDTO(); param.setField(fieldName); - param.setType(getCellValueAsByte(row.getCell(8))); - param.setValue(getCellValueAsString(row.getCell(9))); + param.setType(getCellValueAsByte(row.getCell(9))); + param.setValue(getCellValueAsString(row.getCell(10))); return param; } return null; @@ -220,7 +222,7 @@ void writeOs(List monitorList, OutputStream os) { CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); // 设置表头 - String[] headers = { "name", "app", "host", "intervals", "status", "description", "tags", "field", "type", "value", "metrics", "detected" }; + String[] headers = { "name", "app", "host", "intervals", "status", "description", "tags", "collector(default null if system dispatch)", "field", "type", "value", "metrics", "detected" }; Row headerRow = sheet.createRow(0); for (int i = 0; i < headers.length; i++) { Cell cell = headerRow.createCell(i); @@ -263,25 +265,28 @@ void writeOs(List monitorList, OutputStream os) { Cell tagsCell = row.createCell(6); tagsCell.setCellValue(monitorDTO.getTags().stream().map(Object::toString).collect(Collectors.joining(","))); tagsCell.setCellStyle(cellStyle); + Cell collectorCell = row.createCell(7); + collectorCell.setCellValue(monitorDTO.getCollector()); + collectorCell.setCellStyle(cellStyle); if (metricList != null && i < metricList.size()) { - Cell metricCell = row.createCell(10); + Cell metricCell = row.createCell(11); metricCell.setCellValue(String.join(",", metricList)); metricCell.setCellStyle(cellStyle); } - Cell detectedCell = row.createCell(11); + Cell detectedCell = row.createCell(12); detectedCell.setCellValue(monitor.getDetected() != null && monitor.getDetected()); detectedCell.setCellStyle(cellStyle); } // 填写参数信息 if (i < paramList.size()) { ParamDTO paramDTO = paramList.get(i); - Cell fieldCell = row.createCell(7); + Cell fieldCell = row.createCell(8); fieldCell.setCellValue(paramDTO.getField()); fieldCell.setCellStyle(cellStyle); - Cell typeCell = row.createCell(8); + Cell typeCell = row.createCell(9); typeCell.setCellValue(paramDTO.getType()); typeCell.setCellStyle(cellStyle); - Cell valueCell = row.createCell(9); + Cell valueCell = row.createCell(10); valueCell.setCellValue(paramDTO.getValue()); valueCell.setCellStyle(cellStyle); }