1 22 package org.jboss.console.plugins.monitor; 23 24 import org.jboss.monitor.ThresholdMonitor; 25 import org.jboss.mx.util.MBeanServerLocator; 26 import org.jboss.mx.util.InstanceOfQueryExp; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MalformedObjectNameException ; 30 import javax.management.ObjectName ; 31 import javax.servlet.ServletException ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 import java.io.IOException ; 35 import java.util.ArrayList ; 36 import java.util.Set ; 37 import java.util.Iterator ; 38 39 46 public class ClearMonitorAlertsServlet extends javax.servlet.http.HttpServlet 47 { 48 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 49 throws ServletException , IOException 50 { 51 doit(req, resp); 52 } 53 54 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 55 throws ServletException , IOException 56 { 57 doit(req, resp); 58 } 59 60 protected void doit(HttpServletRequest req, HttpServletResponse resp) 61 throws ServletException , IOException 62 { 63 try 64 { 65 MBeanServer mbeanServer = MBeanServerLocator.locateJBoss(); 66 InstanceOfQueryExp queryExp = null; 67 queryExp = new InstanceOfQueryExp("org.jboss.monitor.JBossMonitorMBean"); 68 Set monitors = mbeanServer.queryNames(null, queryExp); 69 Iterator mbeans = monitors.iterator(); 70 while (mbeans.hasNext()) 71 { 72 ObjectName moname = (ObjectName ) mbeans.next(); 73 Object [] nullArgs = {}; 74 String [] nullSig = {}; 75 boolean alerted = ((Boolean ) mbeanServer.invoke(moname, "alerted", nullArgs, nullSig)).booleanValue(); 76 if (alerted) 77 { 78 mbeanServer.invoke(moname, "clearAlert", nullArgs, nullSig); 79 } 80 } 81 } 82 catch (Exception ex) 83 { 84 req.setAttribute("error", "Error clearing alerts: " + ex.toString()); 85 } 86 req.getRequestDispatcher("/listMonitors.jsp").forward(req, resp); 87 } 88 89 } 90 | Popular Tags |