1 22 package org.jboss.console.plugins; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import javax.management.MBeanServer ; 29 import javax.management.ObjectName ; 30 31 import org.jboss.console.manager.interfaces.ManageableResource; 32 import org.jboss.console.manager.interfaces.TreeNode; 33 import org.jboss.console.plugins.helpers.AbstractPluginWrapper; 34 import org.jboss.monitor.services.ActiveAlarmTableMBean; 35 import org.jboss.mx.util.InstanceOfQueryExp; 36 44 public class MonitorLister 45 extends AbstractPluginWrapper 46 { 47 public MonitorLister () { super(); } 48 49 private TreeNode[] createMonitorSubNodes () throws Exception 50 { 51 MBeanServer mbeanServer = getMBeanServer(); 52 InstanceOfQueryExp queryExp = null; 53 queryExp = new InstanceOfQueryExp("org.jboss.monitor.JBossMonitorMBean"); 54 Set monitors = mbeanServer.queryNames(null, queryExp); 55 Iterator mbeans = monitors.iterator();; 56 57 TreeNode[] result = null; 58 59 ArrayList monitorNodes = new ArrayList (); 60 61 String emptySig[] = {}; 62 Object emptyArgs[] = {}; 63 while( mbeans.hasNext() ) 64 { 65 ObjectName mbean = (ObjectName )mbeans.next(); 66 String monitorName = (String )mbeanServer.getAttribute(mbean, "MonitorName"); 67 boolean alerted = ((Boolean )mbeanServer.invoke(mbean, "alerted", emptyArgs, emptySig)).booleanValue(); 68 String image = "images/service.gif"; 70 Object [] args = {"monitors", monitorName, "-service.xml"}; 71 String [] signature = {"java.lang.String", "java.lang.String", "java.lang.String"}; 72 Object rtn = mbeanServer.invoke(new ObjectName ("jboss.admin:service=DeploymentFileRepository"), "isStored", args, signature); 73 boolean persisted = ((Boolean )rtn).booleanValue(); 74 String url = ""; 75 if (persisted) 76 { 77 url = "manageThresholdMonitor.jsp?monitorObjectName=" + encode(mbean.toString()); 78 } 79 else 80 { 81 url = "/jmx-console/HtmlAdaptor?action=inspectMBean&name=" +encode(mbean.toString()); 82 } 83 monitorNodes.add(createTreeNode ( 84 monitorName, "Alert Monitor " + monitorName, image, url, null, null, null ) 92 ); 93 94 } 95 96 if (monitorNodes.size() == 0) 97 { 98 result = null; 99 } 100 else 101 { 102 result = (TreeNode[]) monitorNodes.toArray(new TreeNode[monitorNodes.size()]); 103 } 104 105 return result; 106 } 107 108 private TreeNode[] createSnapshotSubNodes() throws Exception 109 { 110 MBeanServer mbeanServer = getMBeanServer(); 111 InstanceOfQueryExp queryExp = null; 112 queryExp = new InstanceOfQueryExp("org.jboss.monitor.SnapshotRecordingMonitorMBean"); 113 Set monitors = mbeanServer.queryNames(null, queryExp); 114 Iterator mbeans = monitors.iterator();; 115 116 TreeNode[] result = null; 117 118 ArrayList monitorNodes = new ArrayList (); 119 120 while( mbeans.hasNext() ) 121 { 122 ObjectName mbean = (ObjectName )mbeans.next(); 123 String monitorName = (String )mbeanServer.getAttribute(mbean, "MonitorName"); 124 String url = "manageSnapshot.jsp?monitorObjectName=" + encode(mbean.toString()); 125 String image = "images/service.gif"; 126 monitorNodes.add(createTreeNode ( 127 monitorName, "Snapshot " + monitorName, image, url, null, null, null ) 135 ); 136 137 } 138 139 if (monitorNodes.size() == 0) 140 { 141 result = null; 142 } 143 else 144 { 145 result = (TreeNode[]) monitorNodes.toArray(new TreeNode[monitorNodes.size()]); 146 } 147 148 return result; 149 } 150 151 private TreeNode[] createWebSubNodes() throws Exception 152 { 153 TreeNode[] webSubNodes = new TreeNode[2]; 154 155 webSubNodes[0] = createTreeNode( 156 "Connector scoreboard", "JBossWeb Connectors status scoreboard", "images/smallnet.gif", "status", null, 161 null, null ); 164 webSubNodes[1] = createTreeNode( 165 "Full status", "JBossWeb complete status", "images/smallnet.gif", "status?full=true", null, 170 null, null ); 173 174 return webSubNodes; 175 } 176 177 protected TreeNode getTreeForResource(String profile, ManageableResource resource) 178 { 179 try 180 { 181 ArrayList subNodeList = new ArrayList (); 182 183 if (isActiveAlarmTablePresent()) 184 { 185 subNodeList.add(createTreeNode( 186 "Alarm Table", "Alarm Table", "images/smallnet.gif", "listActiveAlarmTable.jsp", null, 191 null, null )); 194 } 195 196 subNodeList.add(createTreeNode( 197 "Monitor Alerts", "Monitor Alerts", "images/smallnet.gif", "listMonitors.jsp", null, 202 createMonitorSubNodes(), null )); 205 206 subNodeList.add(createTreeNode( 207 "Snapshots", "Snapshot Monitors", "images/smallnet.gif", null, null, 212 createSnapshotSubNodes(), null )); 215 216 subNodeList.add(createTreeNode( 217 "Web Status", "JBossWeb Connectors status", "images/smallnet.gif", null, null, 222 createWebSubNodes(), null )); 225 226 TreeNode[] subnodes = (TreeNode[]) subNodeList.toArray(new TreeNode[subNodeList.size()]); 228 229 return createTreeNode ( 230 "Monitoring", "Monitoring", "images/smallnet.gif", null, null, 235 subnodes, null ); 238 } 239 catch (Exception e) 240 { 241 e.printStackTrace (); 242 return null; 243 } 244 } 245 246 private boolean isActiveAlarmTablePresent() 247 { 248 MBeanServer server = getMBeanServer(); 249 return server.isRegistered(ActiveAlarmTableMBean.OBJECT_NAME); 250 } 251 } 252 | Popular Tags |