Skip to content

Commit

Permalink
[collector]bugfix linux ssh collect npe (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Mar 16, 2023
1 parent 97bc3ac commit 28b0426
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void parseResponseDataByNetcat(String result, List<String> aliasFields,
String[] lines = result.split("\n");
if (lines.length + 1 < aliasFields.size()) {
log.error("ssh response data not enough: {}", result);
return;
}
boolean contains = lines[0].contains("=");
Map<String, String> mapValue = Arrays.stream(lines)
Expand Down Expand Up @@ -169,6 +170,7 @@ private void parseResponseDataByOne(String result, List<String> aliasFields, Col
String[] lines = result.split("\n");
if (lines.length + 1 < aliasFields.size()) {
log.error("ssh response data not enough: {}", result);
return;
}
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
int aliasIndex = 0;
Expand All @@ -177,7 +179,11 @@ private void parseResponseDataByOne(String result, List<String> aliasFields, Col
if (CollectorConstants.RESPONSE_TIME.equalsIgnoreCase(aliasFields.get(aliasIndex))) {
valueRowBuilder.addColumns(responseTime.toString());
} else {
valueRowBuilder.addColumns(lines[lineIndex].trim());
if (lineIndex < lines.length) {
valueRowBuilder.addColumns(lines[lineIndex].trim());
} else {
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
}
lineIndex++;
}
aliasIndex++;
Expand All @@ -190,6 +196,7 @@ private void parseResponseDataByMulti(String result, List<String> aliasFields,
String[] lines = result.split("\n");
if (lines.length <= 1) {
log.error("ssh response data only has header: {}", result);
return;
}
String[] fields = lines[0].split(" ");
Map<String, Integer> fieldMapping = new HashMap<>(fields.length);
Expand Down Expand Up @@ -249,11 +256,11 @@ private ClientSession getConnectSession(SshProtocol sshProtocol, int timeout) th
clientSession.addPublicKeyIdentity(keyPair);
}
} else {
throw new IllegalArgumentException("需填写账户登陆密码或公钥");
throw new IllegalArgumentException("please input password or secret.");
}
// 进行认证
if (!clientSession.auth().verify(timeout, TimeUnit.MILLISECONDS).isSuccess()) {
throw new IllegalArgumentException("认证失败");
throw new IllegalArgumentException("Auth failed.");
}
CommonCache.getInstance().addCache(identifier, clientSession);
return clientSession;
Expand Down

0 comments on commit 28b0426

Please sign in to comment.