Skip to content

Commit

Permalink
Issue #114: Last modification and tests
Browse files Browse the repository at this point in the history
Issue #114: Developed IPMI extension

Developed IPMI extension.
  • Loading branch information
alexdgilbert committed Apr 15, 2024
1 parent ba71684 commit 6811ed9
Show file tree
Hide file tree
Showing 30 changed files with 1,407 additions and 705 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.sentrysoftware.metricshub.engine.configuration.IConfiguration;

/**
* This abstract class defines a generic protocol configuration that will be extended to configure all the protocols such as {@link SshProtocolConfig} or {@link IpmiProtocolConfig}).
* This abstract class defines a generic protocol configuration that will be extended to configure all the protocols.
*/
public abstract class AbstractProtocolConfig {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ProtocolsConfig {
private IConfiguration snmp;

@JsonSetter(nulls = SKIP)
private IpmiProtocolConfig ipmi;
private IConfiguration ipmi;

@JsonSetter(nulls = SKIP)
private SshProtocolConfig ssh;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.sentrysoftware.metricshub.agent.config.ResourceGroupConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.AbstractProtocolConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.HttpProtocolConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.IpmiProtocolConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.OsCommandProtocolConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.ProtocolsConfig;
import org.sentrysoftware.metricshub.agent.config.protocols.SshProtocolConfig;
Expand Down Expand Up @@ -945,9 +944,9 @@ private static void validateProtocols(@NonNull final String resourceKey, final R
snmpConfig.validateConfiguration(resourceKey);
}

final IpmiProtocolConfig ipmiConfig = protocolsConfig.getIpmi();
final IConfiguration ipmiConfig = protocolsConfig.getIpmi();
if (ipmiConfig != null) {
validateIpmiInfo(resourceKey, ipmiConfig.getUsername(), ipmiConfig.getTimeout());
ipmiConfig.validateConfiguration(resourceKey);
}

final SshProtocolConfig sshConfig = protocolsConfig.getSsh();
Expand Down Expand Up @@ -1188,7 +1187,6 @@ static HostConfiguration buildHostConfiguration(
protocols.getWbem(),
protocols.getWmi(),
protocols.getOsCommand(),
protocols.getIpmi(),
protocols.getWinrm()
)
.filter(Objects::nonNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import lombok.Data;
import org.sentrysoftware.metricshub.engine.common.helpers.ArrayHelper;
import org.sentrysoftware.metricshub.cli.service.CliExtensionManager;
import org.sentrysoftware.metricshub.engine.common.exception.InvalidConfigurationException;
import org.sentrysoftware.metricshub.engine.configuration.IConfiguration;
import org.sentrysoftware.metricshub.engine.configuration.IpmiConfiguration;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.Spec;

/**
* This class is used by MetricsHubCliService to configure Ipmi protocol when using the MetricsHub CLI.
* It create the engine's {@link IpmiConfiguration} object that is used to monitor a specific resource through IPMI.
* It create the engine's {@link IConfiguration} object that is used to monitor a specific resource through IPMI.
*/
@Data
public class IpmiConfigCli implements IProtocolConfigCli {
Expand Down Expand Up @@ -89,28 +91,29 @@ public class IpmiConfigCli implements IProtocolConfigCli {
defaultValue = "" + DEFAULT_TIMEOUT,
description = "Timeout in seconds for HTTP operations (default: ${DEFAULT-VALUE} s)"
)
private long timeout;
private String timeout;

/**
* This method creates an {@link IpmiConfiguration} for a given username and a given password
* This method creates an {@link IConfiguration} for a given username and a given password
*
* @param defaultUsername Username specified at the top level of the CLI (with the --username option)
* @param defaultPassword Password specified at the top level of the CLI (with the --password option)
* @return an {@link IpmiConfiguration} instance corresponding to the options specified by the user in the CLI
* @return an {@link IConfiguration} instance corresponding to the options specified by the user in the CLI
*/
@Override
public IConfiguration toProtocol(final String defaultUsername, final char[] defaultPassword) {
try {
return IpmiConfiguration
.builder()
.username(username == null ? defaultUsername : username)
.password(username == null ? defaultPassword : password)
.bmcKey(ArrayHelper.hexToByteArray(bmcKey))
.skipAuth(skipAuth)
.timeout(timeout)
.build();
} catch (Exception e) {
throw new ParameterException(spec.commandLine(), e.getMessage());
}
public IConfiguration toProtocol(final String defaultUsername, final char[] defaultPassword)
throws InvalidConfigurationException {
final ObjectNode configuration = JsonNodeFactory.instance.objectNode();
configuration.set("username", new TextNode(username == null ? defaultUsername : username));
configuration.set(
"password",
new TextNode(username == null ? String.valueOf(defaultPassword) : String.valueOf(password))
);
configuration.set("timeout", new TextNode(timeout));

return CliExtensionManager
.getExtensionManagerSingleton()
.buildConfigurationFromJsonNode("ipmi", configuration, value -> value)
.orElseThrow();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.sentrysoftware.metricshub.agent.extension;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.sentrysoftware.metricshub.engine.common.exception.InvalidConfigurationException;
import org.sentrysoftware.metricshub.engine.common.helpers.StringHelper;
import org.sentrysoftware.metricshub.engine.configuration.IConfiguration;

/**
* The IpmiConfiguration class represents the configuration for IPMI (Intelligent Platform Management Interface) connections
* in the MetricsHub engine.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class IpmiTestConfiguration implements IConfiguration {

@Builder.Default
private final Long timeout = 120L;

private String username;
private char[] password;
private byte[] bmcKey;
private boolean skipAuth;

@Override
public String toString() {
String description = "IPMI";
if (username != null) {
description = description + " as " + username;
}
return description;
}

/**
* Validate the given IPMI information (username and timeout)
*
* @param resourceKey Resource unique identifier
* @throws InvalidConfigurationException
*/
@Override
public void validateConfiguration(String resourceKey) throws InvalidConfigurationException {
StringHelper.validateConfigurationAttribute(
username,
attr -> attr == null || attr == "",
() ->
String.format(
"Resource %s - Username value is invalid for protocol %s." +
" Timeout value returned: %s. This resource will not be monitored. Please verify the configured timeout value.",
resourceKey,
"HTTP",
timeout
)
);

StringHelper.validateConfigurationAttribute(
timeout,
attr -> attr == null || attr < 0L,
() ->
String.format(
"Resource %s - Timeout value is invalid for protocol %s." +
" Timeout value returned: %s. This resource will not be monitored. Please verify the configured timeout value.",
resourceKey,
"HTTP",
timeout
)
);

StringHelper.validateConfigurationAttribute(
timeout,
attr -> attr == null || attr < 0L,
() ->
String.format(
"Resource %s - Timeout value is invalid for protocol %s." +
" Timeout value returned: %s. This resource will not be monitored. Please verify the configured timeout value.",
resourceKey,
"HTTP",
timeout
)
);

StringHelper.validateConfigurationAttribute(
timeout,
attr -> attr == null || attr < 0L,
() ->
String.format(
"Resource %s - Timeout value is invalid for protocol %s." +
" Timeout value returned: %s. This resource will not be monitored. Please verify the configured timeout value.",
resourceKey,
"HTTP",
timeout
)
);
}
}
Loading

0 comments on commit 6811ed9

Please sign in to comment.