use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class EventBuilder method addParam.
public EventBuilder addParam(final String parmName, final String val, final String type, final String encoding) {
if (parmName != null) {
Value value = new Value();
value.setContent(val);
if (type != null) {
value.setType(type);
}
if (encoding != null) {
value.setEncoding(encoding);
}
Parm parm = new Parm();
parm.setParmName(parmName);
parm.setValue(value);
addParam(parm);
}
return this;
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class NotifdConfigManager method matchNotificationParameters.
// TODO This change only works for one parameter, need to expand it to many.
/**
* <p>matchNotificationParameters</p>
*
* @param event a {@link org.opennms.netmgt.xml.event.Event} object.
* @param notification a {@link org.opennms.netmgt.config.notifications.Notification} object.
* @return a boolean.
*/
public boolean matchNotificationParameters(Event event, Notification notification) {
boolean parmmatch = false;
if (notification.getVarbind() != null && notification.getVarbind().getVbname() != null) {
String notfValue = null;
String notfName = notification.getVarbind().getVbname();
if (notification.getVarbind().getVbvalue() != null) {
notfValue = notification.getVarbind().getVbvalue();
} else {
LOG.debug("BroadcastEventProcessor:matchNotificationParameters: Null value for varbind, assuming true.");
parmmatch = true;
}
for (final Parm parm : event.getParmCollection()) {
final String parmName = parm.getParmName();
final Value parmValue = parm.getValue();
final String parmContent;
if (parmValue == null) {
continue;
} else {
parmContent = parmValue.getContent();
}
if (parmName.equals(notfName)) {
// regular expression should start with a '~'
if (notfValue.charAt(0) == '~') {
if (parmContent.matches(notfValue.substring(1))) {
parmmatch = true;
}
} else {
if (parmContent.startsWith(notfValue)) {
parmmatch = true;
}
}
}
}
} else if (notification.getVarbind() == null || notification.getVarbind().getVbname() == null) {
parmmatch = true;
}
return parmmatch;
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class AbstractEventUtil method getAllParmValues.
/**
* Helper method.
*
* @param event
* @return All event parameter values as a String.
*/
protected static String getAllParmValues(Event event) {
String retParmVal = null;
if (event.getParmCollection().size() < 1) {
retParmVal = null;
} else {
final StringBuilder ret = new StringBuilder();
for (Parm evParm : event.getParmCollection()) {
Value parmValue = evParm.getValue();
if (parmValue == null)
continue;
String parmValueStr = EventConstants.getValueAsString(parmValue);
if (parmValueStr == null)
continue;
if (ret.length() == 0) {
ret.append(parmValueStr);
} else {
ret.append(SPACE_DELIM + parmValueStr);
}
}
retParmVal = ret.toString();
}
return retParmVal;
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class AbstractEventUtil method getAllParamValues.
/**
* Helper method.
*
* @param event
* @return All event parameter values as a String
*/
protected static String getAllParamValues(final Event event) {
if (event.getParmCollection().size() < 1) {
return null;
} else {
final StringBuilder ret = new StringBuilder();
for (final Parm evParm : event.getParmCollection()) {
final String parmName = evParm.getParmName();
if (parmName == null)
continue;
final Value parmValue = evParm.getValue();
if (parmValue == null)
continue;
final String parmValueStr = EventConstants.getValueAsString(parmValue);
if (ret.length() != 0) {
ret.append(SPACE_DELIM);
}
ret.append(parmName.trim()).append(NAME_VAL_DELIM).append("\"").append(parmValueStr).append("\"");
}
return ret.toString().intern();
}
}
use of org.opennms.netmgt.xml.event.Value in project opennms by OpenNMS.
the class SnmpTrapHelper method addParameters.
/**
* Adds the parameters.
*
* @param builder the trap builder object
* @param trapConfig the trap configuration object
* @throws SnmpTrapException the SNMP trap exception
*/
private void addParameters(SnmpTrapBuilder builder, SnmpTrapConfig trapConfig) throws SnmpTrapException {
int i = 0;
for (Parm parm : trapConfig.getParameters()) {
try {
Value value = parm.getValue();
addVarBinding(builder, parm.getParmName(), value.getType(), value.getEncoding(), value.getContent());
} catch (SnmpTrapException e) {
throw new SnmpTrapException(e.getMessage() + " in event parm[" + i + "]");
} finally {
i++;
}
}
}
Aggregations