Skip to content

Commit 5920555

Browse files
Merge pull request #196 from AikidoSec/log-hostname-errors
Add logging when error occurs trying to fetch hostname
2 parents 3f92ac1 + c6a7257 commit 5920555

File tree

1 file changed

+8
-1
lines changed
  • agent_api/src/main/java/dev/aikido/agent_api/helpers/net

1 file changed

+8
-1
lines changed

agent_api/src/main/java/dev/aikido/agent_api/helpers/net/Hostname.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package dev.aikido.agent_api.helpers.net;
22

3+
import dev.aikido.agent_api.helpers.logging.LogManager;
4+
import dev.aikido.agent_api.helpers.logging.Logger;
5+
36
import java.io.IOException;
47
import java.util.Scanner;
58

9+
610
public final class Hostname {
711
private Hostname() {}
12+
private static final Logger logger = LogManager.getLogger(Hostname.class);
13+
814
public static String getHostname() {
915
// getHostName function seem unreliable, so using "hostname" command which works for both UNIX(-like) systems and Windows
1016
// See https://stackoverflow.com/a/7800008 for more info.
1117
try (Scanner s = new Scanner(Runtime.getRuntime().exec("hostname").getInputStream()).useDelimiter("\\A")) {
1218
if (s.hasNext()) {
1319
return s.next().trim();
1420
}
15-
} catch (IOException ignored) {
21+
} catch (IOException e) {
22+
logger.debug(e);
1623
}
1724
return "unknown";
1825
}

0 commit comments

Comments
 (0)