use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.
the class EventExpander method expandEvent.
/**
* <p>
* This method is invoked to check and configure a received event. The event
* configuration manager is consulted to find the appropriate configuration
* that is used to expand the event. In addition, the security parameters
* from the configuration manager is consulted to ensure that secure files
* are cleared out if necessary.
* </p>
*
* <p>
* Any secure fields that exists in the incoming event are cleared during
* expansion.
* </p>
*
* @param e
* The event to expand if necessary.
*/
public void expandEvent(Event e) {
org.opennms.netmgt.xml.eventconf.Event econf = lookup(m_eventConfDao, e);
if (econf != null) {
if (m_eventConfDao.isSecureTag("mask")) {
e.setMask(null);
}
if (e.getMask() == null && econf.getMask() != null) {
e.setMask(transform(econf.getMask()));
}
//
if (e.getUei() == null) {
e.setUei(econf.getUei());
}
//
if (e.getSnmp() == null && econf.getSnmp() != null) {
e.setSnmp(transform(econf.getSnmp()));
}
//
if (m_eventConfDao.isSecureTag("descr")) {
e.setDescr(null);
}
if (e.getDescr() == null && econf.getDescr() != null) {
e.setDescr(econf.getDescr());
}
//
if (m_eventConfDao.isSecureTag("logmsg")) {
e.setLogmsg(null);
}
if (e.getLogmsg() == null && econf.getLogmsg() != null) {
e.setLogmsg(transform(econf.getLogmsg()));
}
//
if (m_eventConfDao.isSecureTag("severity")) {
e.setSeverity(null);
}
if (e.getSeverity() == null && econf.getSeverity() != null) {
e.setSeverity(econf.getSeverity());
}
//
if (m_eventConfDao.isSecureTag("correlation")) {
e.setCorrelation(null);
}
if (e.getCorrelation() == null && econf.getCorrelation() != null) {
e.setCorrelation(transform(econf.getCorrelation()));
}
//
if (m_eventConfDao.isSecureTag("operinstruct")) {
e.setOperinstruct(null);
}
if (e.getOperinstruct() == null && econf.getOperinstruct() != null) {
e.setOperinstruct(econf.getOperinstruct());
}
//
if (m_eventConfDao.isSecureTag("autoaction")) {
e.removeAllAutoaction();
}
if (e.getAutoactionCount() == 0 && econf.getAutoactions().size() > 0) {
econf.getAutoactions().forEach(aa -> {
e.addAutoaction(transform(aa));
});
}
//
if (m_eventConfDao.isSecureTag("operaction")) {
e.removeAllOperaction();
}
if (e.getOperactionCount() == 0 && econf.getOperactions().size() > 0) {
econf.getOperactions().forEach(oa -> {
e.addOperaction(transform(oa));
});
}
//
if (m_eventConfDao.isSecureTag("autoacknowledge")) {
e.setAutoacknowledge(null);
}
if (e.getAutoacknowledge() == null && econf.getAutoacknowledge() != null) {
e.setAutoacknowledge(transform(econf.getAutoacknowledge()));
}
//
if (m_eventConfDao.isSecureTag("loggroup")) {
e.removeAllLoggroup();
}
if (e.getLoggroupCount() == 0 && econf.getLoggroups().size() > 0) {
e.setLoggroup(econf.getLoggroups());
}
//
if (m_eventConfDao.isSecureTag("tticket")) {
e.setTticket(null);
}
if (e.getTticket() == null && econf.getTticket() != null) {
e.setTticket(transform(econf.getTticket()));
}
//
if (m_eventConfDao.isSecureTag("forward")) {
e.removeAllForward();
}
if (e.getForwardCount() == 0 && econf.getForwards().size() > 0) {
econf.getForwards().forEach(fc -> {
e.addForward(transform(fc));
});
}
//
if (m_eventConfDao.isSecureTag("script")) {
e.removeAllScript();
}
if (e.getScriptCount() == 0 && econf.getScripts().size() > 0) {
econf.getScripts().forEach(sc -> {
e.addScript(transform(sc));
});
}
//
if (m_eventConfDao.isSecureTag("mouseovertext")) {
e.setMouseovertext(null);
}
if (e.getMouseovertext() == null && econf.getMouseovertext() != null) {
e.setMouseovertext(econf.getMouseovertext());
}
if (e.getAlarmData() == null && econf.getAlarmData() != null) {
AlarmData alarmData = new AlarmData();
final org.opennms.netmgt.xml.eventconf.AlarmData econfAlarmData = econf.getAlarmData();
alarmData.setAlarmType(econfAlarmData.getAlarmType());
alarmData.setReductionKey(econfAlarmData.getReductionKey());
alarmData.setAutoClean(econfAlarmData.getAutoClean());
alarmData.setX733AlarmType(econfAlarmData.getX733AlarmType());
alarmData.setX733ProbableCause(econfAlarmData.getX733ProbableCause());
alarmData.setClearKey(econfAlarmData.getClearKey());
List<org.opennms.netmgt.xml.eventconf.UpdateField> updateFieldList = econfAlarmData.getUpdateFields();
if (updateFieldList.size() > 0) {
List<UpdateField> updateFields = new ArrayList<>(updateFieldList.size());
for (org.opennms.netmgt.xml.eventconf.UpdateField econfUpdateField : updateFieldList) {
UpdateField eventField = new UpdateField();
eventField.setFieldName(econfUpdateField.getFieldName());
eventField.setUpdateOnReduction(econfUpdateField.getUpdateOnReduction());
updateFields.add(eventField);
}
alarmData.setUpdateField(updateFields);
}
e.setAlarmData(alarmData);
}
if (econf.getParameters() != null && econf.getParameters().size() > 0) {
if (e.getParmCollection() == null) {
e.setParmCollection(new ArrayList<>(econf.getParameters().size()));
}
for (Parameter p : econf.getParameters()) {
if (EventUtils.getParm(e, p.getName()) == null) {
Parm parm = new Parm();
parm.setParmName(p.getName());
Value v = new Value();
v.setContent(p.getValue());
v.setType("string");
v.setEncoding("text");
v.setExpand(p.getExpand());
parm.setValue(v);
e.addParm(parm);
} else {
LOG.warn("expandEvent: the event {} already has a parameter named {}, the original content will be preserved. Check the event definition and rename the optional parameter.", e.getUei(), p.getName());
}
}
}
}
Map<String, Map<String, String>> decode = new HashMap<String, Map<String, String>>();
if (econf != null && econf.getVarbindsdecodes().size() > 0) {
for (final Varbindsdecode element : econf.getVarbindsdecodes()) {
List<Decode> decodeArray = element.getDecodes();
Map<String, String> valueMap = new HashMap<String, String>();
for (final Decode element2 : decodeArray) {
valueMap.put(element2.getVarbindvalue(), element2.getVarbinddecodedstring());
}
decode.put(element.getParmid(), valueMap);
}
}
// end fill of event using econf
// do the event parm expansion
expandParms(e, decode);
}
use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.
the class JsmiMibParser method getTrapVarbindsDecode.
/**
* Gets the trap varbinds decode.
*
* @param trap the trap object
* @return the trap varbinds decode
*/
protected List<Varbindsdecode> getTrapVarbindsDecode(Notification trap) {
Map<String, Varbindsdecode> decode = new LinkedHashMap<String, Varbindsdecode>();
int vbNum = 1;
for (SmiVariable var : trap.getObjects()) {
String parmName = "parm[#" + vbNum + "]";
SmiPrimitiveType type = var.getType().getPrimitiveType();
if (type.equals(SmiPrimitiveType.ENUM)) {
SortedMap<BigInteger, String> map = new TreeMap<BigInteger, String>();
SmiType t = var.getType();
while (t.getEnumValues() == null) {
t = t.getBaseType();
}
List<SmiNamedNumber> enumValues = t.getEnumValues();
if (enumValues != null) {
for (SmiNamedNumber v : enumValues) {
map.put(v.getValue(), v.getId());
}
for (Entry<BigInteger, String> entry : map.entrySet()) {
if (!decode.containsKey(parmName)) {
Varbindsdecode newVarbind = new Varbindsdecode();
newVarbind.setParmid(parmName);
decode.put(newVarbind.getParmid(), newVarbind);
}
Decode d = new Decode();
d.setVarbinddecodedstring(entry.getValue());
d.setVarbindvalue(entry.getKey().toString());
decode.get(parmName).addDecode(d);
}
}
}
vbNum++;
}
return new ArrayList<Varbindsdecode>(decode.values());
}
use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.
the class JsmiMibParserTest method testNotifications.
/**
* Test generate events from notifications.
*
* @throws Exception the exception
*/
@Test
public void testNotifications() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "IF-MIB.txt"))) {
Events events = parser.getEvents("uei.opennms.org/traps/ifmib");
Assert.assertNotNull(events);
System.out.println(JaxbUtils.marshal(events));
Assert.assertEquals(2, events.getEvents().size());
Event event = null;
for (Event e : events.getEvents()) {
if (e.getUei().contains("linkDown"))
event = e;
}
Assert.assertNotNull(event);
// TODO Must be more specific
Assert.assertNotNull(event.getDescr());
Assert.assertNotNull(event.getLogmsg());
// TODO Must be more specific
Assert.assertNotNull(event.getLogmsg().getContent());
Assert.assertEquals("Indeterminate", event.getSeverity());
Assert.assertEquals("IF-MIB defined trap event: linkDown", event.getEventLabel());
Assert.assertNotNull(event.getMask());
for (final Maskelement me : event.getMask().getMaskelements()) {
if (me.getMename().equals("id"))
Assert.assertEquals(".1.3.6.1.6.3.1.1.5", me.getMevalues().get(0));
if (me.getMename().equals("generic"))
Assert.assertEquals("6", me.getMevalues().get(0));
if (me.getMename().equals("specific"))
Assert.assertEquals("3", me.getMevalues().get(0));
}
Assert.assertEquals(2, event.getVarbindsdecodes().size());
for (Varbindsdecode vb : event.getVarbindsdecodes()) {
if (vb.getParmid().equals("parm[#2]"))
Assert.assertEquals(3, vb.getDecodes().size());
if (vb.getParmid().equals("parm[#3]"))
Assert.assertEquals(7, vb.getDecodes().size());
}
} else {
Assert.fail("The IF-MIB.txt file couldn't be parsed successfully.");
}
}
use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.
the class SpectrumUtils method translateAllEventTables.
public List<Varbindsdecode> translateAllEventTables(EventFormat ef, String eventTablePath) throws IOException {
List<Varbindsdecode> vbds = new ArrayList<>();
Pattern pat = Pattern.compile("^\\{\\s*T\\s+(\\w+)\\s+(\\d+)\\s*\\}");
for (String token : ef.getSubstTokens()) {
Matcher mat = pat.matcher(token);
if (mat.matches()) {
LOG.debug("Token [{}] looks like an event-table, processing it", token);
EventTable et = loadEventTable(eventTablePath, mat.group(1));
String parmId = "parm[#" + mat.group(2) + "]";
Varbindsdecode vbd = translateEventTable(et, parmId);
LOG.debug("Loaded event-table [{}] with parm-ID [{}], with {} mappings", et.getTableName(), parmId, vbd.getDecodeCount());
vbds.add(translateEventTable(et, parmId));
} else {
LOG.debug("Token [{}] does not look like an event-table, skipping it", token);
}
}
LOG.debug("Translated %d event-tables for event-code [{}]", vbds.size(), ef.getEventCode());
return vbds;
}
use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.
the class SpectrumUtilsTest method translateSimpleEventTable.
@Test
public void translateSimpleEventTable() {
EventTable et = new EventTable("foobar");
et.put(1, "foo");
et.put(2, "bar");
et.put(3, "baz");
Varbindsdecode vbd = m_utils.translateEventTable(et, "parm[#1]");
Assert.assertEquals("Parm ID is parm[#1]", "parm[#1]", vbd.getParmid());
Assert.assertEquals("Three decode elements", 3, vbd.getDecodeCount());
Assert.assertEquals("First key is 1", "1", vbd.getDecode(0).getVarbindvalue());
Assert.assertEquals("First value is foo", "foo", vbd.getDecode(0).getVarbinddecodedstring());
Assert.assertEquals("Second key is 2", "2", vbd.getDecode(1).getVarbindvalue());
Assert.assertEquals("Second value is bar", "bar", vbd.getDecode(1).getVarbinddecodedstring());
Assert.assertEquals("Third key is 3", "3", vbd.getDecode(2).getVarbindvalue());
Assert.assertEquals("Third value is baz", "baz", vbd.getDecode(2).getVarbinddecodedstring());
}
Aggregations