apache / hertzbeat

Apache HertzBeat(incubating) is a real-time monitoring system with agentless, performance cluster, prometheus-compatible, custom monitoring and status page building capabilities.
https://hertzbeat.apache.org/
Apache License 2.0
5.53k stars 958 forks source link

[Question] I did not get the desired result using SNMP. #2740

Open MaNong889 opened 6 days ago

MaNong889 commented 6 days ago

Question

When I use a custom SNMP template to retrieve the power status and fan status, the value is not 'OK', but the number 4 and 3. image image image image image

MaNong889 commented 5 days ago

The value I expected ok, but the result was 3 and 4

MaNong889 commented 5 days ago

image Why is my field type set to 1, but instead of getting a string, it retrieves a number?

zuobiao-zhou commented 3 days ago

Since the code returns a number instead of the string you were expecting, could you help us fix it?

MaNong889 commented 2 days ago

or (VariableBinding binding : vbs) { if (binding == null) { continue; }

Variable variable = binding.getVariable();
String value;

if (variable instanceof TimeTicks timeTicks) {
    String timeValue = timeTicks.toString(FORMAT_PATTERN);
    oidsValueMap.put(binding.getOid().toDottedString(), timeValue);
} else {
    String valueString = binding.toValueString();
    if (valueString.matches("^[a-zA-Z]+\\(\\d+\\)$")) {
        value = valueString.substring(0, valueString.indexOf("(")).trim();
    } else {
        value = valueString; 
    }
    oidsValueMap.put(binding.getOid().toDottedString(), value);
}

} I am an operations engineer and I don't understand Java code. However, I sent the SnmpCollectImpl.java file to ChatGPT, and it helped me write a chunk of code that I replaced in the data collection part of SnmpCollectImpl.java. But the compilation keeps failing, and I can't resolve it. What should I do?

zuobiao-zhou commented 2 days ago

Hello, in our project, we utilize snmp4j to implement the SNMP protocol. When performing GET operations to query the power status or fan status, snmp4j only provides a numerical representation of the query results. As shown in your command line screenshot, a value of 4 for power status indicates that the power is on, while a value of 3 for fan status indicates that the fan is operating normally. This is reflected in the code snippet oidsValueMap.put(binding.getOid().toDottedString(), binding.toValueString()); within snmpCollectImpl.java.

Although this approach is not as intuitive as using "on" or "ok", it does function properly, and we can still set up alerts based on these values. Currently, I haven't come up with an optimal solution to make the outputs more descriptive.