Search in sources :

Example 11 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class AlarmChangeNotificationClient method jsonAlarmToEventBuilder.

private EventBuilder jsonAlarmToEventBuilder(JSONObject jsonObject, EventBuilder eb) {
    // copy generic alarm details as paramaters
    String alarmId = (jsonObject.get("alarmid") == null) ? null : jsonObject.get("alarmid").toString();
    String severity = (jsonObject.get("severity") == null) ? null : jsonObject.get("severity").toString();
    String logmsg = (jsonObject.get("logmsg") == null) ? null : jsonObject.get("logmsg").toString();
    String eventuei = (jsonObject.get("eventuei") == null) ? null : jsonObject.get("eventuei").toString();
    String reductionkey = (jsonObject.get("reductionkey") == null) ? null : jsonObject.get("reductionkey").toString();
    String clearkey = (jsonObject.get("clearkey") == null) ? null : jsonObject.get("clearkey").toString();
    String alarmtype = (jsonObject.get("alarmtype") == null) ? null : jsonObject.get("alarmtype").toString();
    String alarmacktime = (jsonObject.get("alarmacktime") == null) ? null : jsonObject.get("alarmacktime").toString();
    String alarmackuser = (jsonObject.get("alarmackuser") == null) ? null : jsonObject.get("alarmackuser").toString();
    String suppressedtime = (jsonObject.get("suppressedtime") == null) ? null : jsonObject.get("suppressedtime").toString();
    String suppresseduntil = (jsonObject.get("suppresseduntil") == null) ? null : jsonObject.get("suppresseduntil").toString();
    String suppresseduser = (jsonObject.get("suppresseduser") == null) ? null : jsonObject.get("suppresseduser").toString();
    // Node / service identity - copy into event corresponding event fields
    String nodeid = (jsonObject.get("nodeid") == null) ? null : jsonObject.get("nodeid").toString();
    String ipaddr = (jsonObject.get("ipaddr") == null) ? null : jsonObject.get("ipaddr").toString();
    String ifindex = (jsonObject.get("ifindex") == null) ? null : jsonObject.get("ifindex").toString();
    String applicationdn = (jsonObject.get("applicationdn") == null) ? null : jsonObject.get("applicationdn").toString();
    String serviceid = (jsonObject.get("serviceid") == null) ? null : jsonObject.get("serviceid").toString();
    String systemid = (jsonObject.get("systemid") == null) ? null : jsonObject.get("systemid").toString();
    eb.addParam(AlarmChangeEventConstants.ALARMID_PARAM, alarmId);
    eb.addParam(AlarmChangeEventConstants.ALARM_SEVERITY_PARAM, severity);
    eb.addParam(AlarmChangeEventConstants.LOGMSG_PARAM, logmsg);
    eb.addParam(AlarmChangeEventConstants.CLEARKEY_PARAM, clearkey);
    eb.addParam(AlarmChangeEventConstants.ALARMTYPE_PARAM, alarmtype);
    eb.addParam(AlarmChangeEventConstants.ALARM_ACK_TIME_PARAM, alarmacktime);
    eb.addParam(AlarmChangeEventConstants.ALARM_ACK_USER_PARAM, alarmackuser);
    eb.addParam(AlarmChangeEventConstants.SUPPRESSEDTIME_PARAM, suppressedtime);
    eb.addParam(AlarmChangeEventConstants.SUPPRESSEDUNTIL_PARAM, suppresseduntil);
    eb.addParam(AlarmChangeEventConstants.SUPPRESSEDUSER_PARAM, suppresseduser);
    eb.addParam(AlarmChangeEventConstants.EVENTUEI_PARAM, eventuei);
    eb.addParam(AlarmChangeEventConstants.REDUCTIONKEY_PARAM, reductionkey);
    if (nodeid != null)
        eb.setNodeid(Long.parseLong(nodeid));
    if (ipaddr != null)
        try {
            IPAddress ipaddress = new IPAddress(ipaddr);
            eb.setInterface(ipaddress.toInetAddress());
        } catch (Exception e) {
            LOG.error("cannot parse json object ipaddr=" + ipaddr, e);
        }
    if (ifindex != null)
        eb.setIfIndex(Integer.parseInt(ifindex));
    eb.addParam(AlarmChangeEventConstants.APPLICATIONDN_PARAM, applicationdn);
    eb.addParam(AlarmChangeEventConstants.SERVICEID_PARAM, serviceid);
    eb.addParam(AlarmChangeEventConstants.SYSTEMID_PARAM, systemid);
    return eb;
}
Also used : IPAddress(org.opennms.core.network.IPAddress) ParseException(org.json.simple.parser.ParseException) EventProxyException(org.opennms.netmgt.events.api.EventProxyException)

Example 12 with IPAddress

use of org.opennms.core.network.IPAddress in project opennms by OpenNMS.

the class Package method hasIncludeRange.

public boolean hasIncludeRange(final String addr) {
    if (getIncludeRanges().size() == 0 && getSpecifics().size() == 0) {
        return true;
    }
    final IPAddress ipAddr = new IPAddress(addr);
    for (final IncludeRange rng : getIncludeRanges()) {
        final IPAddress begin = rng.getBeginAsAddress();
        final IPAddress end = rng.getEndAsAddress();
        if (ipAddr.isGreaterThanOrEqualTo(begin) && ipAddr.isLessThanOrEqualTo(end)) {
            return true;
        }
    }
    return false;
}
Also used : IPAddress(org.opennms.core.network.IPAddress)

Aggregations

IPAddress (org.opennms.core.network.IPAddress)12 Test (org.junit.Test)4 IPAddressRange (org.opennms.core.network.IPAddressRange)2 BigInteger (java.math.BigInteger)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParseException (org.json.simple.parser.ParseException)1 Parameters (org.junit.runners.Parameterized.Parameters)1 SnmpEventInfo (org.opennms.netmgt.config.SnmpEventInfo)1 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)1 Specific (org.opennms.netmgt.config.discovery.Specific)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)1