001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.console.plugins;
023:
024: import java.util.ArrayList;
025: import java.util.Iterator;
026: import java.util.Set;
027:
028: import javax.management.MBeanServer;
029: import javax.management.ObjectName;
030:
031: import org.jboss.console.manager.interfaces.ManageableResource;
032: import org.jboss.console.manager.interfaces.TreeNode;
033: import org.jboss.console.plugins.helpers.AbstractPluginWrapper;
034: import org.jboss.monitor.services.ActiveAlarmTableMBean;
035: import org.jboss.mx.util.InstanceOfQueryExp;
036:
037: /**
038: * As the number of MBeans is very big, we use a real Java class which is far
039: * faster than beanshell
040: *
041: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
042: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>.
043: * @version $Revision: 57191 $
044: */
045: public class MonitorLister extends AbstractPluginWrapper {
046: /** @since 4.0.1 */
047: private static final long serialVersionUID = 1625760520837838058L;
048:
049: public MonitorLister() {
050: super ();
051: }
052:
053: private TreeNode[] createMonitorSubNodes() throws Exception {
054: MBeanServer mbeanServer = getMBeanServer();
055: InstanceOfQueryExp queryExp = null;
056: queryExp = new InstanceOfQueryExp(
057: "org.jboss.monitor.JBossMonitorMBean");
058: Set monitors = mbeanServer.queryNames(null, queryExp);
059: Iterator mbeans = monitors.iterator();
060: ;
061:
062: TreeNode[] result = null;
063:
064: ArrayList monitorNodes = new ArrayList();
065:
066: String emptySig[] = {};
067: Object emptyArgs[] = {};
068: while (mbeans.hasNext()) {
069: ObjectName mbean = (ObjectName) mbeans.next();
070: String monitorName = (String) mbeanServer.getAttribute(
071: mbean, "MonitorName");
072: boolean alerted = ((Boolean) mbeanServer.invoke(mbean,
073: "alerted", emptyArgs, emptySig)).booleanValue();
074: //String image = alerted ? "images/red_bullet.gif" : "images/green_bullet.gif";
075: String image = "images/service.gif";
076: Object[] args = { "monitors", monitorName, "-service.xml" };
077: String[] signature = { "java.lang.String",
078: "java.lang.String", "java.lang.String" };
079: Object rtn = mbeanServer.invoke(new ObjectName(
080: "jboss.admin:service=DeploymentFileRepository"),
081: "isStored", args, signature);
082: boolean persisted = ((Boolean) rtn).booleanValue();
083: String url = "";
084: if (persisted) {
085: url = "manageThresholdMonitor.jsp?monitorObjectName="
086: + encode(mbean.toString());
087: } else {
088: url = "/jmx-console/HtmlAdaptor?action=inspectMBean&name="
089: + encode(mbean.toString());
090: }
091: monitorNodes.add(createTreeNode(monitorName, // name
092: "Alert Monitor " + monitorName, // description
093: image, // Icon URL
094: url, // Default URL
095: null, // menu
096: null, // sub nodes
097: null // Sub-Resources
098: ));
099:
100: }
101:
102: if (monitorNodes.size() == 0) {
103: result = null;
104: } else {
105: result = (TreeNode[]) monitorNodes
106: .toArray(new TreeNode[monitorNodes.size()]);
107: }
108:
109: return result;
110: }
111:
112: private TreeNode[] createSnapshotSubNodes() throws Exception {
113: MBeanServer mbeanServer = getMBeanServer();
114: InstanceOfQueryExp queryExp = null;
115: queryExp = new InstanceOfQueryExp(
116: "org.jboss.monitor.SnapshotRecordingMonitorMBean");
117: Set monitors = mbeanServer.queryNames(null, queryExp);
118: Iterator mbeans = monitors.iterator();
119: ;
120:
121: TreeNode[] result = null;
122:
123: ArrayList monitorNodes = new ArrayList();
124:
125: while (mbeans.hasNext()) {
126: ObjectName mbean = (ObjectName) mbeans.next();
127: String monitorName = (String) mbeanServer.getAttribute(
128: mbean, "MonitorName");
129: String url = "manageSnapshot.jsp?monitorObjectName="
130: + encode(mbean.toString());
131: String image = "images/service.gif";
132: monitorNodes.add(createTreeNode(monitorName, // name
133: "Snapshot " + monitorName, // description
134: image, // Icon URL
135: url, // Default URL
136: null, // menu
137: null, // sub nodes
138: null // Sub-Resources
139: ));
140:
141: }
142:
143: if (monitorNodes.size() == 0) {
144: result = null;
145: } else {
146: result = (TreeNode[]) monitorNodes
147: .toArray(new TreeNode[monitorNodes.size()]);
148: }
149:
150: return result;
151: }
152:
153: private TreeNode[] createWebSubNodes() throws Exception {
154: TreeNode[] webSubNodes = new TreeNode[2];
155:
156: webSubNodes[0] = createTreeNode("Connector scoreboard", // name
157: "JBossWeb Connectors status scoreboard", // description
158: "images/smallnet.gif", // Icon URL
159: "status", // Default URL
160: null, null, // sub nodes
161: null // Sub-Resources
162: );
163: webSubNodes[1] = createTreeNode("Full status", // name
164: "JBossWeb complete status", // description
165: "images/smallnet.gif", // Icon URL
166: "status?full=true", // Default URL
167: null, null, // sub nodes
168: null // Sub-Resources
169: );
170:
171: return webSubNodes;
172: }
173:
174: protected TreeNode getTreeForResource(String profile,
175: ManageableResource resource) {
176: try {
177: ArrayList subNodeList = new ArrayList();
178:
179: if (isActiveAlarmTablePresent()) {
180: subNodeList.add(createTreeNode("Alarm Table", // name
181: "Alarm Table", // description
182: "images/smallnet.gif", // icon URL
183: "listActiveAlarmTable.jsp", // default URL
184: null, null, // sub-nodes
185: null // sub-resources
186: ));
187: }
188:
189: subNodeList.add(createTreeNode("Monitor Alerts", // name
190: "Monitor Alerts", // description
191: "images/smallnet.gif", // Icon URL
192: "listMonitors.jsp", // Default URL
193: null, createMonitorSubNodes(), // sub nodes
194: null // Sub-Resources
195: ));
196:
197: subNodeList.add(createTreeNode("Snapshots", // name
198: "Snapshot Monitors", // description
199: "images/smallnet.gif", // Icon URL
200: null, // Default URL
201: null, createSnapshotSubNodes(), // sub nodes
202: null // Sub-Resources
203: ));
204:
205: subNodeList.add(createTreeNode("Web Status", // name
206: "JBossWeb Connectors status", // description
207: "images/smallnet.gif", // Icon URL
208: null, // Default URL
209: null, createWebSubNodes(), // sub nodes
210: null // Sub-Resources
211: ));
212:
213: // convert ArrayList to TreeNode[]
214: TreeNode[] subnodes = (TreeNode[]) subNodeList
215: .toArray(new TreeNode[subNodeList.size()]);
216:
217: return createTreeNode("Monitoring", // name
218: "Monitoring", // description
219: "images/smallnet.gif", // Icon URL
220: null, // Default URL
221: null, subnodes, // sub nodes
222: null // Sub-Resources
223: );
224: } catch (Exception e) {
225: e.printStackTrace();
226: return null;
227: }
228: }
229:
230: private boolean isActiveAlarmTablePresent() {
231: MBeanServer server = getMBeanServer();
232: return server.isRegistered(ActiveAlarmTableMBean.OBJECT_NAME);
233: }
234: }
|