Bläddra i källkod

20230901-sync

iaun 3 år sedan
förälder
incheckning
d1b99fe28f

+ 12 - 0
src/main/java/cn/iaun/it/controller/ItMonitorController.java

@@ -163,6 +163,12 @@ public class ItMonitorController {
         return new Result<>(ResultCode.SUCCESS, itMonitorService.getResourceDetailsByGroupId(id));
     }
 
+    @PostMapping("/resource/get-by-rid/{i}")
+    public Result<ItMonitorItMonitorResourceDetailsVo> getItMonitorResourceByResourceId(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getResourceDetailsByResourceId(id));
+    }
+
     @PostMapping("/resource/add")
     public Result<?> addItMonitorResource(@Validated @RequestBody ItMonitorResource itMonitorResource) {
         if (!itMonitorService.checkAgentExistByAgentId(itMonitorResource.getAgentId())
@@ -243,6 +249,12 @@ public class ItMonitorController {
         return new Result<>(ResultCode.SUCCESS, itMonitorService.getAllItemByGroupId(id));
     }
 
+    @PostMapping("/item/get-by-tid/{i}")
+    public Result<List<ItMonitorItem>> getItMonitorItemByTemplateId(@PathVariable String i) {
+        Long id = Long.parseLong(i);
+        return new Result<>(ResultCode.SUCCESS, itMonitorService.getItemByTemplateId(id));
+    }
+
     @PostMapping("/item/add") // TODO: check groupId
     public Result<?> addItMonitorItem(@Validated @RequestBody ItMonitorItem itMonitorItem) {
         if (itMonitorItem.getItemGroupId() == null ||

+ 2 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorItemMapper.java

@@ -11,4 +11,6 @@ public interface ItMonitorItemMapper extends BaseMapper<ItMonitorItem> {
     Long selectByItemId(Long itemId, Long groupId);
 
     List<ItMonitorItem> selectByItemGroupId(List<Long> itemGroupIds);
+
+    List<ItMonitorItem> selectByTemplateId(Long templateId);
 }

+ 2 - 0
src/main/java/cn/iaun/it/mapper/ItMonitorResourceMapper.java

@@ -11,5 +11,7 @@ import java.util.List;
 public interface ItMonitorResourceMapper extends BaseMapper<ItMonitorResource> {
     Boolean apiAuthCheck(Long resourceId, String agentIP, String agentKey);
     List<ItMonitorItMonitorResourceDetailsVo> getMonitorResourceDetailsByResourceGroupId(Long resourceGroupId);
+    ItMonitorItMonitorResourceDetailsVo getMonitorResourceDetailsByResourceResourceId(Long resourceId);
+
     List<ItMonitorItMonitorResourceDetailsVo> getAllMonitorResourceDetailsByResourceGroupId();
 }

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

@@ -63,6 +63,8 @@ public interface ItMonitorService {
 
     List<ItMonitorItMonitorResourceDetailsVo> getResourceDetailsByGroupId(Long groupId);
 
+    ItMonitorItMonitorResourceDetailsVo getResourceDetailsByResourceId(Long resourceId);
+
     int addResource(ItMonitorResource itMonitorResource);
 
     int delResource(Long resourceId);
@@ -93,6 +95,8 @@ public interface ItMonitorService {
 
     int setItem(ItMonitorItem itMonitorItem);
 
+    List<ItMonitorItem> getItemByTemplateId(Long templateId);
+
     // 监控阈值
     List<ItMonitorThreshold> getThresholdByResourceIdAndItemId(Long resourceId, Long itemId);
 
@@ -126,4 +130,6 @@ public interface ItMonitorService {
     List<ItMonitorApiAgentInitItemGroupVo> apiGetItemGroupsByResourceId(Long resourceId);
 
     List<ItMonitorItem> apiGetItemsByItemGroupIds(List<Long> itemGroupIds);
+
+
 }

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

@@ -182,6 +182,11 @@ public class ItMonitorServiceImpl implements ItMonitorService {
         return itMonitorResourceMapper.getMonitorResourceDetailsByResourceGroupId(groupId);
     }
 
+    @Override
+    public ItMonitorItMonitorResourceDetailsVo getResourceDetailsByResourceId(Long resourceId) {
+        return itMonitorResourceMapper.getMonitorResourceDetailsByResourceResourceId(resourceId);
+    }
+
     @Override
     public int addResource(ItMonitorResource itMonitorResource) {
         return itMonitorResourceMapper.insert(itMonitorResource);
@@ -254,6 +259,11 @@ public class ItMonitorServiceImpl implements ItMonitorService {
         return itMonitorItemMapper.updateById(itMonitorItem);
     }
 
+    @Override
+    public List<ItMonitorItem> getItemByTemplateId(Long templateId) {
+        return itMonitorItemMapper.selectByTemplateId(templateId);
+    }
+
     @Override
     public List<ItMonitorThreshold> getThresholdByResourceIdAndItemId(Long resourceId, Long itemId) {
         QueryWrapper<ItMonitorThreshold> queryWrapper = new QueryWrapper<>();

+ 5 - 0
src/main/resources/mapper/ItMonitorItemMapper.xml

@@ -16,4 +16,9 @@
             #{item}
         </foreach>
     </select>
+    <select id="selectByTemplateId" resultType="cn.iaun.it.model.ItMonitorItem">
+        SELECT `item_id`, `item_name`, `item_key_name`, `item_group_id`, `item_type`
+        FROM it_monitor_item
+        WHERE item_group_id IN (SELECT imig.group_id FROM it_monitor_item_group imig WHERE imig.template_id = #{templateId})
+    </select>
 </mapper>

+ 16 - 0
src/main/resources/mapper/ItMonitorResourceMapper.xml

@@ -40,4 +40,20 @@
                  LEFT JOIN it_monitor_template imt ON imr.`template_id` = imt.`template_id`
                  LEFT JOIN it_monitor_agent ima ON imr.`agent_id` = ima.`agent_id`
     </select>
+    <select id="getMonitorResourceDetailsByResourceResourceId"
+            resultType="cn.iaun.it.model.vo.monitor.ItMonitorItMonitorResourceDetailsVo">
+        SELECT imr.`resource_id`       AS `resource_id`,
+               imr.`template_id`       AS `template_id`,
+               imt.`template_name`     AS `template_name`,
+               imr.`agent_id`          AS `agent_id`,
+               ima.`agent_name`        AS `agent_name`,
+               ima.`agent_ip`          AS `agent_ip`,
+               imr.`resource_group_id` AS `resource_group_id`,
+               imr.`resource_name`     AS `resource_name`
+        FROM `it_monitor_resource` imr
+                 LEFT JOIN it_monitor_template imt ON imr.`template_id` = imt.`template_id`
+                 LEFT JOIN it_monitor_agent ima ON imr.`agent_id` = ima.`agent_id`
+        WHERE `resource_id` = #{resourceId}
+        LIMIT 1
+    </select>
 </mapper>