Skip to content

Commit

Permalink
1018 task host support ipv6 address (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
l646505418 authored Jun 27, 2023
1 parent 5ee39e1 commit c99855d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,16 @@ public HttpUriRequest createHttpRequest(HttpProtocol httpProtocol) {
// uri
String uri = CollectUtil.replaceUriSpecialChar(httpProtocol.getUrl());
if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) {

requestBuilder.setUri(httpProtocol.getHost() + ":" + httpProtocol.getPort() + uri);
} else {
String ipAddressType = IpDomainUtil.checkIpAddressType(httpProtocol.getHost());
String baseUri = CollectorConstants.IPV6.equals(ipAddressType) ? String.format("[%s]:%s%s",httpProtocol.getHost(),httpProtocol.getPort(),uri) : String.format("%s:%s%s",httpProtocol.getHost(),httpProtocol.getPort(),uri);
boolean ssl = Boolean.parseBoolean(httpProtocol.getSsl());
if (ssl) {
requestBuilder.setUri(CollectorConstants.HTTPS_HEADER + httpProtocol.getHost() + ":" + httpProtocol.getPort() + uri);
requestBuilder.setUri(CollectorConstants.HTTPS_HEADER + baseUri);
} else {
requestBuilder.setUri(CollectorConstants.HTTP_HEADER + httpProtocol.getHost() + ":" + httpProtocol.getPort() + uri);
requestBuilder.setUri(CollectorConstants.HTTP_HEADER + baseUri);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ public interface CollectorConstants {
* POSTGRESQL状态码 不可达
*/
String POSTGRESQL_UN_REACHABLE_CODE = "08001";

String IPV6 = "ipv6";
String IPV4 = "ipv4";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.http.conn.util.InetAddressUtils;
import org.dromara.hertzbeat.common.constants.CollectorConstants;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
Expand Down Expand Up @@ -106,4 +108,16 @@ public static String getLocalhostIp() {
return null;
}

/**
*
* @param ipDomain
* @return IP address type
*/
public static String checkIpAddressType(String ipDomain){
if (InetAddressUtils.isIPv6Address(ipDomain)) {
return CollectorConstants.IPV6;
}
return CollectorConstants.IPV4;
}

}

0 comments on commit c99855d

Please sign in to comment.