diff --git a/collector/pom.xml b/collector/pom.xml index 3a5a4553690..b491b1920ce 100644 --- a/collector/pom.xml +++ b/collector/pom.xml @@ -56,6 +56,12 @@ org.springframework.boot spring-boot-starter-validation + + + org.springframework + spring-jdbc + 5.3.23 + org.apache.kafka diff --git a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/database/JdbcCommonCollect.java b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/database/JdbcCommonCollect.java index edab67afb4b..6747dd8ea91 100644 --- a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/database/JdbcCommonCollect.java +++ b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/database/JdbcCommonCollect.java @@ -32,6 +32,8 @@ import org.dromara.hertzbeat.common.util.CommonUtil; import lombok.extern.slf4j.Slf4j; import org.postgresql.util.PSQLException; +import org.springframework.core.io.FileSystemResource; +import org.springframework.jdbc.datasource.init.ScriptUtils; import java.sql.Connection; import java.sql.DriverManager; @@ -54,6 +56,8 @@ public class JdbcCommonCollect extends AbstractCollect { private static final String QUERY_TYPE_ONE_ROW = "oneRow"; private static final String QUERY_TYPE_MULTI_ROW = "multiRow"; private static final String QUERY_TYPE_COLUMNS = "columns"; + + private static final String RUN_SCRIPT = "runScript"; public JdbcCommonCollect(){} @@ -84,6 +88,11 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a case QUERY_TYPE_COLUMNS: queryOneRowByMatchTwoColumns(statement, jdbcProtocol.getSql(), metrics.getAliasFields(), builder, startTime); break; + case RUN_SCRIPT: + Connection connection = statement.getConnection(); + FileSystemResource rc = new FileSystemResource(jdbcProtocol.getSql()); + ScriptUtils.executeSqlScript(connection, rc); + break; default: builder.setCode(CollectRep.Code.FAIL); builder.setMsg("Not support database query type: " + jdbcProtocol.getQueryType()); diff --git a/common/src/main/java/org/dromara/hertzbeat/common/entity/job/protocol/JdbcProtocol.java b/common/src/main/java/org/dromara/hertzbeat/common/entity/job/protocol/JdbcProtocol.java index 28a03185aa4..0a0ed74edfe 100644 --- a/common/src/main/java/org/dromara/hertzbeat/common/entity/job/protocol/JdbcProtocol.java +++ b/common/src/main/java/org/dromara/hertzbeat/common/entity/job/protocol/JdbcProtocol.java @@ -61,7 +61,7 @@ public class JdbcProtocol { */ private String platform; /** - * SQL查询方式: oneRow, multiRow, columns + * SQL查询方式: oneRow, multiRow, columns, runScript */ private String queryType; /**