diff --git a/collector/src/main/java/com/usthe/collector/collect/snmp/SnmpCollectImpl.java b/collector/src/main/java/com/usthe/collector/collect/snmp/SnmpCollectImpl.java index 424563b172e..d93ee498078 100644 --- a/collector/src/main/java/com/usthe/collector/collect/snmp/SnmpCollectImpl.java +++ b/collector/src/main/java/com/usthe/collector/collect/snmp/SnmpCollectImpl.java @@ -150,7 +150,11 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a } catch (Exception e) { log.warn("[snmp collect] error: {}", e.getMessage(), e); builder.setCode(CollectRep.Code.FAIL); - builder.setMsg(e.getMessage()); + if (e.getMessage() == null) { + builder.setMsg(e.toString()); + } else { + builder.setMsg(e.getMessage()); + } } } diff --git a/collector/src/main/java/com/usthe/collector/util/CollectUtil.java b/collector/src/main/java/com/usthe/collector/util/CollectUtil.java index fa45fdb0732..44c67c6cbbb 100644 --- a/collector/src/main/java/com/usthe/collector/util/CollectUtil.java +++ b/collector/src/main/java/com/usthe/collector/util/CollectUtil.java @@ -17,10 +17,7 @@ package com.usthe.collector.util; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; +import com.google.gson.*; import com.google.gson.reflect.TypeToken; import com.usthe.common.entity.job.Configmap; import com.usthe.common.util.CommonConstants; @@ -46,9 +43,12 @@ public class CollectUtil { private static final int DEFAULT_TIMEOUT = 60000; private static final String SMILING_PLACEHOLDER = "^_^"; - private static final String SMILING_PLACEHOLDER_REGEX = "\\^_\\^"; + private static final String SMILING_PLACEHOLDER_REX = "\\^_\\^"; + private static final String SMILING_PLACEHOLDER_REGEX = "(\\^_\\^)(\\w|-|$|\\.)+(\\^_\\^)"; + private static final Pattern SMILING_PLACEHOLDER_REGEX_PATTERN = Pattern.compile(SMILING_PLACEHOLDER_REGEX); private static final String CRYING_PLACEHOLDER = "-_-"; - private static final String CRYING_PLACEHOLDER_REGEX = "-_-"; + private static final String CRYING_PLACEHOLDER_REGEX = "(-_-)(\\w|-|$|\\.)+(-_-)"; + private static final Pattern CRYING_PLACEHOLDER_REGEX_PATTERN = Pattern.compile(CRYING_PLACEHOLDER_REGEX); private static final List UNIT_SYMBOLS = Arrays.asList("G", "g", "M", "m", "K", "k", "B", "b", "%"); /** @@ -196,15 +196,27 @@ public static JsonElement replaceCryPlaceholder(JsonElement jsonElement, Map