@Test public void translateAllVarbindTokensInMessage() { String input = "{d \"%w- %d %m-, %Y - %T\"} - A \"empSIP4xxErrorsBelowEvent\" event has occurred, from {t} device, named {m}.\n\n" + "\"Event generated when one of the SIP 400s error\n" + "values goes below the range specified for\n" + "that particular object\"\n\n" + "empSIP4xxStatEventInfo = {S 1}\n" + "(event [{e}])\n"; EventFormat format = new EventFormat("0xdeadbeef"); format.setContents(input); String output = m_utils.translateAllSubstTokens(format); Assert.assertTrue("Date token got removed", !output.contains("{d")); Assert.assertTrue("Date token got replaced correctly", output.contains("%eventtime%")); Assert.assertTrue("Model-type token got removed", !output.contains("{t}")); Assert.assertTrue("Model-type token got replaced correctly", output.contains("%asset[manufacturer]%")); Assert.assertTrue("Model-name token got removed", !output.contains("{m}")); Assert.assertTrue("Model-name token got replaced correctly", output.contains("%nodelabel%")); Assert.assertTrue("Varbind 1 token got removed", !output.contains("{S 1}")); Assert.assertTrue("Varbind 1 token got replaced correctly", output.contains("%parm[#1]%")); Assert.assertTrue("Event-ID token got removed", !output.contains("{e}")); Assert.assertTrue("Event-ID token got replaced correctly", output.contains("%uei%")); }
public String translateAllSubstTokens(EventFormat format) { String untranslated = format.getContents(); String translated = untranslated; Matcher m = Pattern.compile("(?s)(\\{.*?\\})").matcher(untranslated); while (m.find()) { LogUtils.debugf(this, "Found a token [%s], replacing it with token [%s]", m.group(1), translateFormatSubstToken(m.group(1))); translated = translated.replace(m.group(1), translateFormatSubstToken(m.group(1))); LogUtils.debugf(this, "New translated string: %s", translated); } return translated; }
SpectrumUtils { public String translateAllSubstTokens(EventFormat format) { String untranslated = format.getContents(); String translated = untranslated; Matcher m = Pattern.compile("(?s)(\\{.*?\\})").matcher(untranslated); while (m.find()) { LogUtils.debugf(this, "Found a token [%s], replacing it with token [%s]", m.group(1), translateFormatSubstToken(m.group(1))); translated = translated.replace(m.group(1), translateFormatSubstToken(m.group(1))); LogUtils.debugf(this, "New translated string: %s", translated); } return translated; } }
SpectrumUtils { public String translateAllSubstTokens(EventFormat format) { String untranslated = format.getContents(); String translated = untranslated; Matcher m = Pattern.compile("(?s)(\\{.*?\\})").matcher(untranslated); while (m.find()) { LogUtils.debugf(this, "Found a token [%s], replacing it with token [%s]", m.group(1), translateFormatSubstToken(m.group(1))); translated = translated.replace(m.group(1), translateFormatSubstToken(m.group(1))); LogUtils.debugf(this, "New translated string: %s", translated); } return translated; } SpectrumUtils(); }
SpectrumUtils { public String translateAllSubstTokens(EventFormat format) { String untranslated = format.getContents(); String translated = untranslated; Matcher m = Pattern.compile("(?s)(\\{.*?\\})").matcher(untranslated); while (m.find()) { LogUtils.debugf(this, "Found a token [%s], replacing it with token [%s]", m.group(1), translateFormatSubstToken(m.group(1))); translated = translated.replace(m.group(1), translateFormatSubstToken(m.group(1))); LogUtils.debugf(this, "New translated string: %s", translated); } return translated; } SpectrumUtils(); String translateAllSubstTokens(EventFormat format); String translateFormatSubstToken(String inToken); List<Varbindsdecode> translateAllEventTables(EventFormat ef, String eventTablePath); Varbindsdecode translateEventTable(EventTable et, String parmId); String translateSeverity(int spectrumSeverity); void setModelTypeAssetField(String fieldName); String getModelTypeAssetField(); }
SpectrumUtils { public String translateAllSubstTokens(EventFormat format) { String untranslated = format.getContents(); String translated = untranslated; Matcher m = Pattern.compile("(?s)(\\{.*?\\})").matcher(untranslated); while (m.find()) { LogUtils.debugf(this, "Found a token [%s], replacing it with token [%s]", m.group(1), translateFormatSubstToken(m.group(1))); translated = translated.replace(m.group(1), translateFormatSubstToken(m.group(1))); LogUtils.debugf(this, "New translated string: %s", translated); } return translated; } SpectrumUtils(); String translateAllSubstTokens(EventFormat format); String translateFormatSubstToken(String inToken); List<Varbindsdecode> translateAllEventTables(EventFormat ef, String eventTablePath); Varbindsdecode translateEventTable(EventTable et, String parmId); String translateSeverity(int spectrumSeverity); void setModelTypeAssetField(String fieldName); String getModelTypeAssetField();  }