This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new f76581b860 fix[protocol-sd]: add register center params check (#4048)
f76581b860 is described below
commit f76581b860e5ecfb46069377264175f0460f0717
Author: shown <[email protected]>
AuthorDate: Wed Mar 4 23:19:00 2026 +0800
fix[protocol-sd]: add register center params check (#4048)
Signed-off-by: yuluo-yx <[email protected]>
Co-authored-by: Duansg <[email protected]>
---
.../collector/collect/nginx/NginxCollectImpl.java | 4 +-
.../collector/collect/registry/RegistryImpl.java | 2 +
.../discovery/impl/NacosDiscoveryClient.java | 9 +-
.../collector/collect/sd/NacosSdCollectImpl.java | 12 +-
.../discovery/impl/NacosDiscoveryClientTest.java | 292 +++++++++++++++++++++
.../hertzbeat/common/entity/job/SshTunnel.java | 7 +
.../common/entity/job/protocol/DnsProtocol.java | 1 +
.../common/entity/job/protocol/DnsSdProtocol.java | 9 +-
.../entity/job/protocol/EurekaSdProtocol.java | 7 +
.../common/entity/job/protocol/FtpProtocol.java | 7 +
.../common/entity/job/protocol/HttpProtocol.java | 7 +
.../common/entity/job/protocol/HttpSdProtocol.java | 9 +-
.../common/entity/job/protocol/IcmpProtocol.java | 7 +
.../common/entity/job/protocol/ImapProtocol.java | 6 +
.../common/entity/job/protocol/IpmiProtocol.java | 7 +
.../common/entity/job/protocol/JdbcProtocol.java | 7 +
.../common/entity/job/protocol/JmxProtocol.java | 6 +
.../common/entity/job/protocol/KafkaProtocol.java | 7 +
.../entity/job/protocol/MemcachedProtocol.java | 6 +
.../common/entity/job/protocol/ModbusProtocol.java | 7 +
.../entity/job/protocol/MongodbProtocol.java | 7 +
.../common/entity/job/protocol/MqttProtocol.java | 7 +
.../entity/job/protocol/NebulaGraphProtocol.java | 7 +
.../common/entity/job/protocol/NginxProtocol.java | 3 +-
.../common/entity/job/protocol/NgqlProtocol.java | 7 +
.../common/entity/job/protocol/NtpProtocol.java | 7 +
.../common/entity/job/protocol/PlcProtocol.java | 7 +
.../common/entity/job/protocol/Pop3Protocol.java | 1 +
.../entity/job/protocol/PrometheusProtocol.java | 7 +
.../common/entity/job/protocol/Protocol.java | 7 +
.../common/entity/job/protocol/PushProtocol.java | 7 +
.../entity/job/protocol/RedfishProtocol.java | 7 +
.../common/entity/job/protocol/RedisProtocol.java | 7 +
.../entity/job/protocol/RegistryProtocol.java | 8 +-
.../entity/job/protocol/RocketmqProtocol.java | 7 +
.../common/entity/job/protocol/S7Protocol.java | 7 +
.../common/entity/job/protocol/ScriptProtocol.java | 7 +
.../common/entity/job/protocol/SmtpProtocol.java | 7 +
.../common/entity/job/protocol/SnmpProtocol.java | 7 +
.../common/entity/job/protocol/SshProtocol.java | 9 +-
.../common/entity/job/protocol/TelnetProtocol.java | 7 +
.../common/entity/job/protocol/UdpProtocol.java | 11 +-
.../entity/job/protocol/WebsocketProtocol.java | 9 +-
.../entity/job/protocol/ZookeeperSdProtocol.java | 9 +-
.../apache/hertzbeat/common/util/IpDomainUtil.java | 18 ++
.../entity/job/protocol/RegistryProtocolTest.java | 53 ++++
.../hertzbeat/common/entity/job/SshTunnel.java | 7 +
.../apache/hertzbeat/common/util/IpDomainUtil.java | 16 ++
48 files changed, 664 insertions(+), 18 deletions(-)
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
index 259e9451be..9fa578385e 100644
---
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/nginx/NginxCollectImpl.java
@@ -78,7 +78,7 @@ public class NginxCollectImpl extends AbstractCollect {
@Override
public void preCheck(Metrics metrics) throws IllegalArgumentException {
final NginxProtocol nginxProtocol;
- if (metrics == null || (nginxProtocol = metrics.getNginx()) == null ||
nginxProtocol.isInValid()) {
+ if (metrics == null || (nginxProtocol = metrics.getNginx()) == null ||
nginxProtocol.isInvalid()) {
throw new IllegalArgumentException("Nginx collect must has nginx
params");
}
}
@@ -141,7 +141,7 @@ public class NginxCollectImpl extends AbstractCollect {
RequestBuilder requestBuilder = RequestBuilder.get();
String portWithUri = nginxProtocol.getPort() +
CollectUtil.replaceUriSpecialChar(nginxProtocol.getUrl());
String host = nginxProtocol.getHost();
-
+
if (IpDomainUtil.isHasSchema(host)) {
requestBuilder.setUri(host + ":" + portWithUri);
} else {
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/RegistryImpl.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/RegistryImpl.java
index 39de5ae4be..44ad1196e5 100644
---
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/RegistryImpl.java
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/RegistryImpl.java
@@ -51,7 +51,9 @@ public class RegistryImpl extends AbstractCollect {
@Override
public void preCheck(Metrics metrics) throws IllegalArgumentException {
+
RegistryProtocol registryProtocol = metrics.getRegistry();
+
if (Objects.isNull(registryProtocol) || registryProtocol.isInvalid()){
throw new IllegalArgumentException("registry collect must have a
valid registry protocol param! ");
}
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClient.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClient.java
index 983fe8e364..906de99803 100644
---
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClient.java
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClient.java
@@ -53,10 +53,17 @@ public class NacosDiscoveryClient implements
DiscoveryClient {
@Override
public void initClient(ConnectConfig connectConfig) {
try {
+
localConnectConfig = connectConfig;
namingService =
NamingFactory.createNamingService(connectConfig.getHost() + ":" +
connectConfig.getPort());
+
+ // Perform a synchronous probe to verify connectivity eagerly,
+ // because NamingFactory.createNamingService() establishes the TCP
+ // connection in a background thread and getServerStatus() returns
+ // "UP" by default before that thread finishes.
+ namingService.getServicesOfServer(0, 1);
} catch (NacosException exception) {
- throw new RuntimeException("Failed to init namingService");
+ throw new RuntimeException("Failed to connect to Nacos server: " +
exception.getErrMsg());
}
}
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/sd/NacosSdCollectImpl.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/sd/NacosSdCollectImpl.java
index dd6dad2a15..c553a09265 100644
---
a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/sd/NacosSdCollectImpl.java
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/sd/NacosSdCollectImpl.java
@@ -39,12 +39,12 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
public class NacosSdCollectImpl extends AbstractCollect {
-
+
/**
* Client management to interact with discovery services
*/
private final DiscoveryClientManagement discoveryClientManagement = new
DiscoveryClientManagement();
-
+
@Override
public void preCheck(Metrics metrics) throws IllegalArgumentException {
// Validate the required configuration is present
@@ -55,7 +55,7 @@ public class NacosSdCollectImpl extends AbstractCollect {
throw new IllegalArgumentException("Nacos service discovery
monitoring, the config is invalid");
}
}
-
+
@Override
public void collect(CollectRep.MetricsData.Builder builder, Metrics
metrics) {
// Create Registry protocol from NacosSd protocol
@@ -74,13 +74,13 @@ public class NacosSdCollectImpl extends AbstractCollect {
builder.setMsg("Failed to get Nacos discovery client");
return;
}
-
+
// Get all services registered in Nacos
List<ServiceInstance> services = discoveryClient.getServices();
if (CollectionUtils.isEmpty(services)) {
return;
}
-
+
// Populate the response data with service information
services.forEach(service -> {
CollectRep.ValueRow.Builder valueRowBuilder =
CollectRep.ValueRow.newBuilder();
@@ -106,7 +106,7 @@ public class NacosSdCollectImpl extends AbstractCollect {
}
}
}
-
+
@Override
public String supportProtocol() {
return DispatchConstants.PROTOCOL_NACOS_SD;
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClientTest.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClientTest.java
new file mode 100644
index 0000000000..71978cdac8
--- /dev/null
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/registry/discovery/impl/NacosDiscoveryClientTest.java
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hertzbeat.collector.collect.registry.discovery.impl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingFactory;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.api.naming.pojo.Instance;
+import com.alibaba.nacos.api.naming.pojo.ListView;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import
org.apache.hertzbeat.collector.collect.registry.constant.DiscoveryClientHealthStatus;
+import
org.apache.hertzbeat.collector.collect.registry.discovery.entity.ConnectConfig;
+import
org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServerInfo;
+import
org.apache.hertzbeat.collector.collect.registry.discovery.entity.ServiceInstance;
+import org.apache.hertzbeat.common.entity.job.protocol.RegistryProtocol;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+/**
+ * Test case for {@link NacosDiscoveryClient}
+ */
+@ExtendWith(MockitoExtension.class)
+class NacosDiscoveryClientTest {
+
+ private NacosDiscoveryClient nacosDiscoveryClient;
+
+ @Mock
+ private NamingService namingService;
+
+ private static final String HOST = "127.0.0.1";
+ private static final int PORT = 8848;
+
+ @BeforeEach
+ void setUp() {
+ nacosDiscoveryClient = new NacosDiscoveryClient();
+ }
+
+ @Test
+ void testBuildConnectConfig() {
+ RegistryProtocol protocol = RegistryProtocol.builder()
+ .host(HOST)
+ .port(String.valueOf(PORT))
+ .build();
+
+ ConnectConfig config =
nacosDiscoveryClient.buildConnectConfig(protocol);
+
+ assertNotNull(config);
+ assertEquals(HOST, config.getHost());
+ assertEquals(PORT, config.getPort());
+ }
+
+ @Test
+ void testInitClientSuccess() throws NacosException {
+ ConnectConfig config =
ConnectConfig.builder().host(HOST).port(PORT).build();
+
+ try (MockedStatic<NamingFactory> mockedFactory =
Mockito.mockStatic(NamingFactory.class)) {
+ mockedFactory.when(() -> NamingFactory.createNamingService(HOST +
":" + PORT))
+ .thenReturn(namingService);
+ ListView<String> emptyView = new ListView<>();
+ emptyView.setData(Collections.emptyList());
+ when(namingService.getServicesOfServer(0,
1)).thenReturn(emptyView);
+
+ nacosDiscoveryClient.initClient(config);
+
+ mockedFactory.verify(() -> NamingFactory.createNamingService(HOST
+ ":" + PORT));
+ verify(namingService).getServicesOfServer(0, 1);
+ }
+ }
+
+ @Test
+ void testInitClientFailedOnCreate() throws NacosException {
+ ConnectConfig config =
ConnectConfig.builder().host(HOST).port(PORT).build();
+
+ try (MockedStatic<NamingFactory> mockedFactory =
Mockito.mockStatic(NamingFactory.class)) {
+ mockedFactory.when(() ->
NamingFactory.createNamingService(anyString()))
+ .thenThrow(new NacosException(500, "connection refused"));
+
+ assertThrows(RuntimeException.class, () ->
nacosDiscoveryClient.initClient(config));
+ }
+ }
+
+ @Test
+ void testInitClientFailedOnProbe() throws NacosException {
+ ConnectConfig config =
ConnectConfig.builder().host(HOST).port(PORT).build();
+
+ try (MockedStatic<NamingFactory> mockedFactory =
Mockito.mockStatic(NamingFactory.class)) {
+ mockedFactory.when(() ->
NamingFactory.createNamingService(anyString()))
+ .thenReturn(namingService);
+ when(namingService.getServicesOfServer(0, 1))
+ .thenThrow(new NacosException(500, "host unreachable"));
+
+ RuntimeException ex = assertThrows(RuntimeException.class, () ->
nacosDiscoveryClient.initClient(config));
+ assertTrue(ex.getMessage().contains("Failed to connect"));
+ }
+ }
+
+ @Test
+ void testGetServerInfoWithNullNamingService() {
+ assertThrows(NullPointerException.class, () ->
nacosDiscoveryClient.getServerInfo());
+ }
+
+ @Test
+ void testGetServerInfoWhenHealthy() {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.UP);
+
+ ServerInfo serverInfo = nacosDiscoveryClient.getServerInfo();
+
+ assertNotNull(serverInfo);
+ assertEquals(HOST, serverInfo.getAddress());
+ assertEquals(String.valueOf(PORT), serverInfo.getPort());
+ }
+
+ @Test
+ void testGetServerInfoWhenNotHealthy() {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.DOWN);
+
+ assertThrows(RuntimeException.class, () ->
nacosDiscoveryClient.getServerInfo());
+ }
+
+ @Test
+ void testGetServicesWithNullNamingService() {
+ List<ServiceInstance> result = nacosDiscoveryClient.getServices();
+
+ assertNotNull(result);
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ void testGetServicesWhenNotHealthy() {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.DOWN);
+
+ List<ServiceInstance> result = nacosDiscoveryClient.getServices();
+
+ assertNotNull(result);
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ void testGetServicesSuccess() throws NacosException {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.UP);
+
+ ListView<String> serviceNames = new ListView<>();
+ serviceNames.setData(Collections.singletonList("test-service"));
+ when(namingService.getServicesOfServer(0,
9999)).thenReturn(serviceNames);
+
+ Instance instance = new Instance();
+ instance.setInstanceId("inst-1");
+ instance.setServiceName("test-service");
+ instance.setIp("192.168.1.1");
+ instance.setPort(9090);
+ instance.setWeight(1.0);
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put("version", "1.0");
+ instance.setMetadata(metadata);
+ instance.setHealthy(true);
+
+
when(namingService.getAllInstances("test-service")).thenReturn(Collections.singletonList(instance));
+
+ List<ServiceInstance> result = nacosDiscoveryClient.getServices();
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ ServiceInstance serviceInstance = result.get(0);
+ assertEquals("inst-1", serviceInstance.getServiceId());
+ assertEquals("test-service", serviceInstance.getServiceName());
+ assertEquals("192.168.1.1", serviceInstance.getAddress());
+ assertEquals(9090, serviceInstance.getPort());
+ assertEquals(DiscoveryClientHealthStatus.UP,
serviceInstance.getHealthStatus());
+ }
+
+ @Test
+ void testGetServicesWithUnhealthyInstance() throws NacosException {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.UP);
+
+ ListView<String> serviceNames = new ListView<>();
+ serviceNames.setData(Collections.singletonList("test-service"));
+ when(namingService.getServicesOfServer(0,
9999)).thenReturn(serviceNames);
+
+ Instance instance = new Instance();
+ instance.setInstanceId("inst-down");
+ instance.setServiceName("test-service");
+ instance.setIp("10.0.0.1");
+ instance.setPort(8080);
+ instance.setWeight(1.0);
+ instance.setHealthy(false);
+
+
when(namingService.getAllInstances("test-service")).thenReturn(Collections.singletonList(instance));
+
+ List<ServiceInstance> result = nacosDiscoveryClient.getServices();
+
+ assertEquals(1, result.size());
+ assertEquals(DiscoveryClientHealthStatus.DOWN,
result.get(0).getHealthStatus());
+ }
+
+ @Test
+ void testGetServicesThrowsNacosException() throws NacosException {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.UP);
+ when(namingService.getServicesOfServer(anyInt(), anyInt()))
+ .thenThrow(new NacosException(500, "server error"));
+
+ assertThrows(RuntimeException.class, () ->
nacosDiscoveryClient.getServices());
+ }
+
+ @Test
+ void testHealthCheckReturnsTrue() {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.UP);
+
+ assertTrue(nacosDiscoveryClient.healthCheck());
+ }
+
+ @Test
+ void testHealthCheckReturnsFalse() {
+ injectNamingServiceAndConfig();
+
when(namingService.getServerStatus()).thenReturn(DiscoveryClientHealthStatus.DOWN);
+
+ assertFalse(nacosDiscoveryClient.healthCheck());
+ }
+
+ @Test
+ void testCloseWithNullNamingService() {
+ nacosDiscoveryClient.close();
+ }
+
+ @Test
+ void testCloseSuccess() throws NacosException {
+ injectNamingServiceAndConfig();
+
+ nacosDiscoveryClient.close();
+
+ verify(namingService).shutDown();
+ }
+
+ @Test
+ void testCloseThrowsNacosException() throws NacosException {
+ injectNamingServiceAndConfig();
+ doThrow(new NacosException(500, "shutdown
error")).when(namingService).shutDown();
+
+ nacosDiscoveryClient.close();
+
+ verify(namingService).shutDown();
+ }
+
+ private void injectNamingServiceAndConfig() {
+ ReflectionTestUtils.setField(nacosDiscoveryClient, "namingService",
namingService);
+ ConnectConfig config =
ConnectConfig.builder().host(HOST).port(PORT).build();
+ ReflectionTestUtils.setField(nacosDiscoveryClient,
"localConnectConfig", config);
+ }
+}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
index 154669560f..8caa8dcd1c 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
@@ -77,4 +77,11 @@ public class SshTunnel implements CommonRequestProtocol,
Protocol {
* share connection session
*/
private String shareConnection = "true";
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsProtocol.java
index 9982d25da3..43c3102c36 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsProtocol.java
@@ -39,6 +39,7 @@ public class DnsProtocol implements CommonRequestProtocol,
Protocol {
private String queryClass;
private String recordType;
+ @Override
public boolean isInvalid() {
return StringUtils.isAnyBlank(dnsServerIP, port, address, timeout,
tcp, queryClass, recordType);
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsSdProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsSdProtocol.java
index 9597ac6f91..b2d00590ed 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsSdProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/DnsSdProtocol.java
@@ -30,7 +30,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class DnsSdProtocol implements Protocol {
-
+
private String host;
private String port;
@@ -38,4 +38,11 @@ public class DnsSdProtocol implements Protocol {
private String recordType;
private String recordName;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocol.java
index c522d919d8..0c8cf93f76 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/EurekaSdProtocol.java
@@ -32,4 +32,11 @@ import lombok.NoArgsConstructor;
public class EurekaSdProtocol implements Protocol{
private String url;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocol.java
index f095116c75..a3d2b525ab 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/FtpProtocol.java
@@ -65,4 +65,11 @@ public class FtpProtocol implements CommonRequestProtocol,
Protocol {
*
*/
private String ssl = "false";
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpProtocol.java
index 1b48e4871a..61b36f0e7a 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpProtocol.java
@@ -133,4 +133,11 @@ public class HttpProtocol implements
CommonRequestProtocol, Protocol {
*/
private String digestAuthPassword;
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpSdProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpSdProtocol.java
index 67d50fa6e5..a90751df81 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpSdProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/HttpSdProtocol.java
@@ -30,6 +30,13 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class HttpSdProtocol implements Protocol {
-
+
private String url;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IcmpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IcmpProtocol.java
index 3376196744..4133eb7480 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IcmpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IcmpProtocol.java
@@ -44,4 +44,11 @@ public class IcmpProtocol implements CommonRequestProtocol,
Protocol {
@Override
public void setPort(String port) {
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocol.java
index fe8bec07bb..35e4a32854 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ImapProtocol.java
@@ -64,4 +64,10 @@ public class ImapProtocol implements CommonRequestProtocol,
Protocol {
*/
private String folderName;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IpmiProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IpmiProtocol.java
index b2dca81df5..103626f541 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IpmiProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/IpmiProtocol.java
@@ -69,4 +69,11 @@ public class IpmiProtocol implements CommonRequestProtocol,
Protocol {
static class Field {
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JdbcProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JdbcProtocol.java
index 7f378a5f70..0454ffcbfc 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JdbcProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JdbcProtocol.java
@@ -79,4 +79,11 @@ public class JdbcProtocol implements CommonRequestProtocol,
Protocol {
* ssh tunnel
*/
private SshTunnel sshTunnel;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JmxProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JmxProtocol.java
index b08ea6e4e4..192d65e6c6 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JmxProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/JmxProtocol.java
@@ -65,4 +65,10 @@ public class JmxProtocol implements CommonRequestProtocol,
Protocol {
*/
private String objectName;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/KafkaProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/KafkaProtocol.java
index c2bc9a8060..f1a3065577 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/KafkaProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/KafkaProtocol.java
@@ -55,4 +55,11 @@ public class KafkaProtocol implements CommonRequestProtocol,
Protocol {
* Monitor internal topic
*/
private String monitorInternalTopic = "false";
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MemcachedProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MemcachedProtocol.java
index cba7e57851..6384600b94 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MemcachedProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MemcachedProtocol.java
@@ -41,5 +41,11 @@ public class MemcachedProtocol implements
CommonRequestProtocol, Protocol {
*/
private String port;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ModbusProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ModbusProtocol.java
index c019873b3c..b08840dce3 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ModbusProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ModbusProtocol.java
@@ -52,4 +52,11 @@ public class ModbusProtocol implements Protocol {
private String timeout;
private List<String> registerAddresses;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MongodbProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MongodbProtocol.java
index 4ab005b1c1..0f58343bfb 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MongodbProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MongodbProtocol.java
@@ -77,4 +77,11 @@ public class MongodbProtocol implements
CommonRequestProtocol, Protocol {
*/
private String timeout;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MqttProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MqttProtocol.java
index d0d1fa7dd9..e80f660444 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MqttProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/MqttProtocol.java
@@ -109,4 +109,11 @@ public class MqttProtocol implements
CommonRequestProtocol, Protocol {
return StringUtils.isNotBlank(this.username) &&
StringUtils.isNotBlank(this.password);
}
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NebulaGraphProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NebulaGraphProtocol.java
index d67ed5c8ad..48d999984a 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NebulaGraphProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NebulaGraphProtocol.java
@@ -57,4 +57,11 @@ public class NebulaGraphProtocol implements
CommonRequestProtocol, Protocol {
*/
private String timeout;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NginxProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NginxProtocol.java
index 95e655c87b..62ca0e38c5 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NginxProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NginxProtocol.java
@@ -60,7 +60,8 @@ public class NginxProtocol implements CommonRequestProtocol,
Protocol {
* Validates the relevant parameters
* @return is invalid true or false
*/
- public boolean isInValid() {
+ @Override
+ public boolean isInvalid() {
return StringUtils.isAnyBlank(host, port, timeout);
}
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocol.java
index 6af38d125d..a5b775aac0 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NgqlProtocol.java
@@ -71,4 +71,11 @@ public class NgqlProtocol implements CommonRequestProtocol,
Protocol {
* how to parse data
*/
private String parseType;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocol.java
index d722802051..ee9178b02b 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/NtpProtocol.java
@@ -44,4 +44,11 @@ public class NtpProtocol implements CommonRequestProtocol,
Protocol {
* TIME OUT PERIOD
*/
private String timeout;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PlcProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PlcProtocol.java
index 5b24077413..bbcc01b1c9 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PlcProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PlcProtocol.java
@@ -52,4 +52,11 @@ public class PlcProtocol implements Protocol {
private List<String> registerAddresses;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Pop3Protocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Pop3Protocol.java
index baa762db62..4adca6b648 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Pop3Protocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Pop3Protocol.java
@@ -61,6 +61,7 @@ public class Pop3Protocol implements CommonRequestProtocol,
Protocol {
*/
private String authorize;
+ @Override
public boolean isInvalid() {
return StringUtils.isAllBlank(host, port, timeout, ssl, email,
authorize);
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PrometheusProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PrometheusProtocol.java
index 2744efbfac..3411a2b56f 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PrometheusProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PrometheusProtocol.java
@@ -104,4 +104,11 @@ public class PrometheusProtocol implements
CommonRequestProtocol, Protocol {
*/
private String digestAuthPassword;
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Protocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Protocol.java
index fa51b9cc3a..7d41fe9134 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Protocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/Protocol.java
@@ -21,4 +21,11 @@ package org.apache.hertzbeat.common.entity.job.protocol;
* Base class for all protocols
*/
public interface Protocol {
+
+ /**
+ * Check Protocol params vaild.
+ * @return True or False.
+ */
+ boolean isInvalid();
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PushProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PushProtocol.java
index e7998179a4..5cd8a46dc4 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PushProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/PushProtocol.java
@@ -36,4 +36,11 @@ public class PushProtocol implements CommonRequestProtocol,
Protocol {
private String port;
private String uri = "/api/push";
private List<Field> fields;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
index 3155d2fa7a..1d1764936a 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
@@ -62,4 +62,11 @@ public class RedfishProtocol implements
CommonRequestProtocol, Protocol {
private String schema;
private List<String> jsonPath;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedisProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedisProtocol.java
index 393e43f91a..b0c240fcec 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedisProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedisProtocol.java
@@ -67,4 +67,11 @@ public class RedisProtocol implements CommonRequestProtocol,
Protocol {
*/
private SshTunnel sshTunnel;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocol.java
index ce459071ce..a33f5cfd75 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocol.java
@@ -25,6 +25,9 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
+import static org.apache.hertzbeat.common.util.IpDomainUtil.validPort;
+import static org.apache.hertzbeat.common.util.IpDomainUtil.validateIpDomain;
+
/**
* Registry protocol
*/
@@ -37,7 +40,10 @@ public class RegistryProtocol implements
CommonRequestProtocol, Protocol {
private String port;
private String discoveryClientTypeName;
+ @Override
public boolean isInvalid() {
- return StringUtils.isAnyBlank(host, String.valueOf(port),
discoveryClientTypeName);
+
+ return validateIpDomain(host) && validPort(port)
+ && StringUtils.isAnyBlank(host, String.valueOf(port),
discoveryClientTypeName);
}
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RocketmqProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RocketmqProtocol.java
index e7bfe12b51..3688e23a54 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RocketmqProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RocketmqProtocol.java
@@ -65,4 +65,11 @@ public class RocketmqProtocol implements
CommonRequestProtocol, Protocol {
public void setPort(String port) {
this.namesrvPort = port;
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/S7Protocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/S7Protocol.java
index cebe9e8a11..bfcd18d0ab 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/S7Protocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/S7Protocol.java
@@ -56,4 +56,11 @@ public class S7Protocol implements Protocol {
private String timeout;
private List<String> registerAddresses;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocol.java
index eeae02df8d..9876a751de 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ScriptProtocol.java
@@ -69,4 +69,11 @@ public class ScriptProtocol implements
CommonRequestProtocol, Protocol {
public void setPort(String port) {
this.scriptPath = port;
}
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocol.java
index aa42bfa0bb..fa8d8a120b 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SmtpProtocol.java
@@ -54,4 +54,11 @@ public class SmtpProtocol implements CommonRequestProtocol,
Protocol {
* Sent command
*/
private String cmd;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocol.java
index 109c1acb4f..229cde701e 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SnmpProtocol.java
@@ -91,4 +91,11 @@ public class SnmpProtocol implements CommonRequestProtocol,
Protocol {
* v3 requires
*/
private String privPasswordEncryption;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SshProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SshProtocol.java
index b9c708a486..88e5f8b78d 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SshProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/SshProtocol.java
@@ -65,7 +65,7 @@ public class SshProtocol implements CommonRequestProtocol,
Protocol {
* private key passphrase (optional)
*/
private String privateKeyPassphrase;
-
+
/**
* reuse connection session
*/
@@ -110,4 +110,11 @@ public class SshProtocol implements CommonRequestProtocol,
Protocol {
* Proxy private key (optional)
*/
private String proxyPrivateKey;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/TelnetProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/TelnetProtocol.java
index c10b12e91c..a485c87b02 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/TelnetProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/TelnetProtocol.java
@@ -51,4 +51,11 @@ public class TelnetProtocol implements
CommonRequestProtocol, Protocol {
*/
private String cmd;
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
+
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/UdpProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/UdpProtocol.java
index 221eccc4f6..f062b39fb1 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/UdpProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/UdpProtocol.java
@@ -34,7 +34,7 @@ public class UdpProtocol implements CommonRequestProtocol,
Protocol {
* IP ADDRESS OR DOMAIN NAME OF THE PEER HOST
*/
private String host;
-
+
/**
* Port number
*/
@@ -44,9 +44,16 @@ public class UdpProtocol implements CommonRequestProtocol,
Protocol {
* TIME OUT PERIOD
*/
private String timeout;
-
+
/**
* Custom protocol packet hexString Hexadecimal character string
*/
private String content;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/WebsocketProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/WebsocketProtocol.java
index 84687cd202..c4f5045fc1 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/WebsocketProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/WebsocketProtocol.java
@@ -39,9 +39,16 @@ public class WebsocketProtocol implements
CommonRequestProtocol, Protocol {
* Port number
*/
private String port;
-
+
/**
* The path to the websocket endpoint
*/
private String path;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocol.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocol.java
index 830398d517..7b53f354b5 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocol.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/ZookeeperSdProtocol.java
@@ -30,8 +30,15 @@ import lombok.AllArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class ZookeeperSdProtocol implements Protocol{
-
+
private String url;
private String pathPrefix;
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo: add
+ return true;
+ }
}
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
index 3c72baa41a..83eabdf2e4 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
@@ -149,4 +149,22 @@ public final class IpDomainUtil {
}
}
+ /**
+ * check port is valid.
+ * @return true if valid
+ */
+ public static boolean validPort(String portStr) {
+
+ if (portStr == null || portStr.trim().isEmpty()) {
+ return false;
+ }
+
+ try {
+ int port = Integer.parseInt(portStr);
+ return port >= 0 && port <= 65535;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
}
diff --git
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocolTest.java
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocolTest.java
new file mode 100644
index 0000000000..f11e2ba911
--- /dev/null
+++
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/entity/job/protocol/RegistryProtocolTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.hertzbeat.common.entity.job.protocol;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class RegistryProtocolTest {
+
+ @Test
+ void isInvalid() {
+
+ RegistryProtocol protocol1 = new RegistryProtocol();
+ protocol1.setPort("8080");
+ protocol1.setHost("127.0.0.1");
+ assertTrue(protocol1.isInvalid());
+
+ RegistryProtocol protocol2 = new RegistryProtocol();
+ protocol2.setPort("8080");
+ protocol2.setHost("www.baidu.com");
+ assertTrue(protocol2.isInvalid());
+
+ RegistryProtocol protocol3 = new RegistryProtocol();
+ protocol3.setPort("8080");
+ protocol3.setHost("www.baidu.com.");
+ assertFalse(protocol3.isInvalid());
+
+ RegistryProtocol protocol4 = new RegistryProtocol();
+ protocol3.setPort("80800");
+ protocol3.setHost("10.45.56.344");
+ assertFalse(protocol4.isInvalid());
+ }
+}
diff --git
a/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
b/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
index 154669560f..7eb9bb2c79 100644
---
a/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
+++
b/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/entity/job/SshTunnel.java
@@ -77,4 +77,11 @@ public class SshTunnel implements CommonRequestProtocol,
Protocol {
* share connection session
*/
private String shareConnection = "true";
+
+ @Override
+ public boolean isInvalid() {
+
+ // todo add
+ return false;
+ }
}
diff --git
a/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
b/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
index e882cbef59..a2a7ae0962 100644
---
a/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
+++
b/hertzbeat-common-spring/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java
@@ -150,4 +150,20 @@ public final class IpDomainUtil {
}
}
+ /**
+ * check port is valid.
+ * @return true if valid
+ */
+ public static boolean validPort(String portStr) {
+ if (portStr == null || portStr.trim().isEmpty()) {
+ return false;
+ }
+ try {
+ int port = Integer.parseInt(portStr);
+ return port >= 0 && port <= 65535;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]