[jboss-user] [Management, JMX/JBoss] - Re: Problem with monitoring and notifications
fgeymonat
do-not-reply at jboss.com
Wed Feb 14 12:27:39 EST 2007
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 at 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();
| }
|
| }
|
|
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4016480#4016480
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4016480
More information about the jboss-user
mailing list