Search in sources :

Example 21 with Value

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;
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Example 22 with Value

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;
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Example 23 with Value

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;
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Example 24 with Value

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();
    }
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Example 25 with Value

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++;
        }
    }
}
Also used : Value(org.opennms.netmgt.xml.event.Value) Parm(org.opennms.netmgt.xml.event.Parm)

Aggregations

Value (org.opennms.netmgt.xml.event.Value)33 Parm (org.opennms.netmgt.xml.event.Parm)31 InetAddress (java.net.InetAddress)5 Event (org.opennms.netmgt.xml.event.Event)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 Test (org.junit.Test)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 PollableNode (org.opennms.netmgt.poller.pollables.PollableNode)3 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)2 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 PollableInterface (org.opennms.netmgt.poller.pollables.PollableInterface)2 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 Logmsg (org.opennms.netmgt.xml.event.Logmsg)2 Snmp (org.opennms.netmgt.xml.event.Snmp)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1