diff --git a/metricshub-agent/src/main/java/org/sentrysoftware/metricshub/cli/snmp/SnmpCli.java b/metricshub-agent/src/main/java/org/sentrysoftware/metricshub/cli/snmp/SnmpCli.java index d940e8131..8f1988708 100644 --- a/metricshub-agent/src/main/java/org/sentrysoftware/metricshub/cli/snmp/SnmpCli.java +++ b/metricshub-agent/src/main/java/org/sentrysoftware/metricshub/cli/snmp/SnmpCli.java @@ -71,6 +71,7 @@ public class SnmpCli implements IQuery, Callable { @Option(names = "-v", order = 7, description = "Verbose mode (repeat the option to increase verbosity)") boolean[] verbose; + @Override public JsonNode getQuery() { final ObjectNode queryNode = JsonNodeFactory.instance.objectNode(); String action; @@ -93,6 +94,11 @@ public JsonNode getQuery() { return queryNode; } + /** + * Validates SNMP configuration and ensures exactly one query type (--snmp-get, --snmp-getnext, or --snmp-walk) is specified. + * + * @throws ParameterException if SNMP is not configured, no query is specified, or multiple queries are specified. + */ void validate() throws ParameterException { if (snmpConfigCli == null) { throw new ParameterException(spec.commandLine(), "SNMP protocol must be configured: --snmp."); diff --git a/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/common/IQuery.java b/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/common/IQuery.java index 4c16d1c74..3fc0fbdc6 100644 --- a/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/common/IQuery.java +++ b/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/common/IQuery.java @@ -1,5 +1,7 @@ package org.sentrysoftware.metricshub.engine.common; +import com.fasterxml.jackson.databind.JsonNode; + /*- * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ * MetricsHub Engine @@ -20,4 +22,15 @@ * along with this program. If not, see . * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ */ -public interface IQuery {} + +/** + * Represents a query to be executed by an extension. + */ +public interface IQuery { + /** + * Builds and returns the query as a JSON object. + * + * @return the query as a {@link JsonNode}. + */ + JsonNode getQuery(); +}