-
1. Re: Problem with monitoring and notifications
bhuste1 Aug 9, 2006 2:08 PM (in response to jean_yves)I am experiencing the exact same problem. Have you had any luck working around this problem?
-
2. Re: Problem with monitoring and notifications
pilhuhn Aug 9, 2006 3:54 PM (in response to jean_yves)The code only sends one alert and then stalls. Only when you (manually) call clearAlert(), it will send another.
Actually this behaviour should perhaps be configurable (submit an entry into JIRA), but prevents you from being spammed by alerts, which is a good idea. -
3. Re: Problem with monitoring and notifications
bhuste1 Aug 10, 2006 9:38 AM (in response to jean_yves)Only when you (manually) call clearAlert(), it will send another.
What object exposes a clearAlert method? I was able to take the code from the web-console using the mbean servers invoke() method and clear the alert--is this the best approach? -
4. Re: Problem with monitoring and notifications
fgeymonat Feb 14, 2007 12:27 PM (in response to jean_yves)I have experienced the same problem, and i solve it modifying the EmailAlertListener adding the necesary code for manually clear the alerts.
Next i copy the code to you./* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.monitor.alerts; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import javax.mail.Address; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.management.MBeanServer; import javax.management.Notification; import javax.management.ObjectName; import javax.naming.InitialContext; import org.jboss.monitor.JBossMonitorNotification; import org.jboss.monitor.alerts.JBossAlertListener; import org.jboss.mx.util.InstanceOfQueryExp; import org.jboss.mx.util.MBeanServerLocator; import org.jboss.util.Strings; /** * Comment * * @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @version $Revision: 1.3 $ * **/ public class EmailAlertListener extends JBossAlertListener implements EmailAlertListenerMBean { protected String messageTemplate; protected String subjectTemplate; protected String fromString; protected Address from; protected String replyToString; protected Address replyTo; protected Address[] to; protected HashSet toSet = new HashSet(); public void handleNotification(Notification notification, Object handback) { if (!(notification instanceof JBossMonitorNotification)) return; JBossMonitorNotification jBossNotification = (JBossMonitorNotification) notification; Map substitutions = ((JBossMonitorNotification) notification).substitutionMap(); String message = Strings.subst(messageTemplate, substitutions, "%(", ")"); String subject = Strings.subst(subjectTemplate, substitutions, "%(", ")"); try { Session session = (Session) new InitialContext().lookup("java:/Mail"); // create a message // Address replyToList[] = { replyTo }; Message newMessage = new MimeMessage(session); newMessage.setFrom(from); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.TO, to); newMessage.setSubject(subject); newMessage.setSentDate(new java.util.Date()); newMessage.setText(message); // Send newMessage // Transport transport = session.getTransport(); transport.connect(); transport.sendMessage(newMessage, to); // Cleans the alert...jejeje... // MBeanServer mbeanServer = MBeanServerLocator.locateJBoss(); InstanceOfQueryExp queryExp = null; queryExp = new InstanceOfQueryExp("org.jboss.monitor.JBossMonitorMBean"); Set monitors = mbeanServer.queryNames(null, queryExp); Iterator mbeans = monitors.iterator(); while (mbeans.hasNext()) { ObjectName monitorObjectName = (ObjectName)mbeans.next(); String monitorName = (String)mbeanServer.getAttribute(monitorObjectName, "MonitorName"); Object[] nullArgs = {}; String[] nullSignature = {}; log.debug("Verifying status for monitor: " + monitorName.toString()); boolean alerted = ((Boolean)mbeanServer.invoke(monitorObjectName, "alerted", nullArgs, nullSignature)).booleanValue(); if (monitorName.equals(jBossNotification.getMonitorName()) && alerted) { try { log.debug("Clearing Alert for monitor: " + monitorName.toString()); mbeanServer.invoke(monitorObjectName, "clearAlert", nullArgs, nullSignature); break; } catch (Exception ex) { log.debug("Failed to Clear Alert: " + monitorName.toString()); ex.printStackTrace(); } } } } catch (Exception ex) { ex.printStackTrace(); } } }
-
5. Re: Problem with monitoring and notifications
fgeymonat Feb 14, 2007 1:54 PM (in response to jean_yves)Another solution that i found was to modify the ThresholdMonitor.java and the StringThresholdMonitor classes.
Only i comment the first line at the method protected void testThreshold() that is //if (alertSent) return;
Its i good solution because it nevers clean the alerts and you can see them at the web-console (and clean of course).
Thanks,
Bye
FG