use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class EventParameterUtils method format.
/**
* Format each parameter
*
* @param parm
* the parameter
* @return the formatted event parameter string
*/
public static String format(Parm parm) {
Value pValue = parm.getValue();
String type = pValue.getType();
String encoding = pValue.getEncoding();
String tmp = EventDatabaseConstants.escape(parm.getParmName(), EventDatabaseConstants.NAME_VAL_DELIM);
String name = EventDatabaseConstants.escape(tmp, EventDatabaseConstants.MULTIPLE_VAL_DELIM);
tmp = EventDatabaseConstants.escape(pValue.getContent(), EventDatabaseConstants.NAME_VAL_DELIM);
String value = EventDatabaseConstants.escape(tmp, EventDatabaseConstants.MULTIPLE_VAL_DELIM);
String empty = "";
name = (name != null ? name.trim() : empty);
value = (value != null ? value.trim() : empty);
type = (type != null ? type.trim() : empty);
encoding = (encoding != null ? encoding.trim() : empty);
StringBuffer buf = new StringBuffer();
buf.append(name);
buf.append(EventDatabaseConstants.NAME_VAL_DELIM);
buf.append(value);
buf.append('(');
buf.append(type);
buf.append(EventDatabaseConstants.DB_ATTRIB_DELIM);
buf.append(encoding);
buf.append(')');
return buf.toString();
// return name + EventDatabaseConstants.NAME_VAL_DELIM + value + "(" + type +
// EventDatabaseConstants.DB_ATTRIB_DELIM + encoding + ")";
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class EventParameterUtils method decode.
/**
* <p>decode</p>
*
* @param eventparms an event parm string
* @return a list of parameters
*/
public static List<Parm> decode(final String eventparms) {
if (eventparms == null)
return null;
final List<Parm> parms = new ArrayList<Parm>();
String[] paramslistString = eventparms.split(Character.toString(EventDatabaseConstants.MULTIPLE_VAL_DELIM));
if (paramslistString != null) {
for (int i = 0; i < paramslistString.length; i++) {
String[] paramEncoded = paramslistString[i].split(Character.toString(EventDatabaseConstants.NAME_VAL_DELIM));
if (paramEncoded != null && paramEncoded.length == 2) {
Parm parm = new Parm();
parm.setParmName(paramEncoded[0]);
Value value = new Value();
int startParamType = paramEncoded[1].lastIndexOf('(');
if (startParamType == -1) {
value.setContent(paramEncoded[1]);
value.setType("string");
value.setEncoding("text");
} else {
value.setContent(paramEncoded[1].substring(0, startParamType));
String paramType = paramEncoded[1].substring(startParamType + 1);
String[] typeAndEncode = paramType.split(Character.toString(EventDatabaseConstants.DB_ATTRIB_DELIM));
if (typeAndEncode != null && typeAndEncode.length == 2) {
value.setType(typeAndEncode[0]);
value.setEncoding(typeAndEncode[1].split("\\)")[0]);
} else {
value.setType("string");
value.setEncoding("text");
}
}
parm.setValue(value);
parms.add(parm);
}
}
}
return parms;
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class AbstractEventUtil method getNumParmValue.
/**
* Helper method.
*
* @param parm
* @param event
* @return The value of a parameter based on its ordinal position in the event's list of parameters
*/
protected static String getNumParmValue(String parm, Event event) {
String retParmVal = null;
final List<Parm> parms = event.getParmCollection();
int end = parm.lastIndexOf(PARM_END_SUFFIX);
if (end != -1 && parms != null && parms.size() > 0) {
// Get the value between the '#' and ']'
String eparmname = parm.substring(PARM_NUM_PREFIX_LENGTH, end);
int parmNum = -1;
try {
parmNum = Integer.parseInt(eparmname);
} catch (NumberFormatException nfe) {
parmNum = -1;
retParmVal = null;
}
if (parmNum > 0 && parmNum <= parms.size()) {
final Parm evParm = parms.get(parmNum - 1);
// get parm value
Value eparmval = evParm.getValue();
if (eparmval != null) {
retParmVal = EventConstants.getValueAsString(eparmval);
}
} else {
retParmVal = null;
}
}
return retParmVal;
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class AbstractEventUtil method getNamedParmValue.
/**
* Helper method.
*
* @param parm a {@link java.lang.String} object.
* @param event a {@link org.opennms.netmgt.xml.event.Event} object.
* @return A parameter's value as a String using the parameter's name..
*/
public String getNamedParmValue(String parm, Event event) {
final Matcher matcher = PARM_REGEX.matcher(parm);
if (!matcher.matches()) {
return null;
}
final String eparmname = matcher.group(1);
final Parm evParm = event.getParmTrim(eparmname);
if (evParm != null) {
final Value eparmval = evParm.getValue();
if (eparmval != null) {
return EventConstants.getValueAsString(eparmval);
}
}
return null;
}
use of org.opennms.netmgt.xml.event.Value 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);
}
Aggregations