summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangwenrui <[email protected]>2020-12-28 18:39:58 +0800
committerwangwenrui <[email protected]>2020-12-28 18:39:58 +0800
commitc41c67e23ffc370e2bbff3f5ac44b3a4c5a1b885 (patch)
treea11fbb2005f8986926a2ad0e30ce383813bc6a31
parent69d8f8bba8834e329afbe79092b8846a4115fa3d (diff)
EAL4:修改中等级别问题
-rw-r--r--pom.xml813
-rw-r--r--src/main/java/com/nis/controller/TrafficController.java5
-rw-r--r--src/main/java/com/nis/job/ConfagentJob.java33
-rw-r--r--src/main/java/com/nis/server/SNMPTrapServer.java3
-rw-r--r--src/main/java/com/nis/service/impl/TrafficServiceImpl.java5
-rw-r--r--src/main/java/com/nis/util/BufferReaderWrapper.java17
-rw-r--r--src/main/java/com/nis/util/DateUtil.java387
-rw-r--r--src/main/java/com/nis/util/SnmpUtil.java12
-rw-r--r--src/main/java/com/nis/util/ToolUtil.java718
-rw-r--r--src/main/java/com/nis/util/YamlUtil.java28
10 files changed, 479 insertions, 1542 deletions
diff --git a/pom.xml b/pom.xml
index 4446966..fed4ba6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,404 +1,409 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.3.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.nis</groupId>
- <artifactId>nz-confagent</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>nz-confagent</name>
- <description>confagent</description>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- <junit.version>4.12</junit.version>
- <jedis.version>2.9.0</jedis.version>
- <druid.version>1.1.24</druid.version>
- <mybatisplus.version>3.0.7.1</mybatisplus.version>
- <mysql.version>5.1.48</mysql.version>
- <mssql.version>4.0</mssql.version>
- <oracle.version>11.2.0.3</oracle.version>
- <commons.lang.version>2.6</commons.lang.version>
- <commons.fileupload.version>1.3.1</commons.fileupload.version>
- <commons.collections.version>3.2.2</commons.collections.version>
- <commons.beanutils.version>1.9.3</commons.beanutils.version>
- <commons.io.version>2.5</commons.io.version>
- <commons.codec.version>1.10</commons.codec.version>
- <fastjson.version>1.2.45</fastjson.version>
- <joda.time.version>2.9.9</joda.time.version>
- <lombok.version>1.18.4</lombok.version>
- <swagger.version>2.7.0</swagger.version>
- <quartz.version>2.3.0</quartz.version>
- <shiro.version>1.4.0</shiro.version>
- <kaptcha.version>0.0.9</kaptcha.version>
- <qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
- <aliyun.oss.version>2.5.0</aliyun.oss.version>
- <qcloud.cos.version>4.4</qcloud.cos.version>
- <swagger.version>2.7.0</swagger.version>
- <commons-lang3.version>3.3.2</commons-lang3.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-aop</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>${jedis.version}</version>
- </dependency>
- <!-- mysql驱动 -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
- </dependency>
- <!-- oracle驱动 -->
- <dependency>
- <groupId>com.oracle</groupId>
- <artifactId>ojdbc6</artifactId>
- <version>${oracle.version}</version>
- </dependency>
- <!-- mssql驱动 -->
- <dependency>
- <groupId>com.microsoft.sqlserver</groupId>
- <artifactId>sqljdbc4</artifactId>
- <version>${mssql.version}</version>
- </dependency>
- <!-- postgresql驱动 -->
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- </dependency>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid-spring-boot-starter</artifactId>
- <version>${druid.version}</version>
- </dependency>
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>${mybatisplus.version}</version>
- <exclusions>
- <exclusion>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-generator</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>${fastjson.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>${commons.lang.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-fileupload</groupId>
- <artifactId>commons-fileupload</artifactId>
- <version>${commons.fileupload.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>${commons.collections.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>${commons.beanutils.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons.io.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>${commons.codec.version}</version>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>${joda.time.version}</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>${lombok.version}</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>${swagger.version}</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${swagger.version}</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-freemarker</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-mail</artifactId>
- </dependency>
- <dependency>
- <groupId>org.quartz-scheduler</groupId>
- <artifactId>quartz</artifactId>
- <version>${quartz.version}</version>
- <exclusions>
- <exclusion>
- <groupId>com.mchange</groupId>
- <artifactId>c3p0</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.zaxxer</groupId>
- <artifactId>HikariCP-java6</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-core</artifactId>
- <version>${shiro.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shiro</groupId>
- <artifactId>shiro-spring</artifactId>
- <version>${shiro.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.axet</groupId>
- <artifactId>kaptcha</artifactId>
- <version>${kaptcha.version}</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>${swagger.version}</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>${swagger.version}</version>
- </dependency>
- <dependency>
- <groupId>com.qiniu</groupId>
- <artifactId>qiniu-java-sdk</artifactId>
- <version>${qiniu.version}</version>
- </dependency>
- <dependency>
- <groupId>com.aliyun.oss</groupId>
- <artifactId>aliyun-sdk-oss</artifactId>
- <version>${aliyun.oss.version}</version>
- </dependency>
- <dependency>
- <groupId>com.qcloud</groupId>
- <artifactId>cos_api</artifactId>
- <version>${qcloud.cos.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>5.1.5.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>5.1.5.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-test</artifactId>
- <version>2.1.3.RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>RELEASE</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>${commons-lang3.version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.8.5</version>
- </dependency>
- <dependency>
- <groupId>com.jcraft</groupId>
- <artifactId>jsch</artifactId>
- <version>0.1.54</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-websocket</artifactId>
- <version>2.0.4.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>commons-net</groupId>
- <artifactId>commons-net</artifactId>
- <version>3.6</version>
- </dependency>
- <dependency>
- <groupId>org.yaml</groupId>
- <artifactId>snakeyaml</artifactId>
- <version>1.27</version>
- </dependency>
-
- <!-- prometheus java sdk -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-core</artifactId>
- </dependency>
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-registry-prometheus</artifactId>
- </dependency>
-
- <!-- snmp -->
- <dependency>
- <groupId>org.snmp4j</groupId>
- <artifactId>snmp4j</artifactId>
- <version>2.6.2</version>
- </dependency>
- </dependencies>
-
- <build>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>8</source>
- <target>8</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- <!-- 跳过单元测试 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- <plugin>
- <groupId>com.spotify</groupId>
- <artifactId>docker-maven-plugin</artifactId>
- <version>0.4.14</version>
- <configuration>
- <imageName>nz/confagent</imageName>
- <dockerDirectory>${project.basedir}</dockerDirectory>
- <resources>
- <resource>
- <targetPath>/</targetPath>
- <directory>${project.build.directory}</directory>
- <include>${project.build.finalName}.jar</include>
- </resource>
- </resources>
- </configuration>
- <!-- 运行命令 mvn clean package docker:build 打包并生成docker镜像 -->
- </plugin>
- </plugins>
- </build>
-
- <!-- 阿里云maven仓库 -->
- <repositories>
- <repository>
- <id>public</id>
- <name>aliyun nexus</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>public</id>
- <name>aliyun nexus</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>2.1.3.RELEASE</version>
+ <relativePath/> <!-- lookup parent from repository -->
+ </parent>
+ <groupId>com.nis</groupId>
+ <artifactId>nz-confagent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>nz-confagent</name>
+ <description>confagent</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <java.version>1.8</java.version>
+ <junit.version>4.12</junit.version>
+ <jedis.version>2.9.0</jedis.version>
+ <druid.version>1.1.24</druid.version>
+ <mybatisplus.version>3.0.7.1</mybatisplus.version>
+ <mysql.version>5.1.48</mysql.version>
+ <mssql.version>4.0</mssql.version>
+ <oracle.version>11.2.0.3</oracle.version>
+ <commons.lang.version>2.6</commons.lang.version>
+ <commons.fileupload.version>1.3.1</commons.fileupload.version>
+ <commons.collections.version>3.2.2</commons.collections.version>
+ <commons.beanutils.version>1.9.3</commons.beanutils.version>
+ <commons.io.version>2.5</commons.io.version>
+ <commons.codec.version>1.10</commons.codec.version>
+ <fastjson.version>1.2.45</fastjson.version>
+ <joda.time.version>2.9.9</joda.time.version>
+ <lombok.version>1.18.4</lombok.version>
+ <swagger.version>2.7.0</swagger.version>
+ <quartz.version>2.3.0</quartz.version>
+ <shiro.version>1.4.0</shiro.version>
+ <kaptcha.version>0.0.9</kaptcha.version>
+ <qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
+ <aliyun.oss.version>2.5.0</aliyun.oss.version>
+ <qcloud.cos.version>4.4</qcloud.cos.version>
+ <swagger.version>2.7.0</swagger.version>
+ <commons-lang3.version>3.3.2</commons-lang3.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-redis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>redis.clients</groupId>
+ <artifactId>jedis</artifactId>
+ <version>${jedis.version}</version>
+ </dependency>
+ <!-- mysql驱动 -->
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>${mysql.version}</version>
+ </dependency>
+ <!-- oracle驱动 -->
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc6</artifactId>
+ <version>${oracle.version}</version>
+ </dependency>
+ <!-- mssql驱动 -->
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>sqljdbc4</artifactId>
+ <version>${mssql.version}</version>
+ </dependency>
+ <!-- postgresql驱动 -->
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>druid-spring-boot-starter</artifactId>
+ <version>${druid.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.baomidou</groupId>
+ <artifactId>mybatis-plus-boot-starter</artifactId>
+ <version>${mybatisplus.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.baomidou</groupId>
+ <artifactId>mybatis-plus-generator</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>${fastjson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>${commons.lang.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>${commons.fileupload.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>${commons.collections.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>${commons.beanutils.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>${commons.io.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>${commons.codec.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>${joda.time.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>${lombok.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-redis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-freemarker</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-mail</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.quartz-scheduler</groupId>
+ <artifactId>quartz</artifactId>
+ <version>${quartz.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.mchange</groupId>
+ <artifactId>c3p0</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP-java6</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-core</artifactId>
+ <version>${shiro.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-spring</artifactId>
+ <version>${shiro.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.github.axet</groupId>
+ <artifactId>kaptcha</artifactId>
+ <version>${kaptcha.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.qiniu</groupId>
+ <artifactId>qiniu-java-sdk</artifactId>
+ <version>${qiniu.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.aliyun.oss</groupId>
+ <artifactId>aliyun-sdk-oss</artifactId>
+ <version>${aliyun.oss.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.qcloud</groupId>
+ <artifactId>cos_api</artifactId>
+ <version>${qcloud.cos.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>5.1.5.RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>5.1.5.RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-test</artifactId>
+ <version>2.1.3.RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>RELEASE</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons-lang3.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.5</version>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.54</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-websocket</artifactId>
+ <version>2.0.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>3.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.27</version>
+ </dependency>
+
+ <!-- prometheus java sdk -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.micrometer</groupId>
+ <artifactId>micrometer-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.micrometer</groupId>
+ <artifactId>micrometer-registry-prometheus</artifactId>
+ </dependency>
+
+ <!-- snmp -->
+ <dependency>
+ <groupId>org.snmp4j</groupId>
+ <artifactId>snmp4j</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>cn.hutool</groupId>
+ <artifactId>hutool-all</artifactId>
+ <version>5.5.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <source>8</source>
+ <target>8</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ <!-- 跳过单元测试 -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>0.4.14</version>
+ <configuration>
+ <imageName>nz/confagent</imageName>
+ <dockerDirectory>${project.basedir}</dockerDirectory>
+ <resources>
+ <resource>
+ <targetPath>/</targetPath>
+ <directory>${project.build.directory}</directory>
+ <include>${project.build.finalName}.jar</include>
+ </resource>
+ </resources>
+ </configuration>
+ <!-- 运行命令 mvn clean package docker:build 打包并生成docker镜像 -->
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- 阿里云maven仓库 -->
+ <repositories>
+ <repository>
+ <id>public</id>
+ <name>aliyun nexus</name>
+ <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>public</id>
+ <name>aliyun nexus</name>
+ <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
diff --git a/src/main/java/com/nis/controller/TrafficController.java b/src/main/java/com/nis/controller/TrafficController.java
index 0b032f8..46ced5f 100644
--- a/src/main/java/com/nis/controller/TrafficController.java
+++ b/src/main/java/com/nis/controller/TrafficController.java
@@ -1,5 +1,6 @@
package com.nis.controller;
+import cn.hutool.log.Log;
import com.nis.service.TrafficService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,9 +14,9 @@ import org.springframework.web.bind.annotation.RestController;
* @version: 1.0
*/
@RestController
-@Slf4j
+//@Slf4j
public class TrafficController {
-
+ private Log log = Log.get();
@Autowired
private TrafficService trafficService;
diff --git a/src/main/java/com/nis/job/ConfagentJob.java b/src/main/java/com/nis/job/ConfagentJob.java
index 40cd548..8204b17 100644
--- a/src/main/java/com/nis/job/ConfagentJob.java
+++ b/src/main/java/com/nis/job/ConfagentJob.java
@@ -1,5 +1,10 @@
package com.nis.job;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.net.url.UrlBuilder;
+import cn.hutool.core.util.ReflectUtil;
+import cn.hutool.core.util.URLUtil;
+import cn.hutool.log.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -9,6 +14,7 @@ import com.nis.util.CommonUtils;
import com.nis.util.Constant;
import com.nis.util.RuntimeUtil;
import com.nis.util.YamlUtil;
+import com.sun.javafx.fxml.builder.URLBuilder;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
@@ -37,7 +43,7 @@ import java.util.stream.Collectors;
*/
@DisallowConcurrentExecution
public class ConfagentJob extends QuartzJobBean {
- private Logger logger = LoggerFactory.getLogger(ConfagentJob.class);
+ private Log logger = Log.get();
private static Map<String,Integer> confEvents=null;
@Autowired
private PromserverService promserverService;
@@ -133,7 +139,9 @@ public class ConfagentJob extends QuartzJobBean {
ResponseEntity<String> responseEntity = null;
try {
RestTemplate restTemplate = new RestTemplate();
- responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD), null, String.class);
+// responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD), null, String.class);
+ int port= Integer.parseInt(promServerPort);
+ responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);
} catch (RestClientException e) {
logger.error("热加载 global prometheus api 接口失败,API 地址是:" + String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e);
}
@@ -159,7 +167,9 @@ public class ConfagentJob extends QuartzJobBean {
ResponseEntity<String> responseEntity = null;
try {
RestTemplate restTemplate = new RestTemplate();
- responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD), null, String.class);
+// responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);;
+ int port= Integer.parseInt(promServerPort);
+ responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);
} catch (RestClientException e) {
logger.error("热加载 per-datacenter prometheus api 接口失败,API 地址是:" + String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e);
}
@@ -225,7 +235,8 @@ public class ConfagentJob extends QuartzJobBean {
ResponseEntity<String> responseEntity = null;
try {
RestTemplate restTemplate = new RestTemplate();
- responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD), null, String.class);
+ int port= Integer.parseInt(promServerPort);
+ responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);;
} catch (RestClientException e) {
logger.error("热加载 thanos rule api 接口失败,API 地址是:" + String.format("http://%s:%s%s", ipaddr, promServerPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e);
}
@@ -389,7 +400,9 @@ public class ConfagentJob extends QuartzJobBean {
ResponseEntity<String> responseEntity = null;
try {
RestTemplate restTemplate = new RestTemplate();
- responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, snmpPort, Constant.API_RELOAD), null, String.class);
+// responseEntity = restTemplate.postForEntity(String.format("http://%s:%s%s", ipaddr, snmpPort, Constant.API_RELOAD), null, String.class);
+ int port = Integer.parseInt(snmpPort);
+ responseEntity = ReflectUtil.invoke(restTemplate,"postForEntity",new UrlBuilder().setScheme("http").setHost(ipaddr).setPort(port).addPath(Constant.API_RELOAD).toString(), null, String.class);
} catch (RestClientException e) {
logger.error("热加载 snmp_exporter api 接口失败,API 地址是:" + String.format("http://%s:%s%s", ipaddr, snmpPort, Constant.API_RELOAD) + ",错误信息是:" + e.getMessage(), e);
}
@@ -827,7 +840,7 @@ public class ConfagentJob extends QuartzJobBean {
// 首先获取 启动项 配置文件路径
String startParameterConfigPath = this.startParameterConfigPath(filePath);
logger.info("获取到的 prometheus 启动项配置文件地址是:" + startParameterConfigPath);
- try (RandomAccessFile raf = new RandomAccessFile(new File(startParameterConfigPath), "rw");) {
+ try (RandomAccessFile raf = new RandomAccessFile(FileUtil.file(startParameterConfigPath), "rw");) {
String readLine = null;
long lastPoint = 0; //记住上一次的偏移量
String time=null;
@@ -854,8 +867,10 @@ public class ConfagentJob extends QuartzJobBean {
// 判断本地的保存时间与数据库的设置时间是否一致 不一致则更新同步
if(!time.equals(retentionDays)) {
logger.error("prometheus going to restart , local time is "+ time);
- RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl stop prometheus"});
- RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl start prometheus"});
+ /*RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl stop prometheus"});
+ RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl start prometheus"});*/
+ cn.hutool.core.util.RuntimeUtil.exec("/bin/sh -c systemctl stop prometheus");
+ cn.hutool.core.util.RuntimeUtil.exec("/bin/sh -c systemctl start prometheus");
}
flag=true;
} catch (FileNotFoundException e) {
@@ -868,7 +883,7 @@ public class ConfagentJob extends QuartzJobBean {
private String startParameterConfigPath(String filePath) {
String readLine = "";
- try (RandomAccessFile raf = new RandomAccessFile(new File(filePath), "rw");) {
+ try (RandomAccessFile raf = new RandomAccessFile(FileUtil.file(filePath), "rw");) {
while ((readLine = raf.readLine()) != null) {
if (readLine.startsWith("EnvironmentFile")) {
break;
diff --git a/src/main/java/com/nis/server/SNMPTrapServer.java b/src/main/java/com/nis/server/SNMPTrapServer.java
index 17cc8ba..b756af8 100644
--- a/src/main/java/com/nis/server/SNMPTrapServer.java
+++ b/src/main/java/com/nis/server/SNMPTrapServer.java
@@ -13,6 +13,7 @@ import java.util.Vector;
import javax.annotation.PostConstruct;
+import cn.hutool.log.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snmp4j.CommandResponder;
@@ -91,7 +92,7 @@ import com.nis.util.DateUtil;
@Component
@Order(1)
public class SNMPTrapServer implements CommandResponder,ApplicationRunner{// implements CommandResponder, extends Service
- private static Logger logger = LoggerFactory.getLogger(SNMPTrapServer.class);
+ private static Log logger = Log.get();
private static SNMPTrapServer ts = null;
@Value("${confagent.snmp.trapThredPoolSize}")
private String snmpTrapThredPoolSize;
diff --git a/src/main/java/com/nis/service/impl/TrafficServiceImpl.java b/src/main/java/com/nis/service/impl/TrafficServiceImpl.java
index 7c26e5e..323967b 100644
--- a/src/main/java/com/nis/service/impl/TrafficServiceImpl.java
+++ b/src/main/java/com/nis/service/impl/TrafficServiceImpl.java
@@ -1,5 +1,6 @@
package com.nis.service.impl;
+import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.nis.dao.TrafficDao;
import com.nis.entity.Traffic;
@@ -28,9 +29,9 @@ import java.util.stream.Collectors;
*/
@Service
-@Slf4j
+//@Slf4j
public class TrafficServiceImpl implements TrafficService {
-
+ private Log log = Log.get();
private static ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
@Value("${confagent.snmp.scrapeTimeOut}")
diff --git a/src/main/java/com/nis/util/BufferReaderWrapper.java b/src/main/java/com/nis/util/BufferReaderWrapper.java
index 771e154..e8e0a9c 100644
--- a/src/main/java/com/nis/util/BufferReaderWrapper.java
+++ b/src/main/java/com/nis/util/BufferReaderWrapper.java
@@ -6,10 +6,25 @@ import java.io.Reader;
public class BufferReaderWrapper extends BufferedReader
{
+ public Reader in;
+ public static final int MAX_STR_LEN=1024;
public BufferReaderWrapper(Reader in) {
super(in);
+ this.in=in;
}
public String load() throws IOException {
- return super.readLine();
+ StringBuffer sb = new StringBuffer();
+ int intC;
+ while ((intC = in.read()) != -1) {
+ char c = (char) intC;
+ if (c == '\n') {
+ break;
+ }
+ if (sb.length() >= MAX_STR_LEN) {
+ throw new IOException("input too long");
+ }
+ sb.append(c);
+ }
+ return sb.toString();
}
}
diff --git a/src/main/java/com/nis/util/DateUtil.java b/src/main/java/com/nis/util/DateUtil.java
index 45b1cb7..0fd0424 100644
--- a/src/main/java/com/nis/util/DateUtil.java
+++ b/src/main/java/com/nis/util/DateUtil.java
@@ -26,396 +26,9 @@ import java.util.*;
public class DateUtil {
- /**
- * 配置时区 默认为0
- */
- public static int configTimeZone = 0;
-
private static final Object lock = new Object();
private static final Map<String, ThreadLocal<SimpleDateFormat>> pool = new HashMap<String, ThreadLocal<SimpleDateFormat>>();
- /**
- * 获取YYYY格式
- *
- * @return
- */
- public static String getYear() {
- return formatDate(new Date(), "yyyy");
- }
-
- /**
- * 获取YYYY格式
- *
- * @return
- */
- public static String getYear(Date date) {
- return formatDate(date, "yyyy");
- }
-
- /**
- * 获取YYYY-MM-DD格式
- *
- * @return
- */
- public static String getDay() {
- return formatDate(new Date(), "yyyy-MM-dd");
- }
-
- /**
- * 获取YYYY-MM-DD格式
- *
- * @return
- */
- public static String getDay(Date date) {
- return formatDate(date, "yyyy-MM-dd");
- }
-
- /**
- * 获取YYYYMMDD格式
- *
- * @return
- */
- public static String getDays() {
- return formatDate(new Date(), "yyyyMMdd");
- }
-
- /**
- * 获取YYYYMMDD格式
- *
- * @return
- */
- public static String getDays(Date date) {
- return formatDate(date, "yyyyMMdd");
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss格式
- *
- * @return
- */
- public static String getTime() {
- return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss.SSS格式
- *
- * @return
- */
- public static String getMsTime() {
- return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
- }
-
- /**
- * 获取YYYYMMDDHHmmss格式
- *
- * @return
- */
- public static String getAllTime() {
- return formatDate(new Date(), "yyyyMMddHHmmss");
- }
-
- /**
- * 获取YYYYMMDDHHmmss格式
- *
- * @return
- */
- public static String getNowTime() {
- return formatDate(new Date(), "yyyyMMddHHmmsss");
- }
-
- /**
- * 获取YYYY-MM-DD HH:mm:ss格式
- *
- * @return
- */
- public static String getTime(Date date) {
- return formatDate(date, "yyyy-MM-dd HH:mm:ss");
- }
-
- public static String formatDate(Date date, String pattern) {
- String formatDate = null;
- if (StringUtils.isNotEmpty(pattern)) {
- formatDate = DateFormatUtils.format(date, pattern);
- } else {
- formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
- }
- return formatDate;
- }
-
- /**
- * @Title: compareDate
- * @Description:(日期比较,如果s>=e 返回true 否则返回false)
- * @param s
- * @param e
- * @return boolean
- * @throws
- * @author luguosui
- */
- public static boolean compareDate(String s, String e) {
- if (parseDate(s) == null || parseDate(e) == null) {
- return false;
- }
- return parseDate(s).getTime() >= parseDate(e).getTime();
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parseDate(String date) {
- return parse(date,"yyyy-MM-dd");
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parseTime(String date) {
- return parse(date,"yyyy-MM-dd HH:mm:ss");
- }
-
- /**
- * @Title: compareDate
- * @Description:(日期比较,如果s>=e 返回true 否则返回false)
- * @param s
- * @param e
- * @param pattern 格式
- * @return boolean
- * @throws
- * @author luguosui
- */
- public static boolean compareDatePattern(String s, String e,String pattern) {
- if (parse(s,pattern) == null || parse(e,pattern) == null) {
- return false;
- }
- return parse(s,pattern).getTime() >= parse(e,pattern).getTime();
- }
-
-
- /**
- * @Title: compareDate
- * @Description:(日期比较,如果s>e 返回true 否则返回false)
- * @param s
- * @param e
- * @param pattern 格式
- * @return boolean
- * @throws
- * @author luguosui
- */
- public static boolean compareDate(String s, String e,String pattern) {
- if (parse(s,pattern) == null || parse(e,pattern) == null) {
- return false;
- }
- return parse(s,pattern).getTime() > parse(e,pattern).getTime();
- }
-
-
- public static boolean compareDated(String s, String e,String pattern) {
- if (parse(s,pattern) == null || parse(e,pattern) == null) {
- return false;
- }
- return parse(s,pattern).getTime() >= parse(e,pattern).getTime();
- }
-
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static Date parse(String date, String pattern) {
- if (ToolUtil.isNotEmpty(date)) {
- if (ToolUtil.isEmpty(pattern)) {
- return null;
- }
- DateFormat format = getDFormat(pattern);
- format.setLenient(false);
- try {
- return format.parse(date);
- } catch (ParseException e) {
- throw new RuntimeException(e.getMessage());
- }
- }
- return null;
- }
-
- public static SimpleDateFormat getDFormat(String pattern) {
- ThreadLocal<SimpleDateFormat> tl = pool.get(pattern);
- if (tl == null) {
- synchronized (lock) {
- tl = pool.get(pattern);
- if (tl == null) {
- final String p = pattern;
- tl = new ThreadLocal<SimpleDateFormat>() {
- @Override
- protected synchronized SimpleDateFormat initialValue() {
- return new SimpleDateFormat(p);
- }
- };
- pool.put(p, tl);
- }
- }
- }
- return tl.get();
- }
-
- /**
- * 格式化日期
- *
- * @return
- */
- public static String format(Date date, String pattern) {
- return DateFormatUtils.format(date, pattern);
- }
-
- /**
- * 把日期转换为Timestamp
- *
- * @param date
- * @return
- */
- public static Timestamp format(Date date) {
- return new Timestamp(date.getTime());
- }
-
- /**
- * 校验日期是否合法
- *
- * @return
- */
- public static boolean isValidDate(String s) {
- return parse(s, "yyyy-MM-dd HH:mm:ss") != null;
- }
-
-
-
-
- public static int getDiffYear(String startTime, String endTime) {
- DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
- try {
- int years = (int) (((fmt.parse(endTime).getTime() - fmt.parse(
- startTime).getTime()) / (1000 * 60 * 60 * 24)) / 365);
- return years;
- } catch (Exception e) {
- // 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
- return 0;
- }
- }
-
- /**
- * <li>功能描述:时间相减得到天数
- *
- * @param beginDateStr
- * @param endDateStr
- * @return long
- * @author Administrator
- */
- public static long getDaySub(String beginDateStr, String endDateStr) {
- long day = 0;
- SimpleDateFormat format = new SimpleDateFormat(
- "yyyy-MM-dd");
- Date beginDate = null;
- Date endDate = null;
-
- try {
- beginDate = format.parse(beginDateStr);
- endDate = format.parse(endDateStr);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
- // System.out.println("相隔的天数="+day);
-
- return day;
- }
-
- /**
- * 得到n天之后的日期
- *
- * @param days
- * @return
- */
- public static String getAfterDayDate(String days) {
- int daysInt = Integer.parseInt(days);
-
- Calendar canlendar = Calendar.getInstance(); // java.util包
- canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
- Date date = canlendar.getTime();
-
- SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String dateStr = sdfd.format(date);
-
- return dateStr;
- }
-
- /**
- * 得到n天之后是周几
- *
- * @param days
- * @return
- */
- public static String getAfterDayWeek(String days) {
- int daysInt = Integer.parseInt(days);
-
- Calendar canlendar = Calendar.getInstance(); // java.util包
- canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
- Date date = canlendar.getTime();
-
- SimpleDateFormat sdf = new SimpleDateFormat("E");
- String dateStr = sdf.format(date);
-
- return dateStr;
- }
- public static String addtime(String timeStr,String addnumber){
- String str=null;
- try{
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = df.parse(timeStr);
- Calendar gc =new GregorianCalendar();
- gc.setTime(date);
- gc.add(GregorianCalendar.MINUTE,Integer.parseInt(addnumber));
- str=df.format(gc.getTime());
- }catch (Exception e) {
- }
- return str;
- }
-
-
- /**
- * 验证一个日期字符串,是否符合格式
- *
- * @param simpleDateFormat
- * @param dates
- */
- public static void validDate(SimpleDateFormat simpleDateFormat, String... dates) {
- try {
- for (String date : dates) {
- simpleDateFormat.setLenient(false);
- simpleDateFormat.parse(date);
- }
- } catch (Exception ex) {
- throw new RuntimeException(ex.getMessage());
- }
- }
- /**
- * 验证一个日期字符串,是否符合格式
- *
- * @param simpleDateFormat
- * @param dates
- */
- public static void validDate(SimpleDateFormat simpleDateFormat, List<String> dates) {
- try {
- for (String date : dates) {
- simpleDateFormat.setLenient(false);
- simpleDateFormat.parse(date);
- }
- } catch (Exception ex) {
- throw new RuntimeException(ex.getMessage());
- }
- }
/**
* 获取配置时区
diff --git a/src/main/java/com/nis/util/SnmpUtil.java b/src/main/java/com/nis/util/SnmpUtil.java
index 4fcbe6a..cc1cc72 100644
--- a/src/main/java/com/nis/util/SnmpUtil.java
+++ b/src/main/java/com/nis/util/SnmpUtil.java
@@ -1,5 +1,6 @@
package com.nis.util;
+import cn.hutool.log.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.snmp4j.*;
@@ -13,15 +14,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
@Component
-@Slf4j
+//@Slf4j
public class SnmpUtil {
-
+ private Log log= Log.get();
@Value("${confagent.snmp.walkTimeOut}")
private Integer DEFAULT_TIMEOUT;
@@ -61,7 +59,7 @@ public class SnmpUtil {
octetPrivPassword = new OctetString(privPassword);
}
- String password = auth.get("password");
+ String password = Arrays.toString(auth.get("password").getBytes());
OctetString octetpassword = null;
if(StringUtils.isNotEmpty(password)){
octetpassword = new OctetString(password);
diff --git a/src/main/java/com/nis/util/ToolUtil.java b/src/main/java/com/nis/util/ToolUtil.java
deleted file mode 100644
index d5f36f8..0000000
--- a/src/main/java/com/nis/util/ToolUtil.java
+++ /dev/null
@@ -1,718 +0,0 @@
-/**
- * Copyright (c) 2015-2016, Chill Zhuang 庄骞 ([email protected]).
- * <p>
- * Licensed 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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 com.nis.util;
-
-
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.regex.Pattern;
-
-/**
- * 高频方法集合类
- */
-public class ToolUtil {
-
-
- /**
- * 字符连接符
- */
- private static final char SEPARATOR = '_';
- /**
- * 默认编码
- */
- private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
-
- private static Pattern humpPattern = Pattern.compile("[A-Z]");
-
-
-
-
-
- /**
- * 下划线命名 转 驼峰命名 首字母小写
- *
- * @param s the s
- * @return String toCamelCase("hello_world") == "helloWorld" toCapitalizeCamelCase("hello_world") == "HelloWorld" toUnderScoreCase("helloWorld") = "hello_world"
- */
- public static String toCamelCase(String s) {
- if (s == null) {
- return null;
- }
-
- String ls = s.toLowerCase();
-
- StringBuilder sb = new StringBuilder(ls.length());
- boolean upperCase = false;
- for (int i = 0; i < ls.length(); i++) {
- char c = ls.charAt(i);
-
- if (c == SEPARATOR) {
- upperCase = true;
- } else if (upperCase) {
- sb.append(Character.toUpperCase(c));
- upperCase = false;
- } else {
- sb.append(c);
- }
- }
-
- return sb.toString();
- }
-
- /**
- * 下划线命名 转 驼峰命名 首字母大写
- *
- * @param s the s
- * @return String toCamelCase("hello_world") == "helloWorld" toCapitalizeCamelCase("hello_world") == "HelloWorld" toUnderScoreCase("helloWorld") = "hello_world"
- */
- public static String toCapitalizeCamelCase(String s) {
- if (s == null) {
- return null;
- }
- String cs = toCamelCase(s);
- return cs.substring(0, 1).toUpperCase() + cs.substring(1);
- }
-
- /**
- * 驼峰命名 转 下划线命名
- *
- * @param s the s
- * @return String toCamelCase("hello_world") == "helloWorld" toCapitalizeCamelCase("hello_world") == "HelloWorld" toUnderScoreCase("helloWorld") = "hello_world"
- */
- public static String toUnderScoreCase(String s) {
- if (s == null) {
- return null;
- }
-
- StringBuilder sb = new StringBuilder();
- boolean upperCase = false;
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
-
- boolean nextUpperCase = true;
-
- if (i < (s.length() - 1)) {
- nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
- }
-
- if ((i > 0) && Character.isUpperCase(c)) {
- if (!upperCase || !nextUpperCase) {
- sb.append(SEPARATOR);
- }
- upperCase = true;
- } else {
- upperCase = false;
- }
-
- sb.append(Character.toLowerCase(c));
- }
-
- return sb.toString();
- }
-
- /**
- * 获取随机位数的字符串
- *
- * @author fengshuonan
- * @Date 2017/8/24 14:09
- */
- public static String getRandomString(int length) {
- String base = "abcdefghijklmnopqrstuvwxyz0123456789";
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < length; i++) {
- int number = random.nextInt(base.length());
- sb.append(base.charAt(number));
- }
- return sb.toString();
- }
-
- /**
- * 判断一个对象是否是时间类型
- *
- * @author stylefeng
- * @Date 2017/4/18 12:55
- */
- public static String dateType(Object o) {
- if (o instanceof Date) {
- return DateUtil.getDay((Date) o);
- } else {
- return o.toString();
- }
- }
-
- /**
- * 获取异常的具体信息
- *
- * @author fengshuonan
- * @Date 2017/3/30 9:21
- * @version 2.0
- */
- public static String getExceptionMsg(Exception e) {
- StringWriter sw = new StringWriter();
- try {
- e.printStackTrace(new PrintWriter(sw));
- } finally {
- try {
- sw.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- return sw.getBuffer().toString().replaceAll("\\$", "T");
- }
-
- /**
- * 比较两个对象是否相等。<br>
- * 相同的条件有两个,满足其一即可:<br>
- * 1. obj1 == null && obj2 == null; 2. obj1.equals(obj2)
- *
- * @param obj1 对象1
- * @param obj2 对象2
- * @return 是否相等
- */
- public static boolean equals(Object obj1, Object obj2) {
- return (obj1 != null) ? (obj1.equals(obj2)) : (obj2 == null);
- }
-
- /**
- * 计算对象长度,如果是字符串调用其length函数,集合类调用其size函数,数组调用其length属性,其他可遍历对象遍历计算长度
- *
- * @param obj 被计算长度的对象
- * @return 长度
- */
- public static int length(Object obj) {
- if (obj == null) {
- return 0;
- }
- if (obj instanceof CharSequence) {
- return ((CharSequence) obj).length();
- }
- if (obj instanceof Collection) {
- return ((Collection<?>) obj).size();
- }
- if (obj instanceof Map) {
- return ((Map<?, ?>) obj).size();
- }
-
- int count;
- if (obj instanceof Iterator) {
- Iterator<?> iter = (Iterator<?>) obj;
- count = 0;
- while (iter.hasNext()) {
- count++;
- iter.next();
- }
- return count;
- }
- if (obj instanceof Enumeration) {
- Enumeration<?> enumeration = (Enumeration<?>) obj;
- count = 0;
- while (enumeration.hasMoreElements()) {
- count++;
- enumeration.nextElement();
- }
- return count;
- }
- if (obj.getClass().isArray() == true) {
- return Array.getLength(obj);
- }
- return -1;
- }
-
- /**
- * 对象中是否包含元素
- *
- * @param obj 对象
- * @param element 元素
- * @return 是否包含
- */
- public static boolean contains(Object obj, Object element) {
- if (obj == null) {
- return false;
- }
- if (obj instanceof String) {
- if (element == null) {
- return false;
- }
- return ((String) obj).contains(element.toString());
- }
- if (obj instanceof Collection) {
- return ((Collection<?>) obj).contains(element);
- }
- if (obj instanceof Map) {
- return ((Map<?, ?>) obj).values().contains(element);
- }
-
- if (obj instanceof Iterator) {
- Iterator<?> iter = (Iterator<?>) obj;
- while (iter.hasNext()) {
- Object o = iter.next();
- if (equals(o, element)) {
- return true;
- }
- }
- return false;
- }
- if (obj instanceof Enumeration) {
- Enumeration<?> enumeration = (Enumeration<?>) obj;
- while (enumeration.hasMoreElements()) {
- Object o = enumeration.nextElement();
- if (equals(o, element)) {
- return true;
- }
- }
- return false;
- }
- if (obj.getClass().isArray() == true) {
- int len = Array.getLength(obj);
- for (int i = 0; i < len; i++) {
- Object o = Array.get(obj, i);
- if (equals(o, element)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * 对象是否不为空(新增)
- *
- * @param o String,List,Map,Object[],int[],long[]
- * @return
- */
- public static boolean isNotEmpty(Object o) {
- return !isEmpty(o);
- }
-
- /**
- * 对象是否为空
- *
- * @param o String,List,Map,Object[],int[],long[]
- * @return
- */
- @SuppressWarnings("rawtypes")
- public static boolean isEmpty(Object o) {
- if (o == null) {
- return true;
- }
- if (o instanceof String) {
- if (o.toString().trim().equals("")) {
- return true;
- }
- } else if (o instanceof List) {
- if (((List) o).size() == 0) {
- return true;
- }
- } else if (o instanceof Map) {
- if (((Map) o).size() == 0) {
- return true;
- }
- } else if (o instanceof Set) {
- if (((Set) o).size() == 0) {
- return true;
- }
- } else if (o instanceof Object[]) {
- if (((Object[]) o).length == 0) {
- return true;
- }
- } else if (o instanceof int[]) {
- if (((int[]) o).length == 0) {
- return true;
- }
- } else if (o instanceof long[]) {
- if (((long[]) o).length == 0) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 对象组中是否存在 Empty Object
- *
- * @param os 对象组
- * @return
- */
- public static boolean isOneEmpty(Object... os) {
- for (Object o : os) {
- if (isEmpty(o)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 对象组中是否全是 Empty Object
- *
- * @param os
- * @return
- */
- public static boolean isAllEmpty(Object... os) {
- for (Object o : os) {
- if (!isEmpty(o)) {
- return false;
- }
- }
- return true;
- }
- /**
- * 对象组都不是empty
- */
- public static boolean isNotAllEmpty(Object... obj){
- for (Object o:obj){
- if (isEmpty(o)){
- return false;
- }
- }
- return true;
- }
-
- /**
- * 是否为数字
- *
- * @param obj
- * @return
- */
- public static boolean isNum(Object obj) {
- try {
- Integer.parseInt(obj.toString());
- } catch (Exception e) {
- return false;
- }
- return true;
- }
-
- /**
- * 如果为空, 则调用默认值
- *
- * @param str
- * @return
- */
- public static Object getValue(Object str, Object defaultValue) {
- if (isEmpty(str)) {
- return defaultValue;
- }
- return str;
- }
-
-
-
- /**
- * 强转->string,并去掉多余空格
- *
- * @param str
- * @return
- */
- public static String toStr(Object str) {
- return toStr(str, "");
- }
-
- /**
- * 强转->string,并去掉多余空格
- *
- * @param str
- * @param defaultValue
- * @return
- */
- public static String toStr(Object str, String defaultValue) {
- if (null == str) {
- return defaultValue;
- }
- return str.toString().trim();
- }
-
- /**
- * map的key转为小写
- *
- * @param map
- * @return Map<String,Object>
- */
- public static Map<String, Object> caseInsensitiveMap(Map<String, Object> map) {
- Map<String, Object> tempMap = new HashMap<>();
- for (String key : map.keySet()) {
- tempMap.put(key.toLowerCase(), map.get(key));
- }
- return tempMap;
- }
-
- /**
- * 获取map中第一个数据值
- *
- * @param <K> Key的类型
- * @param <V> Value的类型
- * @param map 数据源
- * @return 返回的值
- */
- public static <K, V> V getFirstOrNull(Map<K, V> map) {
- V obj = null;
- for (Entry<K, V> entry : map.entrySet()) {
- obj = entry.getValue();
- if (obj != null) {
- break;
- }
- }
- return obj;
- }
-
- /**
- * 创建StringBuilder对象
- *
- * @return StringBuilder对象
- */
- public static StringBuilder builder(String... strs) {
- final StringBuilder sb = new StringBuilder();
- for (String str : strs) {
- sb.append(str);
- }
- return sb;
- }
-
- /**
- * 创建StringBuilder对象
- *
- * @return StringBuilder对象
- */
- public static void builder(StringBuilder sb, String... strs) {
- for (String str : strs) {
- sb.append(str);
- }
- }
-
- /**
- * 去掉指定后缀
- *
- * @param str 字符串
- * @param suffix 后缀
- * @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
- */
- public static String removeSuffix(String str, String suffix) {
- if (isEmpty(str) || isEmpty(suffix)) {
- return str;
- }
-
- if (str.endsWith(suffix)) {
- return str.substring(0, str.length() - suffix.length());
- }
- return str;
- }
-
- /**
- * 判断是否是windows操作系统
- *
- * @author stylefeng
- * @Date 2017/5/24 22:34
- */
- public static Boolean isWinOs() {
- String os = System.getProperty("os.name");
- if (os.toLowerCase().startsWith("win")) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 获取临时目录
- *
- * @author stylefeng
- * @Date 2017/5/24 22:35
- */
- public static String getTempPath() {
- return System.getProperty("java.io.tmpdir");
- }
-
- /**
- * 把一个数转化为int
- *
- * @author fengshuonan
- * @Date 2017/11/15 下午11:10
- */
- public static Integer toInt(Object val) {
- if (val instanceof Double) {
- BigDecimal bigDecimal = new BigDecimal((Double) val);
- return bigDecimal.intValue();
- } else {
- return Integer.valueOf(val.toString());
- }
-
- }
-
- /**
- * 获取项目路径
- */
- public static String getWebRootPath(String filePath) {
- try {
- String path = ToolUtil.class.getClassLoader().getResource("").toURI().getPath();
- path = path.replace("/WEB-INF/classes/", "");
- path = path.replace("/target/classes/", "");
- path = path.replace("file:/", "");
- if (ToolUtil.isEmpty(filePath)) {
- return path;
- } else {
- return path + "/" + filePath;
- }
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * 字符串是否包含不可见字符
- * 包含:true
- * 不包含:false
- * @param content
- * @return Boolean
- */
- public static Boolean containsInvisibleChar(String content) {
- if (content != null && content.length() > 0) {
- char[] contentCharArr = content.toCharArray();
- for (int i = 0; i < contentCharArr.length; i++) {
- if ((contentCharArr[i] <= 0x1F) || contentCharArr[i] == 0x7F) {
- return true;
- }
- }
- return false;
- }
- return false;
- }
-
- /**
- * 获取客户端ip
- * @param req
- * @return
- */
- public static String getRealIp(HttpServletRequest req) {
- String ip = req.getHeader("x-forwarded-for");
-
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = req.getHeader("Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = req.getHeader("WL-Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = req.getRemoteAddr();
- }
- if (ip == null || ip.length() == 0 || "0:0:0:0:0:0:0:1".equals(ip)) {
- ip = "127.0.0.1";
- }
- return ip;
- }
-
- /**
- * 判断开始时间是否在结束时间之前
- * @param opStartTime
- * @param opEndTime
- */
- public static void validateOpTime(String opStartTime,String opEndTime){
- Date startTime = DateUtil.parseTime(opStartTime);
- Date endTime = DateUtil.parseTime(opEndTime);
- if (ToolUtil.isNotAllEmpty(opStartTime,opEndTime)){
- if (startTime.after(endTime)){
- throw new RuntimeException("Incorrect Date Format");
- }
- }
-
- }
-
- /**
- * 验证开始时间和结束时间:格式 开始时间不能大于结束时间
- * @param startTime
- * @param endTime
- * @return
- */
- public static Boolean validateStartAndEndDateFormat(String startTime,String endTime){
- Boolean result = true;
- try {
- Date start = ToolUtil.isNotEmpty(startTime)?DateUtil.parseTime(startTime):null;
- Date end = ToolUtil.isNotEmpty(endTime)?DateUtil.parseTime(endTime):null;
- if (ToolUtil.isNotEmpty(start)&&ToolUtil.isNotEmpty(end)&&start.after(end)){
- result = false;
- }
- }catch (Exception e){
- result = false;
- }
- return result;
- }
-
- /**
- * 获取Annotation 中 memberValues的值
- *
- * @param object
- * @param property
- * @param <T>
- * @return
- */
- public static <T> Object getFieldValue(T object, String property) {
- if (object != null && property != null) {
- Class<T> currClass = (Class<T>) object.getClass();
- try {
- Field field = currClass.getDeclaredField(property);
- field.setAccessible(true);
- return field.get(object);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- /**
- * //递归获取cls实体对象及父级对象的属性 wx:修改,子类覆盖父类的同名方法
- *
- * @param list
- * @param cls
- */
- public static void getFields(List<Field> list, Class<?> cls) {
- Field[] fields = cls.getDeclaredFields();
- if (fields != null && fields.length > 0) {
- List<Field> tempList = new ArrayList<>();
- for (Field field : fields) {
- if (list.size() == 0) {
- tempList.add(field);
- } else {
- boolean has = false;
- for (Field checkF : list) {
- if (checkF.getName().equals(field.getName())) {
- has = true;
- break;
- }
- }
- if (!has) {
- tempList.add(field);
- }
- }
- }
- list.addAll(tempList);
- }
- if (cls.getSuperclass() != null) {
- getFields(list, cls.getSuperclass());
- }
- }
-}
diff --git a/src/main/java/com/nis/util/YamlUtil.java b/src/main/java/com/nis/util/YamlUtil.java
index 1c8ade5..ea51072 100644
--- a/src/main/java/com/nis/util/YamlUtil.java
+++ b/src/main/java/com/nis/util/YamlUtil.java
@@ -1,6 +1,9 @@
package com.nis.util;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.RuntimeUtil;
+import cn.hutool.log.Log;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -17,7 +20,7 @@ import java.util.Map;
import java.util.Set;
public class YamlUtil {
- private static Logger logger = LoggerFactory.getLogger(YamlUtil.class);
+ private static Log logger = Log.get();
/**
* snmp配置相关
* @param param
@@ -34,7 +37,7 @@ public class YamlUtil {
OutputStream out = null;
OutputStreamWriter osw = null;
try {
- File file = new File(ymlPath);
+ File file = FileUtil.file(ymlPath);
out=new FileOutputStream(file);
osw=new OutputStreamWriter(out, "UTF-8");
for(String s : param) {
@@ -84,7 +87,7 @@ public class YamlUtil {
OutputStream out = null;
OutputStreamWriter osw = null;
try {
- File file = new File(ymlPath);
+ File file = FileUtil.file(ymlPath);
/**fileInputStream = new FileInputStream(file);
Map<String,Object> map = y.loadAs(fileInputStream, Map.class);
if(map==null) {
@@ -93,7 +96,7 @@ public class YamlUtil {
map.remove("rule_files");
map.put("scrape_configs", param);**/
//修改 rule.yml配置文件
- File ruleYmlfile = new File(ruleYmlPath);
+ File ruleYmlfile = FileUtil.file(ruleYmlPath);
if(ruleYmlfile.exists()){
// 文件存在则删除文件信息
ruleYmlfile.delete();
@@ -159,7 +162,7 @@ public class YamlUtil {
OutputStreamWriter osw2 = null;
try {
//修改 rule.yml配置文件
- File ruleYmlfile = new File(ruleYmlPath);
+ File ruleYmlfile = FileUtil.file(ruleYmlPath);
if(!ruleYmlfile.exists()){
// 文件不存在 创建文件
ruleYmlfile.createNewFile();
@@ -176,7 +179,7 @@ public class YamlUtil {
//去除告警规则相关内容
param.remove("groups");
// 修改prometheus.yml配置文件
- File ymlfile = new File(ymlPath);
+ File ymlfile = FileUtil.file(ymlPath);
/**fileInputStream = new FileInputStream(ymlfile);
Map<String,Object> map = y.loadAs(fileInputStream, Map.class);
if(map==null) {
@@ -267,7 +270,7 @@ public class YamlUtil {
OutputStream out = null;
try {
// 修改 rule.yml配置文件
- File ruleYmlfile = new File(ruleYmlPath);
+ File ruleYmlfile = FileUtil.file(ruleYmlPath);
if (!ruleYmlfile.exists()) {
// 文件不存在 创建文件
ruleYmlfile.createNewFile();
@@ -320,7 +323,7 @@ public class YamlUtil {
boolean flag=false;
RandomAccessFile raf = null;
try {
- raf = new RandomAccessFile(new File(filePath), "rw");
+ raf = new RandomAccessFile(FileUtil.file(filePath), "rw");
String readLine = null;
long lastPoint = 0; //记住上一次的偏移量
while((readLine=raf.readLine())!=null) {
@@ -333,9 +336,12 @@ public class YamlUtil {
lastPoint = ponit;
}
raf.close();
- RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl daemon-reload"});
+ /*RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl daemon-reload"});
RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl stop prometheus"});
- RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl start prometheus"});
+ RuntimeUtil.run(null, null, new String[]{"/bin/sh", "-c","systemctl start prometheus"});*/
+ RuntimeUtil.exec("/bin/sh -c systemctl daemon-reload");
+ RuntimeUtil.exec("/bin/sh -c systemctl stop prometheus");
+ RuntimeUtil.exec("/bin/sh -c systemctl start prometheus");
flag=true;
} catch (FileNotFoundException e) {
logger.error("prometheusStartHandle error : FileNotFoundException "+e.getMessage(),e);
@@ -373,7 +379,7 @@ public class YamlUtil {
OutputStreamWriter osw = null;
try {
// 修改prometheus.yml配置文件
- File ymlfile = new File(ymlPath);
+ File ymlfile = FileUtil.file(ymlPath);
fileInputStream = new FileInputStream(ymlfile);
Map<String,Object> map = y.loadAs(fileInputStream, Map.class);
if(map==null) {