Index: src/services/org/opennms/netmgt/config/NotificationManager.java =================================================================== RCS file: /cvsroot/opennms/opennms/src/services/org/opennms/netmgt/config/NotificationManager.java,v retrieving revision 1.13.2.4 diff -u -r1.13.2.4 NotificationManager.java --- src/services/org/opennms/netmgt/config/NotificationManager.java 3 Aug 2005 22:12:27 -0000 1.13.2.4 +++ src/services/org/opennms/netmgt/config/NotificationManager.java 15 Nov 2005 17:47:56 -0000 @@ -66,6 +66,9 @@ import org.opennms.netmgt.utils.RowProcessor; import org.opennms.netmgt.utils.SingleResultQuerier; import org.opennms.netmgt.xml.event.Event; +import org.opennms.netmgt.xml.event.Parm; +import org.opennms.netmgt.xml.event.Parms; +import org.opennms.netmgt.xml.event.Value; /** * @author David Hustace @@ -115,14 +118,21 @@ public boolean hasUei(String uei) throws IOException, MarshalException, ValidationException { update(); - + + Category log = ThreadCategory.getInstance(getClass()); + for (Enumeration e = m_notifications.enumerateNotification(); e.hasMoreElements();) { Notification notif = (Notification) e.nextElement(); - + log.debug("hasUei: Checking UEI " + uei + " against " + notif.getUei()); + if (uei.equals(notif.getUei()) || "MATCH-ANY-UEI".equals(notif.getUei())) { return true; + } else if (notif.getUei().charAt(0) == '~') { + if (uei.matches(notif.getUei().substring(1))) { + return true; + } } - } + } return false; } @@ -137,8 +147,32 @@ for (Enumeration e = m_notifications.enumerateNotification(); e.hasMoreElements();) { Notification curNotif = (Notification) e.nextElement(); - - if (curNotif.getStatus().equals("on") && (event.getUei().equals(curNotif.getUei()) || "MATCH-ANY-UEI".equals(curNotif.getUei())) && nodeInterfaceServiceValid(curNotif, event)) { + + boolean curHasUei = false; + boolean curHasSeverity = false; + + log.debug("Checking " + event.getUei() + " against " + curNotif.getUei()); + + if (event.getUei().equals(curNotif.getUei()) || "MATCH-ANY-UEI".equals(curNotif.getUei())) { + curHasUei = true; + } else if (curNotif.getUei().charAt(0) == '~') { + if (event.getUei().matches(curNotif.getUei().substring(1))) { + curHasUei = true; + } + } + + /** + * Check if event severity matches pattern in notification + */ + log.debug("Checking event severity: " + event.getSeverity() + " against notification severity: " + curNotif.getEventSeverity()); + // parameter is optional, return true if not set + if (curNotif.getEventSeverity() == null) { + curHasSeverity = true; + } else if (event.getSeverity().toLowerCase().matches(curNotif.getEventSeverity().toLowerCase())) { + curHasSeverity = true; + } + + if (curNotif.getStatus().equals("on") && curHasUei && curHasSeverity && nodeInterfaceServiceValid(curNotif, event)) { boolean parmsmatched = getConfigManager().matchNotificationParameters(event, curNotif); @@ -370,25 +404,43 @@ connection = getConnection(); int eventID = 0; boolean wasAcked = false; - StringBuffer sql = new StringBuffer("SELECT eventid FROM notifications WHERE eventuei=? "); + StringBuffer sql = new StringBuffer("SELECT n.eventid AS eventid FROM notifications n, events e WHERE n.eventid = e.eventid AND n.eventuei=? "); for (int i = 0; i < matchList.length; i++) { - sql.append("AND ").append(matchList[i]).append("=? "); + if (matchList[i].equals("nodeid") | matchList[i].equals("interfaceid") | matchList[i].equals("serviceid") ) { + sql.append("AND n.").append(matchList[i]).append("=? "); + } else { + sql.append("AND e.eventparms LIKE ? "); + } } sql.append("ORDER BY eventid desc limit 1"); + log.debug("Executing " + sql.toString() ); PreparedStatement statement = connection.prepareStatement(sql.toString()); statement.setString(1, uei); for (int i = 0; i < matchList.length; i++) { if (matchList[i].equals("nodeid")) { statement.setLong(i + 2, event.getNodeid()); - } - - if (matchList[i].equals("interfaceid")) { + } else if (matchList[i].equals("interfaceid")) { statement.setString(i + 2, event.getInterface()); - } - - if (matchList[i].equals("serviceid")) { + } else if (matchList[i].equals("serviceid")) { statement.setInt(i + 2, getServiceId(event.getService())); + } else { + Parms parms = event.getParms(); + String parmName = null; + Value parmValue = null; + String parmContent = null; + Enumeration parmEnum = parms.enumerateParm(); + while (parmEnum.hasMoreElements()) { + Parm parm = (Parm) parmEnum.nextElement(); + parmName = parm.getParmName(); + parmValue = parm.getValue(); + if (parmValue == null) + continue; + else if(parmName.equals(matchList[i])) { + parmContent = parmValue.getContent(); + statement.setString(i + 2, "%" + matchList[i] + "=" + parmContent + "%" ); + } + } } } Index: src/services/org/opennms/netmgt/config/notifications.xsd =================================================================== RCS file: /cvsroot/opennms/opennms/src/services/org/opennms/netmgt/config/notifications.xsd,v retrieving revision 1.2 diff -u -r1.2 notifications.xsd --- src/services/org/opennms/netmgt/config/notifications.xsd 26 Aug 2004 23:03:31 -0000 1.2 +++ src/services/org/opennms/netmgt/config/notifications.xsd 15 Nov 2005 17:47:56 -0000 @@ -35,6 +35,7 @@ +