告警、脚本策略执行测试优化
This commit is contained in:
@@ -31,4 +31,25 @@ public class AgentDataUtil {
|
||||
return alarmEOList.stream()
|
||||
.anyMatch(AlarmEO::isCollect);
|
||||
}
|
||||
|
||||
public static void chmod(String filePath, String mode) throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("chmod", mode, filePath);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
|
||||
Process process = processBuilder.start();
|
||||
int exitCode = process.waitFor();
|
||||
|
||||
if (exitCode != 0) {
|
||||
throw new IOException("chmod命令执行失败,退出码: " + exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
chmod("/opt/app/init.sh", "755"); // 或者 "+x"
|
||||
System.out.println("权限设置成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,4 +217,12 @@ public class AgentUtil {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public static LocalDateTime toLocalDateTime(long timestamp, boolean isSeconds) {
|
||||
java.time.Instant instant = isSeconds ?
|
||||
java.time.Instant.ofEpochSecond(timestamp) :
|
||||
java.time.Instant.ofEpochMilli(timestamp);
|
||||
|
||||
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user