Procházet zdrojové kódy

20230814-完善部分接口

iaun před 3 roky
rodič
revize
fb072987b8

+ 13 - 7
src/main/java/cn/iaun/it/controller/ItMonitorController.java

@@ -70,13 +70,19 @@ public class ItMonitorController {
         return new Result<>(ResultCode.SUCCESS, myPage);
     }
 
-    @PostMapping("/agent/add")
+    @PostMapping("/agent/add") // TODO: check agent key exist
     public Result<?> addItMonitorAgent(@Validated @RequestBody ItMonitorAgent itMonitorAgent) {
         itMonitorAgent.setAgentId(null);
         int result = itMonitorService.addAgent(itMonitorAgent);
         return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
+    @PostMapping("/agent/set") // TODO: check agent key exist
+    public Result<?> setItMonitorAgent(@Validated @RequestBody ItMonitorAgent itMonitorAgent) {
+        int result = itMonitorService.setAgent(itMonitorAgent);
+        return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
+    }
+
     @PostMapping("/agent/del/{i}")
     public Result<?> delItMonitorAgent(@PathVariable String i) {
         Long id = Long.parseLong(i);
@@ -124,7 +130,7 @@ public class ItMonitorController {
         return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
-    @PostMapping("/resource/group/del/{i}")
+    @PostMapping("/resource/group/del/{i}")  // TODO: del resource
     public Result<?> delItMonitorResourceGroup(@PathVariable String i) {
         Long id = Long.parseLong(i);
         int result = itMonitorService.delResourceGroup(id);
@@ -161,7 +167,7 @@ public class ItMonitorController {
         return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
-    @PostMapping("/resource/del/{i}")
+    @PostMapping("/resource/del/{i}")  // TODO: delete data/alarm/threshold?
     public Result<?> delItMonitorResource(@PathVariable String i) {
         Long id = Long.parseLong(i);
         int result = itMonitorService.delResource(id);
@@ -205,7 +211,7 @@ public class ItMonitorController {
     }
 
     @PostMapping("/item/group/set")
-    public Result<?> setItMonitorItemGroup(ItMonitorItemGroup itMonitorItemGroup) { // 只允许修改名称、间隔、置顶itemId
+    public Result<?> setItMonitorItemGroup(ItMonitorItemGroup itMonitorItemGroup) { // 只允许修改名称、间隔、置顶itemId、是否为表格
         if (itMonitorItemGroup.getGroupId() == null || itMonitorItemGroup.getGroupName() == null || itMonitorItemGroup.getGroupName().isEmpty()
                 || (itMonitorItemGroup.getTopItemId() != -1 && !itMonitorService.checkItemExistByItemId(itMonitorItemGroup.getTopItemId(), itMonitorItemGroup.getGroupId()))
         ) {
@@ -222,7 +228,7 @@ public class ItMonitorController {
         return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllItemByGroupId(id));
     }
 
-    @PostMapping("/item/add")
+    @PostMapping("/item/add") // TODO: check groupId
     public Result<?> addItMonitorItem(@Validated @RequestBody ItMonitorItem itMonitorItem) {
         if (!itMonitorService.checkItemGroupExistByGroupId(itMonitorItem.getItemGroupId())) {
             return new Result<>(ResultCode.FAILED_PARAM_INVALID);
@@ -239,7 +245,7 @@ public class ItMonitorController {
         return new Result<>(result == 1 ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
-    @PostMapping("/item/set")
+    @PostMapping("/item/set") // TODO: check groupId
     public Result<?> setItMonitorItem(@Validated @RequestBody ItMonitorItem itMonitorItem) {
         return new Result<>(ResultCode.SUCCESS, itMonitorService.setItem(itMonitorItem));
     }
@@ -275,7 +281,7 @@ public class ItMonitorController {
         return new Result<>(success ? ResultCode.SUCCESS : ResultCode.FAILED);
     }
 
-    @PostMapping("/data/getItem")
+    @PostMapping("/data/get")
     public Result<MyPage<ItMonitorData>> getItMonitorDataByIds(@RequestBody ItMonitorDataGetReqVo itMonitorDataGetReqVo) {
         if (itMonitorDataGetReqVo.getPageNo() == null) {
             itMonitorDataGetReqVo.setPageNo(1);

+ 2 - 0
src/main/java/cn/iaun/it/service/ItMonitorService.java

@@ -26,6 +26,8 @@ public interface ItMonitorService {
 
     int delAgent(Long agentId);
 
+    int setAgent(ItMonitorAgent itMonitorAgent);
+
     // 监控模板
     List<ItMonitorTemplate> getAllTemplate();
 

+ 5 - 0
src/main/java/cn/iaun/it/service/impl/ItMonitorServiceImpl.java

@@ -91,6 +91,11 @@ public class ItMonitorServiceImpl implements ItMonitorService {
         return itMonitorAgentMapper.deleteById(agentId);
     }
 
+    @Override
+    public int setAgent(ItMonitorAgent itMonitorAgent) {
+        return itMonitorAgentMapper.updateById(itMonitorAgent);
+    }
+
     @Override
     public List<ItMonitorTemplate> getAllTemplate() {
         return itMonitorTemplateMapper.selectList(null);

+ 4 - 2
src/main/resources/db/data.sql

@@ -169,11 +169,11 @@ VALUES (2, 'agent2_local', '192.168.254.1', 2);
 delete
 from `it_monitor_item_group`;
 INSERT INTO `it_monitor_item_group` (`group_id`, `group_name`, `template_id`, `interval`, `top_item_id`, `is_table`)
-VALUES (1, 'CPU使用率', 1, 10, -1, 1);
+VALUES (1, 'CPU使用率', 1, 60, -1, 1);
 INSERT INTO `it_monitor_item_group` (`group_id`, `group_name`, `template_id`, `interval`, `top_item_id`, `is_table`)
 VALUES (2, 'CPU信息', 1, 600, -1, 0);
 INSERT INTO `it_monitor_item_group` (`group_id`, `group_name`, `template_id`, `interval`, `top_item_id`, `is_table`)
-VALUES (3, '内存', 1, 10, -1, 0);
+VALUES (3, '内存', 1, 60, -1, 0);
 
 
 delete
@@ -198,6 +198,8 @@ INSERT INTO `it_monitor_item` (`item_id`, `item_name`, `item_key_name`, `item_gr
 VALUES (9, '缓存', 'group3.cache', 3, 3);
 INSERT INTO `it_monitor_item` (`item_id`, `item_name`, `item_key_name`, `item_group_id`, `item_type`)
 VALUES (10, '空闲', 'group3.free', 3, 3);
+INSERT INTO `it_monitor_item` (`item_id`, `item_name`, `item_key_name`, `item_group_id`, `item_type`)
+VALUES (11, '可用', 'group3.available', 3, 3);