-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from lostsnow/feature/config-disable-log-coll…
…ector Feature/config disable log collector
- Loading branch information
Showing
7 changed files
with
113 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
dongtai-agent/src/main/java/io/dongtai/iast/agent/LogCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.dongtai.iast.agent; | ||
|
||
import io.dongtai.iast.agent.util.FileUtils; | ||
import io.dongtai.log.DongTaiLog; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static io.dongtai.iast.agent.Agent.*; | ||
|
||
public class LogCollector { | ||
private static String FLUENT_FILE; | ||
private static String FLUENT_FILE_CONF; | ||
private static Process fluent; | ||
|
||
public static void extractFluent() { | ||
if (IastProperties.getInstance().getDisableLogCollector()) { | ||
return; | ||
} | ||
try { | ||
if (!isMacOs() && !isWindows()) { | ||
FLUENT_FILE = System.getProperty("java.io.tmpdir.dongtai") + "iast" + File.separator + "fluent"; | ||
FileUtils.getResourceToFile("bin/fluent", FLUENT_FILE); | ||
|
||
FLUENT_FILE_CONF = System.getProperty("java.io.tmpdir.dongtai") + "iast" + File.separator + "fluent.conf"; | ||
FileUtils.getResourceToFile("bin/fluent.conf", FLUENT_FILE_CONF); | ||
FileUtils.confReplace(FLUENT_FILE_CONF); | ||
if (!(new File(FLUENT_FILE)).setExecutable(true)) { | ||
DongTaiLog.info("fluent setExecutable failure. please set execute permission, file: {}", FLUENT_FILE); | ||
} | ||
doFluent(); | ||
} | ||
} catch (IOException e) { | ||
DongTaiLog.error("fluent extract failure", e); | ||
} | ||
} | ||
|
||
public static void doFluent() { | ||
if (IastProperties.getInstance().getDisableLogCollector()) { | ||
return; | ||
} | ||
String[] execution = { | ||
"nohup", | ||
FLUENT_FILE, | ||
"-c", | ||
FLUENT_FILE_CONF | ||
}; | ||
try { | ||
fluent = Runtime.getRuntime().exec(execution); | ||
DongTaiLog.info("fluent process started"); | ||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { | ||
public void run() { | ||
stopFluent(); | ||
} | ||
})); | ||
} catch (IOException e) { | ||
DongTaiLog.error("fluent process start failed", e); | ||
} | ||
} | ||
|
||
public static void stopFluent() { | ||
if (fluent == null) { | ||
return; | ||
} | ||
try { | ||
fluent.destroy(); | ||
DongTaiLog.info("fluent process stopped"); | ||
} catch (Exception ignored) { | ||
} finally { | ||
fluent = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters