diff --git a/common/src/main/java/org/dromara/hertzbeat/common/entity/job/Job.java b/common/src/main/java/org/dromara/hertzbeat/common/entity/job/Job.java index 3ffa7bbd346..23bb1076ef9 100644 --- a/common/src/main/java/org/dromara/hertzbeat/common/entity/job/Job.java +++ b/common/src/main/java/org/dromara/hertzbeat/common/entity/job/Job.java @@ -54,6 +54,10 @@ public class Job { * Monitoring Task ID */ private long monitorId; + /** + * Is hide this app in main menus layout, only for app type, default true. + */ + private boolean hide = true; /** * Large categories of monitoring * service-application service monitoring db-database monitoring custom-custom monitoring os-operating system monitoring... diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/config/SystemCommandLineRunner.java b/manager/src/main/java/org/dromara/hertzbeat/manager/config/CommonCommandLineRunner.java similarity index 81% rename from manager/src/main/java/org/dromara/hertzbeat/manager/config/SystemCommandLineRunner.java rename to manager/src/main/java/org/dromara/hertzbeat/manager/config/CommonCommandLineRunner.java index 0f285647ecc..3dfd3956411 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/config/SystemCommandLineRunner.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/config/CommonCommandLineRunner.java @@ -22,8 +22,13 @@ import org.dromara.hertzbeat.common.entity.manager.GeneralConfig; import org.dromara.hertzbeat.manager.dao.GeneralConfigDao; import org.dromara.hertzbeat.manager.pojo.dto.SystemConfig; +import org.dromara.hertzbeat.manager.pojo.dto.TemplateConfig; +import org.dromara.hertzbeat.manager.service.AppService; import org.dromara.hertzbeat.manager.service.impl.SystemGeneralConfigServiceImpl; +import org.dromara.hertzbeat.manager.service.impl.TemplateConfigServiceImpl; import org.springframework.boot.CommandLineRunner; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import jakarta.annotation.Resource; @@ -31,17 +36,23 @@ import java.util.TimeZone; /** - * SystemCommandLineRunner class - * @since 4/7/2023 + * Common CommandLineRunner class */ @Component -public class SystemCommandLineRunner implements CommandLineRunner { +@Order(value = Ordered.HIGHEST_PRECEDENCE + 2) +public class CommonCommandLineRunner implements CommandLineRunner { private static final Integer LANG_REGION_LENGTH = 2; @Resource private SystemGeneralConfigServiceImpl systemGeneralConfigService; + @Resource + private TemplateConfigServiceImpl templateConfigService; + + @Resource + private AppService appService; + @Resource protected GeneralConfigDao generalConfigDao; @@ -76,5 +87,8 @@ public void run(String... args) throws Exception { .build(); generalConfigDao.save(generalConfig2Save); } + // flush the template config in db to memory + TemplateConfig templateConfig = templateConfigService.getConfig(); + appService.updateCustomTemplateConfig(templateConfig); } } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/GeneralConfigController.java b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/GeneralConfigController.java index eed2e6a5e42..9f7d074ddd8 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/GeneralConfigController.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/GeneralConfigController.java @@ -22,7 +22,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.dromara.hertzbeat.common.entity.dto.Message; +import org.dromara.hertzbeat.manager.pojo.dto.TemplateConfig; import org.dromara.hertzbeat.manager.service.GeneralConfigService; +import org.dromara.hertzbeat.manager.service.impl.TemplateConfigServiceImpl; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -55,7 +57,7 @@ public GeneralConfigController(List generalConfigServices) } @PostMapping(path = "/{type}") - @Operation(summary = "Save the sender config", description = "保存公共配置") + @Operation(summary = "Save or update common config", description = "保存公共配置") public ResponseEntity> saveOrUpdateConfig( @Parameter(description = "Config Type", example = "email") @PathVariable("type") @NotNull final String type, @@ -79,4 +81,25 @@ public ResponseEntity> getConfig( } return ResponseEntity.ok(Message.success(configService.getConfig())); } + + @PutMapping(path = "/template/{app}") + @Operation(summary = "Update the app template config") + public ResponseEntity> updateTemplateAppConfig( + @PathVariable("app") @NotNull final String app, + @RequestBody TemplateConfig.AppTemplate template) { + GeneralConfigService configService = configServiceMap.get("template"); + if (configService == null || !(configService instanceof TemplateConfigServiceImpl)) { + throw new IllegalArgumentException("Not supported this config type: template"); + } + TemplateConfig config = ((TemplateConfigServiceImpl) configService).getConfig(); + if (config == null) { + config = new TemplateConfig(); + } + if (config.getApps() == null) { + config.setApps(new HashMap<>(8)); + } + config.getApps().put(app, template); + configService.saveConfig(config); + return ResponseEntity.ok(Message.success()); + } } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/Hierarchy.java b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/Hierarchy.java index 53764be266b..46e04767633 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/Hierarchy.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/Hierarchy.java @@ -60,6 +60,12 @@ public class Hierarchy { */ @Schema(description = "Is it a leaf node", example = "true", accessMode = READ_WRITE) Boolean isLeaf = false; + + /** + * Is hide this app type in main menus layout + */ + @Schema(description = "Is hide this app in main menus layout, only for app type, default true.", example = "true") + Boolean hide = true; /** * For leaf metric diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/SystemConfig.java b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/SystemConfig.java index 991b38d0839..dd30780b900 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/SystemConfig.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/SystemConfig.java @@ -23,10 +23,7 @@ import lombok.NoArgsConstructor; /** - * 系统配置 * System Configuration - * - * @since 4/7/2023 */ @Data @Builder diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/TemplateConfig.java b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/TemplateConfig.java new file mode 100644 index 00000000000..f9cce85e50d --- /dev/null +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/TemplateConfig.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.hertzbeat.manager.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * App Template Config + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TemplateConfig { + + /** + * app template config map + * key: app name + * value: app template config + */ + private Map apps; + + + /** + * app template + */ + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class AppTemplate { + + /** + * Is hide this app in main menus layout, only for app type, default true + */ + private boolean hide = true; + } +} diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java index b5fe29224ac..8a8285f0b06 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java @@ -20,6 +20,7 @@ import org.dromara.hertzbeat.common.entity.job.Job; import org.dromara.hertzbeat.common.entity.manager.ParamDefine; import org.dromara.hertzbeat.manager.pojo.dto.Hierarchy; +import org.dromara.hertzbeat.manager.pojo.dto.TemplateConfig; import java.util.List; import java.util.Map; @@ -27,9 +28,6 @@ /** * Monitoring Type Management Interface - * 监控类型管理接口 - * - * */ public interface AppService { @@ -127,4 +125,10 @@ public interface AppService { * @param app app */ void deleteMonitorDefine(String app); + + /** + * update custom template config in memory + * @param config template config + */ + void updateCustomTemplateConfig(TemplateConfig config); } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index 2c3c56b1005..924712b182f 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -36,6 +36,7 @@ import org.dromara.hertzbeat.manager.pojo.dto.Hierarchy; import org.dromara.hertzbeat.manager.pojo.dto.ObjectStoreConfigChangeEvent; import org.dromara.hertzbeat.manager.pojo.dto.ObjectStoreDTO; +import org.dromara.hertzbeat.manager.pojo.dto.TemplateConfig; import org.dromara.hertzbeat.manager.service.AppService; import org.dromara.hertzbeat.manager.service.MonitorService; import org.dromara.hertzbeat.manager.service.ObjectStoreService; @@ -256,6 +257,7 @@ public List getAllAppHierarchy(String lang) { var hierarchyApp = new Hierarchy(); hierarchyApp.setCategory(job.getCategory()); hierarchyApp.setValue(job.getApp()); + hierarchyApp.setHide(job.isHide()); var nameMap = job.getName(); if (nameMap != null && !nameMap.isEmpty()) { var i18nName = CommonUtil.getLangMappingValueFromI18nMap(lang, nameMap); @@ -419,6 +421,29 @@ public void deleteMonitorDefine(String app) { appDefines.remove(app.toLowerCase()); } + @Override + public void updateCustomTemplateConfig(TemplateConfig config) { + if (config == null) { + return; + } + Map templateMap = config.getApps(); + if (templateMap == null || templateMap.isEmpty()) { + return; + } + for (var entry : templateMap.entrySet()) { + var app = entry.getKey().toLowerCase(); + var appTemplate = entry.getValue(); + if (appTemplate == null) { + continue; + } + var appDefine = appDefines.get(app); + if (appDefine == null) { + continue; + } + appDefine.setHide(appTemplate.isHide()); + } + } + @Override public void run(String... args) throws Exception { var objectStoreConfig = objectStoreConfigService.getConfig(); diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/SystemGeneralConfigServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/SystemGeneralConfigServiceImpl.java index 0ecf27143b1..1a87dd9ec41 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/SystemGeneralConfigServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/SystemGeneralConfigServiceImpl.java @@ -32,8 +32,7 @@ import java.util.TimeZone; /** - * - * @since 4/7/2023 + * system config service impl */ @Service public class SystemGeneralConfigServiceImpl extends AbstractGeneralConfigServiceImpl { @@ -77,14 +76,7 @@ public void handler(SystemConfig systemConfig) { public String type() { return "system"; } - - /** - * 该方法用于获取NoticeSender类型的TypeReference,以供后续处理。 - * This method is used to get the TypeReference of NoticeSender type for subsequent processing. - * - * @return NoticeSender类型的TypeReference - * a TypeReference of NoticeSender type - */ + @Override protected TypeReference getTypeReference() { return new TypeReference<>() { diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/TemplateConfigServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/TemplateConfigServiceImpl.java new file mode 100644 index 00000000000..7696a24fd75 --- /dev/null +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/TemplateConfigServiceImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.hertzbeat.manager.service.impl; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.dromara.hertzbeat.manager.dao.GeneralConfigDao; +import org.dromara.hertzbeat.manager.pojo.dto.TemplateConfig; +import org.dromara.hertzbeat.manager.service.AppService; +import org.springframework.stereotype.Service; + +import jakarta.annotation.Resource; +import java.lang.reflect.Type; + +/** + * template config service impl + */ +@Service +public class TemplateConfigServiceImpl extends AbstractGeneralConfigServiceImpl { + + @Resource + private AppService appService; + + + /** + * 构造方法,传入GeneralConfigDao、ObjectMapper和type。 + * + *

Constructor, passing in GeneralConfigDao, ObjectMapper and type.

+ * + * @param generalConfigDao 配置Dao对象 + * @param objectMapper JSON工具类对象 + */ + protected TemplateConfigServiceImpl(GeneralConfigDao generalConfigDao, ObjectMapper objectMapper) { + super(generalConfigDao, objectMapper); + } + + @Override + public void handler(TemplateConfig templateConfig) { + if (templateConfig != null) { + appService.updateCustomTemplateConfig(templateConfig); + } + } + + @Override + public String type() { + return "template"; + } + + + @Override + protected TypeReference getTypeReference() { + return new TypeReference<>() { + @Override + public Type getType() { + return TemplateConfig.class; + } + }; + } +} diff --git a/web-app/src/app/core/startup/startup.service.ts b/web-app/src/app/core/startup/startup.service.ts index 732a98abb27..5cee21e63e8 100644 --- a/web-app/src/app/core/startup/startup.service.ts +++ b/web-app/src/app/core/startup/startup.service.ts @@ -65,7 +65,10 @@ export class StartupService { this.aclService.setFull(true); // Menu data, https://ng-alain.com/theme/menu this.menuService.add(appData.menu); - menuData.data.forEach((item: { category: string; value: string }) => { + menuData.data.forEach((item: { category: string; value: string; hide: boolean }) => { + if (item.hide) { + return; + } let category = item.category; let app = item.value; let menu: Menu | null = this.menuService.getItem(category); @@ -75,6 +78,20 @@ export class StartupService { link: `/monitors?app=${app}`, i18n: `monitor.app.${app}` }); + } else { + if (app != 'prometheus' && app != 'push') { + this.menuService.getItem('monitoring')?.children?.push({ + text: app, + link: `/monitors?app=${app}`, + i18n: `monitor.app.${app}`, + icon: 'anticon-project' + }); + } + } + }); + this.menuService.getItem('monitoring')?.children?.forEach(item => { + if (item.key != null && (item.children == null || item.children.length == 0)) { + item.hide = true; } }); this.storageService.putData('hierarchy', menuData.data); diff --git a/web-app/src/app/layout/basic/basic.component.ts b/web-app/src/app/layout/basic/basic.component.ts index bad237a5705..00e69ffef38 100644 --- a/web-app/src/app/layout/basic/basic.component.ts +++ b/web-app/src/app/layout/basic/basic.component.ts @@ -15,11 +15,6 @@ import { CONSTANTS } from '../../shared/constants'; - - - - -