Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixbug]: Fix Redfish protocol parse bug #2597

Merged
merged 4 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ConnectSession connect() throws Exception {
? 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ private void parseRedfishResource(CollectRep.MetricsData.Builder builder, String
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ void setUp() {
@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);
Expand All @@ -77,12 +77,12 @@ void collect() {
@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 = """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,4 +60,6 @@ public class RedfishProtocol {
* Redfish Resource Name and Corresponding Collection URI
*/
private String schema;

private List<String> jsonPath;
}
38 changes: 19 additions & 19 deletions manager/src/main/resources/define/app-redfish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Loading