in hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/snmp/SnmpCollectImpl.java [323:362]
private static boolean isDateAndTimeOctetString(VariableBinding binding) {
if (!(binding.getVariable() instanceof OctetString)) {
return false;
}
byte[] bytes = HexFormat.of().parseHex(binding.toValueString().replaceAll(HEX_SPLIT, ""));
if (bytes.length != 8 && bytes.length != 11) return false;
int year = ((bytes[0] & 0xFF) << 8) | (bytes[1] & 0xFF);
if (year < 1970 || year > 3000) return false;
int month = bytes[2] & 0xFF;
if (month < 1 || month > 12) return false;
int day = bytes[3] & 0xFF;
if (day < 1 || day > 31) return false;
int hour = bytes[4] & 0xFF;
if (hour > 23) return false;
int minute = bytes[5] & 0xFF;
if (minute > 59) return false;
int second = bytes[6] & 0xFF;
if (second > 59) return false;
int deciSecond = bytes[7] & 0xFF;
if (deciSecond > 99) return false;
if (bytes.length == 11) {
int tzSign = bytes[8] & 0xFF;
if (tzSign != 0x2B && tzSign != 0x2D) return false;
int tzHour = bytes[9] & 0xFF;
if (tzHour > 23) return false;
int tzMinute = bytes[10] & 0xFF;
if (tzMinute > 59) return false;
}
return true;
}