summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2023-07-31 17:26:03 +0800
committershizhendong <[email protected]>2023-07-31 17:26:03 +0800
commitf28d9cc8a66557e1c4a6d83537eaddd38f5ded87 (patch)
tree2875884a8ab3903bab29f71bdb62a20e409a0e38
parent577f38ef6b26693616e33dddbc1f5495530404fd (diff)
feat: NEZ-3011 新增资产配置同步更新接口
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java23
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/AssetAssetService.java9
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java76
-rw-r--r--nz-admin/src/main/java/com/nis/modules/endpoint/controller/MonitorEndpointController.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/endpoint/dao/MonitorEndpointDao.java3
-rw-r--r--nz-admin/src/main/java/com/nis/modules/endpoint/entity/MonitorEndpoint.java8
-rw-r--r--nz-admin/src/main/java/com/nis/modules/endpoint/service/MonitorEndpointService.java3
-rw-r--r--nz-admin/src/main/java/com/nis/modules/endpoint/service/impl/MonitorEndpointServiceImpl.java106
-rw-r--r--nz-admin/src/main/java/com/nis/modules/module/service/impl/MonitorModuleServiceImpl.java3
-rw-r--r--nz-admin/src/main/resources/mapper/endpoint/MonitorEndpointDao.xml68
10 files changed, 264 insertions, 37 deletions
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
index 5c8d4a63..eac3ff1a 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
@@ -303,6 +303,29 @@ public class AssetController {
assetAssetService.bulkEdit(params);
return R.ok();
}
+
+
+ /**
+ * 资产配置同步更新 dashboard,endpoint
+ *
+ * @return
+ */
+ @RequestMapping(value = "/asset/sync", method = {RequestMethod.POST, RequestMethod.PUT})
+ @SysLog(operation = OperationEnum.UPDATE, type = TypeEnum.ASSET)
+ public R syncAssetEndpointAndDashboard(@RequestBody(required = false) Map<String, Object> requestParam) {
+ // validate param
+ requestParam = Tool.MapUtil.defaultIfEmpty(requestParam, Tool.MapUtil.empty());
+
+ List<Integer> syncAssetIdList = (List<Integer>) requestParam.get("ids");
+ ValidateUtils.is(syncAssetIdList).notNull(RCode.ASSET_ID_ISNULL);
+
+ Integer isSyncEndpoint = Tool.MapUtil.getInt(requestParam, "endpoint", 0);
+ Integer isSyncDashboard = Tool.MapUtil.getInt(requestParam, "dashboard", 0);
+
+ assetAssetService.syncAssetEndpointAndDashboard(syncAssetIdList, isSyncEndpoint, isSyncDashboard);
+ return R.ok();
+ }
+
@GetMapping("/stateConf")
@SysLog(operation = OperationEnum.QUERY, type = TypeEnum.ASSETSTATECONF)
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetAssetService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetAssetService.java
index 1daa96b8..c3df9427 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetAssetService.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetAssetService.java
@@ -113,4 +113,13 @@ public interface AssetAssetService extends IService<AssetAsset> {
* @return
*/
List<AssetAsset> getDiscoveredAssetInfoList();
+
+ /**
+ * sync Asset Endpoint And Dashboard
+ *
+ * @param syncAssetIdList
+ * @param isSyncEndpoint
+ * @param isSyncDashboard
+ */
+ void syncAssetEndpointAndDashboard(List<Integer> syncAssetIdList, Integer isSyncEndpoint, Integer isSyncDashboard);
}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
index ca12531a..d0c76013 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetAssetServiceImpl.java
@@ -2279,7 +2279,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
if (StrUtil.equals("1", syncEndpoint)) {
List<MonitorEndpoint> endpointList = monitorEndpointService.list(new LambdaQueryWrapper<MonitorEndpoint>().eq(MonitorEndpoint::getAssetId, asset.getId()));
if (Tool.CollUtil.isNotEmpty(endpointList)) {
- monitorEndpointService.syncTmpl(Collections.emptyList(), Collections.emptyList(), ListUtil.of(asset.getId()));
+ List<Integer> syncEndpointIdList = endpointList.stream().map(MonitorEndpoint::getId).collect(Collectors.toList());
+ monitorEndpointService.syncConfigByIdList(syncEndpointIdList);
}
}
} else {
@@ -2508,4 +2509,77 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
List<AssetAsset> discoveredAssetInfoList = this.getBaseMapper().getDiscoveredAssetInfoList();
return discoveredAssetInfoList;
}
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void syncAssetEndpointAndDashboard(List<Integer> syncAssetIdList, Integer isSyncEndpoint, Integer isSyncDashboard) {
+ log.info("[syncAssetEndpointAndDashboard] [begin] [syncAssetIdList: {}] [isSyncEndpoint: {}] [isSyncDashboard: {}]", JSONUtil.toJsonStr(syncAssetIdList), isSyncEndpoint, isSyncDashboard);
+ if (ObjectUtil.equal(1, isSyncEndpoint)) {
+ List<MonitorEndpoint> syncEndpointList = monitorEndpointService.list(new LambdaQueryWrapper<MonitorEndpoint>().in(MonitorEndpoint::getAssetId, syncAssetIdList));
+ if (CollUtil.isEmpty(syncEndpointList)) {
+ log.warn("[syncAssetEndpointAndDashboard] [asset has no endpoint to sync] [syncAssetIdList: {}]", JSONUtil.toJsonStr(syncAssetIdList));
+ } else {
+ List<Integer> syncEndpointIdList = syncEndpointList.stream().map(MonitorEndpoint::getId).collect(Collectors.toList());
+ monitorEndpointService.syncConfigByIdList(syncEndpointIdList);
+ }
+ }
+
+ if (ObjectUtil.equal(1, isSyncDashboard)) {
+ List<AssetAsset> assetList = this.getBaseMapper().selectBatchIds(syncAssetIdList);
+ ValidateUtils.is(assetList).notNull(RCode.ASSET_NOT_EXIST);
+
+ // asset model
+ List<Integer> modelIdList = assetList.stream().map(AssetAsset::getModelId).distinct().collect(Collectors.toList());
+ List<AssetModel> modelList = modelService.getBaseMapper().selectBatchIds(modelIdList);
+
+ Map<Integer, AssetModel> assetIdWithModelMap = MapUtil.newHashMap();
+ assetList.forEach(asset -> {
+ AssetModel model = modelList.stream().filter(m -> ObjectUtil.equal(m.getId(), asset.getModelId())).findFirst().get();
+ assetIdWithModelMap.put(asset.getId(), model);
+ });
+
+ // asset info Dashboard List
+ List<VisualDashboard> assetInfoDashboardList = dashboardService.list(new LambdaQueryWrapper<VisualDashboard>()
+ .eq(VisualDashboard::getType, DashboardConstant.Type.ASSET.getValue())
+ .in(VisualDashboard::getLink, syncAssetIdList));
+
+ // asset info dashboard.tmpl_id = model.dashboard_id
+ for (VisualDashboard dashboard : assetInfoDashboardList) {
+ AssetModel assetRefModelEntity = assetIdWithModelMap.get(dashboard.getLink());
+ Integer assetRefModelEntityDashboardId = assetRefModelEntity.getDashboardId();
+ assetRefModelEntityDashboardId = ObjectUtil.defaultIfNull(assetRefModelEntityDashboardId, -1);
+ if (ObjectUtil.notEqual(dashboard.getTmplId(), assetRefModelEntityDashboardId)) {
+ dashboard.setTmplId(assetRefModelEntityDashboardId);
+ dashboardService.update(new LambdaUpdateWrapper<VisualDashboard>()
+ .set(VisualDashboard::getTmplId, assetRefModelEntityDashboardId)
+ .eq(VisualDashboard::getId, dashboard.getId()));
+ }
+ }
+
+ // asset Ref Dashboard List
+ List<VisualDashboard> assetRefDashboardList = dashboardService.list(new LambdaQueryWrapper<VisualDashboard>()
+ .eq(VisualDashboard::getType, DashboardConstant.Type.DASHBOARD.getValue())
+ .eq(VisualDashboard::getVarType, DashboardConstant.VariableType.ASSET.getValue())
+ .in(VisualDashboard::getLink, syncAssetIdList));
+
+ List<VisualDashboard> syncDashboardList = ListUtil.list(true);
+ syncDashboardList.addAll(assetInfoDashboardList);
+ syncDashboardList.addAll(assetRefDashboardList);
+ syncDashboardList = syncDashboardList.stream().distinct().filter(d -> ObjectUtil.notEqual(d.getTmplId(), -1)).collect(Collectors.toList());
+
+ log.info("[syncAssetEndpointAndDashboard] [syncDashboardList] [size: {}]", syncDashboardList.size());
+ if (log.isDebugEnabled()) {
+ log.debug("[syncAssetEndpointAndDashboard] [syncDashboardList] [size: {}] [info: {}]", syncDashboardList.size(), JSONUtil.toJsonStr(syncDashboardList));
+ }
+ if (CollUtil.isEmpty(syncDashboardList)) {
+ log.warn("[syncAssetEndpointAndDashboard] [asset has no dashboard to sync] [syncAssetIdList: {}]", JSONUtil.toJsonStr(syncAssetIdList));
+ } else {
+ // sync dashboard
+ syncDashboardList.forEach(syncDashboard -> {
+ visualService.syncTemplateDashboard(syncDashboard.getId(), null, null, null);
+ });
+ }
+ }
+ log.info("[syncAssetEndpointAndDashboard] [finshed]");
+ }
}
diff --git a/nz-admin/src/main/java/com/nis/modules/endpoint/controller/MonitorEndpointController.java b/nz-admin/src/main/java/com/nis/modules/endpoint/controller/MonitorEndpointController.java
index 1e712b82..ef64273d 100644
--- a/nz-admin/src/main/java/com/nis/modules/endpoint/controller/MonitorEndpointController.java
+++ b/nz-admin/src/main/java/com/nis/modules/endpoint/controller/MonitorEndpointController.java
@@ -186,7 +186,7 @@ public class MonitorEndpointController {
/**
* endpoint配置同步接口
*/
- @PutMapping( "/endpoint/syncTmpl")
+ //@PutMapping( "/endpoint/syncTmpl")
@SysLog(operation = OperationEnum.UPDATE, type = TypeEnum.ENDPOINT)
public R syncTmpl(@RequestBody Map<String, List<Integer>> params) {
ValidateUtils.notAllNull(RCode.ENDPOINT_MODULE_ASSET_ID_ISALLNULL, params.get("moduleIds"), params.get("endpointIds"), params.get("assetIds"));
diff --git a/nz-admin/src/main/java/com/nis/modules/endpoint/dao/MonitorEndpointDao.java b/nz-admin/src/main/java/com/nis/modules/endpoint/dao/MonitorEndpointDao.java
index e4334848..34d3a329 100644
--- a/nz-admin/src/main/java/com/nis/modules/endpoint/dao/MonitorEndpointDao.java
+++ b/nz-admin/src/main/java/com/nis/modules/endpoint/dao/MonitorEndpointDao.java
@@ -31,5 +31,6 @@ public interface MonitorEndpointDao extends BaseMapper<MonitorEndpoint> {
List<MonitorEndpoint> getEnableLogsEndpointInfoListForAgent(@Param("version") Integer version);
List<Map<String,Object>> queryEndpointGroupBy(@Param("column") String column,@Param("params") Map<String, Object> params);
-
+
+ List<MonitorEndpoint> queryEndpointListWithConfig(@Param("params") Map<Object, Object> params);
}
diff --git a/nz-admin/src/main/java/com/nis/modules/endpoint/entity/MonitorEndpoint.java b/nz-admin/src/main/java/com/nis/modules/endpoint/entity/MonitorEndpoint.java
index 8c018460..0d7bdaf9 100644
--- a/nz-admin/src/main/java/com/nis/modules/endpoint/entity/MonitorEndpoint.java
+++ b/nz-admin/src/main/java/com/nis/modules/endpoint/entity/MonitorEndpoint.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
+import com.nis.common.utils.Tool;
import com.nis.modules.agent.entity.Agent;
import com.nis.modules.asset.entity.AssetAsset;
import com.nis.modules.asset.entity.Dc;
@@ -71,6 +72,9 @@ public class MonitorEndpoint implements Serializable {
private MonitorEndpointConfig endpointConfig;
@TableField(exist = false)
+ private List<MonitorEndpointConfig> endpointConfigList;
+
+ @TableField(exist = false)
private List alert;
/**
@@ -78,4 +82,8 @@ public class MonitorEndpoint implements Serializable {
*/
@TableField(exist = false)
private Integer starred;
+
+ public void setName(String name) {
+ this.name = Tool.StrUtil.trim(name);
+ }
}
diff --git a/nz-admin/src/main/java/com/nis/modules/endpoint/service/MonitorEndpointService.java b/nz-admin/src/main/java/com/nis/modules/endpoint/service/MonitorEndpointService.java
index 2d038713..6c42273a 100644
--- a/nz-admin/src/main/java/com/nis/modules/endpoint/service/MonitorEndpointService.java
+++ b/nz-admin/src/main/java/com/nis/modules/endpoint/service/MonitorEndpointService.java
@@ -60,4 +60,7 @@ public interface MonitorEndpointService extends IService<MonitorEndpoint> {
void bulkEdit(Map<String, Object> params);
Map<String, Object> diagnose(Integer id, HttpServletRequest request) throws IOException;
+
+ void syncConfigByIdList(List<Integer> syncEndpointIdList);
+
}
diff --git a/nz-admin/src/main/java/com/nis/modules/endpoint/service/impl/MonitorEndpointServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/endpoint/service/impl/MonitorEndpointServiceImpl.java
index 1a84d90d..345591bf 100644
--- a/nz-admin/src/main/java/com/nis/modules/endpoint/service/impl/MonitorEndpointServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/endpoint/service/impl/MonitorEndpointServiceImpl.java
@@ -25,9 +25,7 @@ import com.nis.modules.agent.service.AgentService;
import com.nis.modules.agent.service.PromApiService;
import com.nis.modules.agent.util.AgentUtil;
import com.nis.modules.alert.entity.AlertMessageEntity;
-import com.nis.modules.alert.entity.AlertSeverityConf;
import com.nis.modules.alert.service.AlertMessageService;
-import com.nis.modules.alert.service.AlertSeverityService;
import com.nis.modules.asset.entity.AssetAsset;
import com.nis.modules.asset.entity.AssetTalonStatus;
import com.nis.modules.asset.service.AssetAssetService;
@@ -50,7 +48,6 @@ import com.nis.modules.module.entity.MonitorModule;
import com.nis.modules.module.service.MonitorModuleService;
import com.nis.modules.project.entity.MonitorProject;
import com.nis.modules.project.service.MonitorProjectService;
-import com.nis.modules.stat.service.StatService;
import com.nis.modules.sys.entity.SnmpCredential;
import com.nis.modules.sys.entity.SysUserStarredEntity;
import com.nis.modules.sys.service.*;
@@ -110,9 +107,6 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
private SnmpCredentialService snmpCredentialService;
@Autowired
- private StatService statService;
-
- @Autowired
private BasicImportAndExportServices basicImportAndExportServices;
@Autowired
@@ -194,7 +188,7 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
Map endpointMetricsStates = redisTemplate.opsForHash().entries(Constant.ENDPOINT_METRICS_STATE_CACHE_KEY);
Map endpointLogsStates = redisTemplate.opsForHash().entries(Constant.ENDPOINT_LOGS_STATE_CACHE_KEY);
- List<MonitorEndpointConfig> endpointConfigs = endpointConfigService.list(new LambdaQueryWrapper<MonitorEndpointConfig>().eq(MonitorEndpointConfig::getEndpointId, endpoint.getId()));
+ List<MonitorEndpointConfig> endpointConfigs = endpointConfigService.list(new LambdaQueryWrapper<MonitorEndpointConfig>().eq(MonitorEndpointConfig::getEndpointId, endpoint.getId()).orderByDesc(MonitorEndpointConfig::getType));
for (MonitorEndpointConfig endpointConfig : endpointConfigs) {
endpointConfig.setVer(endpointConfig.getVersion());
@@ -339,7 +333,13 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
* endpoint配置同步接口
* 根据参数查询符合条件的 endpoint,再根据module模板信息重新渲染endpoint配置
* 当根据module模板生成的 endpoint 配置,缺少必填项时,以原endpoint 配置中内容为准
+ *
+ * @deprecated 使用 syncConfigByIdList 方法替代
+ * @param moduleIds
+ * @param endpointIds
+ * @param assetIds
*/
+ @Deprecated
@Override
@Transactional(rollbackFor = Exception.class)
public void syncTmpl(List<Integer> moduleIds, List<Integer> endpointIds, List<Integer> assetIds) {
@@ -672,7 +672,7 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
@SuppressWarnings("unlikely-arg-type")
private void handleResuleList(List<MonitorEndpoint> endpointList) {
- List<MonitorEndpointConfig> endpointConfigs = endpointConfigService.list();
+ List<MonitorEndpointConfig> endpointConfigs = endpointConfigService.list(new LambdaQueryWrapper<MonitorEndpointConfig>().orderByDesc(MonitorEndpointConfig::getType));
Map endpointMetricsStates = redisTemplate.opsForHash().entries(Constant.ENDPOINT_METRICS_STATE_CACHE_KEY);
Map endpointLogsStates = redisTemplate.opsForHash().entries(Constant.ENDPOINT_LOGS_STATE_CACHE_KEY);
@@ -1595,6 +1595,11 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
endpointConfig.setVersion(endpointConfig.getVersion() + 1);
}
endpointConfig.setSeq(endpoint.getSeq());
+
+ // update hash value
+ String hashStr = endpoint.getId() + endpointConfig.getType() + endpointConfig.getConfig();
+ endpointConfig.setHash(String.valueOf(Math.abs(MurmurHash.hash64(hashStr))));
+
endpointConfigList.add(endpointConfig);
}
endpointConfigService.updateBatchById(endpointConfigList);
@@ -1760,6 +1765,91 @@ public class MonitorEndpointServiceImpl extends ServiceImpl<MonitorEndpointDao,
return resultMap;
}
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void syncConfigByIdList(List<Integer> syncEndpointIdList) {
+ List<MonitorEndpoint> syncEndpointListWithConfig = this.getBaseMapper().queryEndpointListWithConfig(MapUtil.builder().put("ids", syncEndpointIdList).build());
+ log.info("[syncConfigByIdList] [begin] [syncEndpointList] [size: {}]", syncEndpointListWithConfig.size());
+
+ List<Integer> moduleIdList = syncEndpointListWithConfig.stream().map(MonitorEndpoint::getModuleId).distinct().collect(Collectors.toList());
+ List<MonitorModule> moduleList = monitorModuleService.getBaseMapper().selectBatchIds(moduleIdList);
+
+ Map<Integer, AssetAsset> assetInfoCache = MapUtil.newHashMap();
+
+ List<MonitorEndpointConfig> saveBatchEndpointConfigList = ListUtil.list(true);
+ for (MonitorEndpoint endpoint : syncEndpointListWithConfig) {
+ // module
+ MonitorModule moduleInfo = moduleList.stream().filter(m -> ObjectUtil.equal(m.getId(), endpoint.getModuleId())).findFirst().get();
+
+ // asset
+ Integer assetId = endpoint.getAssetId();
+ AssetAsset assetInfo = assetInfoCache.get(assetId);
+ if (ObjectUtil.isNull(assetInfo)) {
+ assetInfo = assetService.queryAssetInfo(assetId);
+ assetInfoCache.put(assetId, assetInfo);
+ }
+
+ String nameExprTmpl = moduleInfo.getEndpointNameTmpl();
+ String renderedName = Tool.NzExpressionUtil.renderExpression(nameExprTmpl, moduleInfo, assetInfo);
+ // name change
+ if (!StrUtil.equals(endpoint.getName(), renderedName)) {
+ // validate name duplicate
+ MonitorEndpoint duplicateEndpoint = this.getOne(new LambdaQueryWrapper<MonitorEndpoint>().select(MonitorEndpoint::getId)
+ .eq(MonitorEndpoint::getName, renderedName)
+ .ne(MonitorEndpoint::getId, endpoint.getId())
+ .last("limit 1"));
+ if (ObjectUtil.isNotNull(duplicateEndpoint)) {
+ throw new NZException(RCode.ENDPOINT_NAME_DUPLICATE);
+ }
+ // update name
+ this.update(new LambdaUpdateWrapper<MonitorEndpoint>()
+ .set(MonitorEndpoint::getName, renderedName)
+ .eq(MonitorEndpoint::getId, endpoint.getId())
+ );
+ }
+ String configExprTmpl = moduleInfo.getConfigs();
+ String renderedConfigJsonStr = Tool.NzExpressionUtil.renderExpression(configExprTmpl, moduleInfo, assetInfo);
+ List<MonitorEndpointConfig> renderedConfigList = JSONUtil.toList(renderedConfigJsonStr, MonitorEndpointConfig.class);
+
+ // current Endpoint Config List
+ List<MonitorEndpointConfig> currentConfigList = CollUtil.defaultIfEmpty(endpoint.getEndpointConfigList(), ListUtil.empty());
+ for (MonitorEndpointConfig renderedConfigPojo : renderedConfigList) {
+ // hash
+ String hashStr = endpoint.getId() + renderedConfigPojo.getType() + renderedConfigPojo.getConfig();
+ String hash = String.valueOf(Math.abs(MurmurHash.hash64(hashStr)));
+
+ MonitorEndpointConfig currentTypeConfig = currentConfigList.stream().filter(e -> StrUtil.equals(e.getType(), renderedConfigPojo.getType())).findFirst().get();
+ // config change
+ if (ObjectUtil.notEqual(hash, currentTypeConfig.getHash()) || ObjectUtil.notEqual(renderedConfigPojo.getEnable(), currentTypeConfig.getEnable())) {
+ renderedConfigPojo.setHash(hash);
+ renderedConfigPojo.setEndpointId(endpoint.getId());
+ saveBatchEndpointConfigList.add(renderedConfigPojo);
+ }
+ }
+ }
+ log.info("[syncConfigByIdList] [save Batch Endpoint Config List] [size: {}]", saveBatchEndpointConfigList.size());
+ if (CollUtil.isNotEmpty(saveBatchEndpointConfigList)) {
+ List<Integer> removeMetricsEndpointIdList = saveBatchEndpointConfigList.stream()
+ .filter(config -> StrUtil.equals(config.getType(), Constant.MonitorConfType.METRICS.getValue()))
+ .map(MonitorEndpointConfig::getEndpointId).distinct().collect(Collectors.toList());
+ if (CollUtil.isNotEmpty(removeMetricsEndpointIdList)) {
+ endpointConfigService.remove(new LambdaQueryWrapper<MonitorEndpointConfig>()
+ .eq(MonitorEndpointConfig::getType, Constant.MonitorConfType.METRICS.getValue())
+ .in(MonitorEndpointConfig::getEndpointId, removeMetricsEndpointIdList));
+ }
+ List<Integer> removeLogsEndpointIdList = saveBatchEndpointConfigList.stream()
+ .filter(config -> StrUtil.equals(config.getType(), Constant.MonitorConfType.LOGS.getValue()))
+ .map(MonitorEndpointConfig::getEndpointId).distinct().collect(Collectors.toList());
+ if (CollUtil.isNotEmpty(removeLogsEndpointIdList)) {
+ endpointConfigService.remove(new LambdaQueryWrapper<MonitorEndpointConfig>()
+ .eq(MonitorEndpointConfig::getType, Constant.MonitorConfType.LOGS.getValue())
+ .in(MonitorEndpointConfig::getEndpointId, removeLogsEndpointIdList));
+ }
+ endpointConfigService.saveBatch(saveBatchEndpointConfigList);
+ }
+ log.info("[syncConfigByIdList] [finshed]");
+ }
+
/**
* endpoint metric 异常诊断
*/
diff --git a/nz-admin/src/main/java/com/nis/modules/module/service/impl/MonitorModuleServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/module/service/impl/MonitorModuleServiceImpl.java
index a2a48a3e..950748ea 100644
--- a/nz-admin/src/main/java/com/nis/modules/module/service/impl/MonitorModuleServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/module/service/impl/MonitorModuleServiceImpl.java
@@ -982,7 +982,8 @@ public class MonitorModuleServiceImpl extends ServiceImpl<MonitorModuleDao, Moni
if (StrUtil.equals("1", syncEndpoint)) {
List<MonitorEndpoint> endpointList = monitorEndpointService.list(new LambdaQueryWrapper<MonitorEndpoint>().eq(MonitorEndpoint::getModuleId, module.getId()));
if (Tool.CollUtil.isNotEmpty(endpointList)) {
- monitorEndpointService.syncTmpl(ListUtil.of(module.getId()), Collections.emptyList(), Collections.emptyList());
+ List<Integer> syncEndpointIdList = endpointList.stream().map(MonitorEndpoint::getId).collect(Collectors.toList());
+ monitorEndpointService.syncConfigByIdList(syncEndpointIdList);
}
}
diff --git a/nz-admin/src/main/resources/mapper/endpoint/MonitorEndpointDao.xml b/nz-admin/src/main/resources/mapper/endpoint/MonitorEndpointDao.xml
index 64545fd3..c08ef297 100644
--- a/nz-admin/src/main/resources/mapper/endpoint/MonitorEndpointDao.xml
+++ b/nz-admin/src/main/resources/mapper/endpoint/MonitorEndpointDao.xml
@@ -77,31 +77,25 @@
</association>
</resultMap>
- <resultMap type="com.nis.modules.endpoint.entity.MonitorEndpoint" id="endpointDetail">
- <result property="id" column="id"/>
- <result property="name" column="name"/>
- <result property="moduleId" column="module_id"/>
- <result property="assetId" column="asset_id"/>
-
- <association columnPrefix="ass_" property="asset" javaType="com.nis.modules.asset.entity.AssetAsset">
- <id column="id" property="id"/>
- <result column="manage_ip" property="manageIp"/>
- <result column="sn" property="sn"/>
- <result column="name" property="name"/>
- <result column="dc_id" property="dcId"/>
-
- <!--state conf monitor-->
- <result property="state.id" column="state_id"/>
- <result property="state.name" column="state_name"/>
- <result property="state.monitor" column="state_monitor"/>
- </association>
-
- <association columnPrefix="dc_" property="dc" javaType="com.nis.modules.asset.entity.Dc">
- <id column="id" property="id"/>
- <result column="name" property="name"/>
- <result column="state" property="state"/>
- </association>
- </resultMap>
+ <resultMap type="com.nis.modules.endpoint.entity.MonitorEndpoint" id="endpointWithConfigResultMap">
+ <id property="id" column="id"/>
+ <result property="name" column="name"/>
+ <result property="moduleId" column="module_id"/>
+ <result property="assetId" column="asset_id"/>
+ <result property="seq" column="seq"/>
+
+ <collection property="endpointConfigList" ofType="com.nis.modules.endpoint.entity.MonitorEndpointConfig"
+ columnPrefix="conf_">
+ <id property="id" column="id"/>
+ <result property="endpointId" column="endpoint_id"/>
+ <result property="type" column="type"/>
+ <result property="config" column="config"/>
+ <result property="version" column="version"/>
+ <result property="enable" column="enable"/>
+ <result property="hash" column="hash"/>
+ <result property="seq" column="seq"/>
+ </collection>
+ </resultMap>
<select id="queryPage" resultMap="endpoint">
SELECT
@@ -490,4 +484,28 @@
AND ( mes.ver != #{version} || mes.state = 0 )
</select>
+ <select id="queryEndpointListWithConfig" resultMap="endpointWithConfigResultMap">
+ SELECT
+ me.*,
+ mec.id AS conf_id,
+ mec.endpoint_id AS conf_endpoint_id,
+ mec.type AS conf_type,
+ mec.config AS conf_config,
+ mec.version AS conf_version,
+ mec.`enable` AS conf_enable,
+ mec.hash AS conf_hash,
+ mec.seq AS conf_seq
+ FROM
+ monitor_endpoint me
+ LEFT JOIN monitor_endpoint_config mec ON me.id = mec.endpoint_id
+ <where>
+ <if test="params.ids != null and params.ids.size > 0">
+ me.id IN
+ <foreach collection="params.ids" item="id" index="no" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </if>
+ </where>
+ </select>
+
</mapper>