This is an automated email from the ASF dual-hosted git repository.

gaoxingcun 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 c3ffad76c [fixbug]: Fix Redfish protocol parse bug (#2597)
c3ffad76c is described below

commit c3ffad76ca992abc3ae2264af468d74c8b353101
Author: Gao Jian <[email protected]>
AuthorDate: Sun Aug 25 19:01:40 2024 +0800

    [fixbug]: Fix Redfish protocol parse bug (#2597)
    
    Co-authored-by: shown <[email protected]>
---
 .../collector/collect/redfish/RedfishClient.java   |  2 +-
 .../collect/redfish/RedfishCollectImpl.java        |  6 ++--
 .../collect/redfish/RedfishCollectImplTest.java    | 12 +++----
 .../entity/job/protocol/RedfishProtocol.java       |  3 ++
 manager/src/main/resources/define/app-redfish.yml  | 38 +++++++++++-----------
 5 files changed, 32 insertions(+), 29 deletions(-)

diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishClient.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishClient.java
index afc715ce4..f9de2fda9 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishClient.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishClient.java
@@ -73,7 +73,7 @@ public class RedfishClient {
                     ? String.format("[%s]:%s", this.host, this.port + uri)
                     : String.format("%s:%s", this.host, this.port + uri);
 
-            requestBuilder.setUri(NetworkConstants.HTTP_HEADER + baseUri);
+            requestBuilder.setUri(NetworkConstants.HTTPS_HEADER + baseUri);
         }
 
         requestBuilder.addHeader(HttpHeaders.CONNECTION, 
NetworkConstants.KEEP_ALIVE);
diff --git 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImpl.java
 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImpl.java
index a6e30f5c2..5977871c6 100644
--- 
a/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImpl.java
+++ 
b/collector/src/main/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImpl.java
@@ -176,10 +176,10 @@ public class RedfishCollectImpl extends AbstractCollect {
         if (!StringUtils.hasText(resp)) {
             return;
         }
-        List<String> aliasFields = metrics.getAliasFields();
+        List<String> jsonPaths = metrics.getRedfish().getJsonPath();
         CollectRep.ValueRow.Builder valueRowBuilder = 
CollectRep.ValueRow.newBuilder();
-        for (String alias : aliasFields) {
-            List<Object> res = JsonPathParser.parseContentWithJsonPath(resp, 
alias);
+        for (String path : jsonPaths) {
+            List<Object> res = JsonPathParser.parseContentWithJsonPath(resp, 
path);
             if (res != null && !res.isEmpty()) {
                 Object value = res.get(0);
                 valueRowBuilder.addColumns(value == null ? 
CommonConstants.NULL_VALUE : String.valueOf(value));
diff --git 
a/collector/src/test/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImplTest.java
 
b/collector/src/test/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImplTest.java
index f2ddf1b34..3fa01f78b 100644
--- 
a/collector/src/test/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImplTest.java
+++ 
b/collector/src/test/java/org/apache/hertzbeat/collector/collect/redfish/RedfishCollectImplTest.java
@@ -63,11 +63,11 @@ public class RedfishCollectImplTest {
     @Test
     void collect() {
         CollectRep.MetricsData.Builder builder = 
CollectRep.MetricsData.newBuilder();
-        List<String> aliasField = new ArrayList<>();
-        aliasField.add("$.Id");
+        List<String> jsonPath = new ArrayList<>();
+        jsonPath.add("$.Id");
         Metrics metrics = new Metrics();
         metrics.setRedfish(redfishProtocol);
-        metrics.setAliasFields(aliasField);
+        metrics.getRedfish().setJsonPath(jsonPath);
         metrics.setName("Chassis");
         RedfishClient.create(redfishProtocol);
         redfishCollect.preCheck(metrics);
@@ -77,12 +77,12 @@ public class RedfishCollectImplTest {
     @Test
     void mockCollect() throws Exception {
         CollectRep.MetricsData.Builder builder = 
CollectRep.MetricsData.newBuilder();
-        List<String> aliasField = new ArrayList<>();
-        aliasField.add("$.['@odata.id']");
+        List<String> jsonPath = new ArrayList<>();
+        jsonPath.add("$.['@odata.id']");
         
redfishProtocol.setSchema("/redfish/v1/Chassis/{ChassisId}/PowerSubsystem/PowerSupplies");
         Metrics metrics = new Metrics();
         metrics.setRedfish(redfishProtocol);
-        metrics.setAliasFields(aliasField);
+        metrics.getRedfish().setJsonPath(jsonPath);
         metrics.setName("PowerSupply");
         String chassis = """
                 {
diff --git 
a/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
 
b/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
index b8042e12f..42b3e53fa 100644
--- 
a/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
+++ 
b/common/src/main/java/org/apache/hertzbeat/common/entity/job/protocol/RedfishProtocol.java
@@ -17,6 +17,7 @@
 
 package org.apache.hertzbeat.common.entity.job.protocol;
 
+import java.util.List;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -59,4 +60,6 @@ public class RedfishProtocol {
      * Redfish Resource Name and Corresponding Collection URI
      */
     private String schema;
+
+    private List<String> jsonPath;
 }
diff --git a/manager/src/main/resources/define/app-redfish.yml 
b/manager/src/main/resources/define/app-redfish.yml
index 2be76bb8c..2c38fd886 100644
--- a/manager/src/main/resources/define/app-redfish.yml
+++ b/manager/src/main/resources/define/app-redfish.yml
@@ -164,12 +164,6 @@ metrics:
           en-US: Chasis Health
     # (optional)metrics field alias name, it is used as an alias field to map 
and convert the collected data and metrics field
     # (可选)监控指标别名, 做为中间字段与采集数据字段和指标字段映射转换
-    aliasFields:
-      - $.['@odata.id']
-      - $.Name
-      - $.ChassisType
-      - $.Status.State
-      - $.Status.Health
     # the protocol used for monitoring, eg: sql, ssh, http, telnet, wmi, snmp, 
sdk
     protocol: redfish
     # the config content when protocol is redfish
@@ -184,6 +178,12 @@ metrics:
       password: ^_^password^_^
       # timeout unit:ms
       timeout: ^_^timeout^_^
+      jsonPath:
+        - $.['@odata.id']
+        - $.Name
+        - $.ChassisType
+        - $.Status.State
+        - $.Status.Health
 
   - name: Battery
     priority: 1
@@ -213,12 +213,6 @@ metrics:
         i18n:
           zh-CN: 电池充电状态
           en-US: Battery Charge Status
-    aliasFields:
-      - $.['@odata.id']
-      - $.Name
-      - $.Status.State
-      - $.Status.Health
-      - $.ChargeState
     protocol: redfish
     redfish:
       # redfish host: ipv4 ipv6 domain
@@ -231,6 +225,12 @@ metrics:
       password: ^_^password^_^
       # timeout unit:ms
       timeout: ^_^timeout^_^
+      jsonPath:
+        - $.['@odata.id']
+        - $.Name
+        - $.Status.State
+        - $.Status.Health
+        - $.ChargeState
 
   - name: Fan
     priority: 2
@@ -265,13 +265,6 @@ metrics:
         i18n:
           zh-CN: 风扇转速
           en-US: Fan Speed
-    aliasFields:
-      - $.['@odata.id']
-      - $.Name
-      - $.Status.State
-      - $.Status.Health
-      - $.SpeedPercent.Reading
-      - $.SpeedPercent.SpeedRPM
     protocol: redfish
     redfish:
       # redfish host: ipv4 ipv6 domain
@@ -286,3 +279,10 @@ metrics:
       timeout: ^_^timeout^_^
       # redfish fan collection schema
       schema: /redfish/v1/Chassis/{ChassisId}/ThermalSubsystem/Fans
+      jsonPath:
+        - $.['@odata.id']
+        - $.Name
+        - $.Status.State
+        - $.Status.Health
+        - $.SpeedPercent.Reading
+        - $.SpeedPercent.SpeedRPM


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to