private List getSegmentServices(Statement stmt, String instance) throws SQLException { List rtn = new ArrayList(); ResultSet rs = null; try { // Discover tables rs = stmt.executeQuery(SEGMENT_QUERY); int segment_col = rs.findColumn("SEGMENT_NAME"); int ts_col = rs.findColumn("TABLESPACE_NAME"); while (rs.next()) { String segment = rs.getString(segment_col); String tablespace = rs.getString(ts_col); ServiceResource service = new ServiceResource(); service.setType(this, SEGMENT); service.setServiceName(segment); service.setDescription("Segment in the " + instance + " database instance"); ConfigResponse productConfig = new ConfigResponse(); ConfigResponse metricConfig = new ConfigResponse(); productConfig.setValue(OracleMeasurementPlugin.PROP_SEGMENT, segment); productConfig.setValue(OracleMeasurementPlugin.PROP_TABLESPACE, tablespace); service.setProductConfig(productConfig); service.setMeasurementConfig(metricConfig); service.setControlConfig(); rtn.add(service); } } finally { DBUtil.closeResultSet(log, rs); } return rtn; }
private ServerResource getOracleServer(OracleInfo oracle) throws PluginException { log.debug("[getOracleServer] oracle=" + oracle); String version = getTypeInfo().getVersion(); ConfigResponse cprop = new ConfigResponse(); cprop.setValue("version", version); ConfigResponse productConfig = new ConfigResponse(); setListeningPorts(productConfig); productConfig.setValue( "jdbcUrl", "jdbc:oracle:thin:@" + oracle.host + ":" + oracle.port + ":" + oracle.sid); ServerResource oracleServer = createServerResource(oracle.home); oracleServer.setIdentifier(oracle.home); setCustomProperties(oracleServer, cprop); setProductConfig(oracleServer, productConfig); oracleServer.setMeasurementConfig(); if (!version.equals(VERSION_9i) && !version.equals(VERSION_8i)) { oracleServer.setControlConfig(); } // HHQ-3577 allow listener names in tnsnames.ora to be used in the url String fs = File.separator; String tnsDir = getTnsNamesDir(oracle.home, "network" + fs + "admin" + fs + "tnsnames.ora"); if (log.isDebugEnabled()) { log.debug("[getOracleServer] using tns dir as " + tnsDir); } System.setProperty("oracle.net.tns_admin", tnsDir); return oracleServer; }
private void storeProcessUserAndGroup(MxProcess process, ConfigResponse config) throws InvalidOptionException, InvalidOptionValueException, PluginException { String user = null; String group = null; try { ProcCredName procCredName = getSigar().getProcCredName(process.getPid()); user = procCredName.getUser(); group = procCredName.getGroup(); } catch (SigarException se) { logger.warn("Failed to get proc cred names for tc Server process " + process.getPid()); if (logger.isDebugEnabled()) { logger.debug(se); } ProcCred procCred; try { procCred = getSigar().getProcCred(process.getPid()); user = String.valueOf(procCred.getUid()); group = String.valueOf(procCred.getGid()); } catch (SigarException e) { logger.warn("Failed to get proc cred for tc Server process " + process.getPid()); } } finally { logger.info( "Using " + user + "/" + group + " as the user/group for tc Runtime instance process with pid: " + process.getPid()); } config.setValue(Utils.SERVER_RESOURCE_CONFIG_PROCESS_USERNAME, user); config.setValue(Utils.SERVER_RESOURCE_CONFIG_PROCESS_GROUP, group); }
final ConfigResponse getAtributtes(Map memberDetails) { ConfigResponse res = new ConfigResponse(); res.setValue("id", (String) memberDetails.get("gemfire.member.id.string")); res.setValue("type", (String) memberDetails.get("gemfire.member.type.string")); res.setValue("host", (String) memberDetails.get("gemfire.member.host.string")); res.setValue("port", (Integer) memberDetails.get("gemfire.member.port.int")); return res; }
protected boolean configureURL(ApacheBinaryInfo binary, ConfigResponse config) { String port = null, address = null; if (binary.conf != null) { // XXX config parsing not complete Map cfg = ApacheBinaryInfo.parseConfig(binary.conf); String listen = (String) cfg.get("Listen"); if (listen != null) { int ix = listen.lastIndexOf(':'); if (ix == -1) { port = listen; address = (String) cfg.get("ServerName"); if (address != null) { ix = address.indexOf(':'); if (ix != -1) { address = address.substring(0, ix); } } } else { address = listen.substring(0, ix); port = listen.substring(ix + 1); } } setConfigTrack(config, binary.conf); String root = (String) cfg.get("ServerRoot"); if (root != null) { binary.root = root; } String log = (String) cfg.get("ErrorLog"); if (binary.serverRootRelative(log).exists()) { setLogTrack(config, log); } String pid = (String) cfg.get("PidFile"); if (pid != null) { File pidFile = binary.serverRootRelative(pid); if (pidFile.exists()) { setPidFile(config, pidFile.getPath()); } } } if (port == null) { port = getConfigProperty(Collector.PROP_PORT, "80"); } if (address == null) { address = getListenAddress(port, this.defaultIp); } config.setValue(Collector.PROP_PROTOCOL, getConnectionProtocol(port)); config.setValue(Collector.PROP_SSL, isSSL(port)); config.setValue(Collector.PROP_HOSTNAME, address); config.setValue(Collector.PROP_PORT, port); config.setValue(Collector.PROP_PATH, getConfigProperty(Collector.PROP_PATH, "/server-status")); return true; }
private List getTnsServices(ConfigResponse config) { String line; BufferedReader reader = null; String tnsnames = config.getValue(PROP_TNSNAMES), installpath = config.getValue(ProductPlugin.PROP_INSTALLPATH); List rtn = new ArrayList(); try { String fs = File.separator; if (log.isDebugEnabled()) { log.debug("READING tnsnames.ora FILE: " + installpath + fs + tnsnames); } reader = new BufferedReader(new FileReader(installpath + fs + tnsnames)); while (null != (line = reader.readLine())) { if (_serviceNameEx.matcher(line).find()) { String[] toks = line.split("="); if (toks[1] == null) continue; String tnslistener = toks[1].replaceAll("\\s*\\)", "").trim(); if (log.isDebugEnabled()) log.debug("Configuring TNS Listener " + tnslistener); ServiceResource service = new ServiceResource(); service.setType(this, "TNS Ping"); service.setServiceName(tnslistener + " TNS Ping"); ConfigResponse productConfig = new ConfigResponse(); productConfig.setValue("tnslistener", tnslistener); service.setProductConfig(productConfig); service.setMeasurementConfig(); rtn.add(service); } } } catch (IOException e) { log.error("Error reading " + tnsnames); } finally { close(reader); } return rtn; }
/** * Function creates Service Resource. * * @param serviceDescriptorName * @param serviceName * @return */ private ServiceResource getService(String serviceDescriptorName, String servicePtql) { ServiceResource service = createServiceResource(serviceDescriptorName); service.setName(serviceDescriptorName); ConfigResponse productConfig = new ConfigResponse(); productConfig.setValue(PROCESS_QUERY, servicePtql); setProductConfig(service, productConfig); setMeasurementConfig(service, new ConfigResponse()); return service; }
private List getUserServices(Statement stmt, String instance) throws SQLException { // Discover the user instances, for user instances to be // discovered, the user must be connected to the database. List rtn = new ArrayList(); ResultSet rs = null; try { // Set server description setDescription("Oracle " + instance + " database instance"); // Discover user instances ArrayList users = new ArrayList(); rs = stmt.executeQuery(USER_QUERY); while (rs.next()) { String username = rs.getString(1); users.add(username); } rs.close(); for (int i = 0; i < users.size(); i++) { String username = (String) users.get(i); ServiceResource service = new ServiceResource(); service.setType(this, USER_INSTANCE); service.setServiceName(username); service.setDescription("User of the " + instance + " database instance"); ConfigResponse productConfig = new ConfigResponse(); ConfigResponse metricConfig = new ConfigResponse(); productConfig.setValue(OracleMeasurementPlugin.PROP_USERNAME, username); service.setProductConfig(productConfig); service.setMeasurementConfig(metricConfig); // Query for service inventory properties rs = stmt.executeQuery(DBA_USER_QUERY + "'" + username + "'"); if (rs != null && rs.next()) { ConfigResponse svcProps = new ConfigResponse(); svcProps.setValue("status", rs.getString("ACCOUNT_STATUS")); svcProps.setValue("default_tablespace", rs.getString("DEFAULT_TABLESPACE")); svcProps.setValue("temp_tablespace", rs.getString("TEMPORARY_TABLESPACE")); service.setCustomProperties(svcProps); } rtn.add(service); } } finally { DBUtil.closeResultSet(log, rs); } return rtn; }
public void setUp() throws Exception { super.setUp(); this.alertConditionEvaluator = EasyMock.createMock(AlertConditionEvaluator.class); ConfigResponse measurementConfig = new ConfigResponse(); measurementConfig.setValue(ConditionalTriggerInterface.CFG_ID, ALERT_DEFINITION_ID); RegisteredTriggerValue regTrigger = new RegisteredTriggerValue(); regTrigger.setId(TRIGGER_ID); regTrigger.setConfig(measurementConfig.encode()); trigger.init(regTrigger, alertConditionEvaluator); }
private void addTrackConfig(ConfigResponse config) { String[] keys = {LogFileTrackPlugin.PROP_FILES_SERVER, ConfigFileTrackPlugin.PROP_FILES_SERVER}; for (int i = 0; i < keys.length; i++) { if (config.getValue(keys[i]) != null) { continue; } String val = getConfigProperty(keys[i]); if (val != null) { config.setValue(keys[i], val); } } }
private List getTablespaceServices(Statement stmt, String instance) throws SQLException { List rtn = new ArrayList(); ResultSet rs = null; try { // Discover tablespaces rs = stmt.executeQuery(TABLESPACE_QUERY); int ts_col = rs.findColumn("TABLESPACE_NAME"); while (rs.next()) { String tablespace = rs.getString(ts_col); ServiceResource service = new ServiceResource(); service.setType(this, TABLESPACE); service.setServiceName(tablespace); service.setDescription("Tablespace on the " + instance + " database instance"); ConfigResponse productConfig = new ConfigResponse(); ConfigResponse metricConfig = new ConfigResponse(); productConfig.setValue(OracleMeasurementPlugin.PROP_TABLESPACE, tablespace); service.setProductConfig(productConfig); service.setMeasurementConfig(metricConfig); ConfigResponse svcProps = new ConfigResponse(); // 9i and 10g only if (!getTypeInfo().getVersion().equals(VERSION_8i)) { svcProps.setValue("block_size", rs.getString("BLOCK_SIZE")); svcProps.setValue("allocation_type", rs.getString("ALLOCATION_TYPE")); svcProps.setValue("space_management", rs.getString("SEGMENT_SPACE_MANAGEMENT")); } svcProps.setValue("contents", rs.getString("CONTENTS")); svcProps.setValue("logging", rs.getString("LOGGING")); service.setCustomProperties(svcProps); rtn.add(service); } } finally { DBUtil.closeResultSet(log, rs); } return rtn; }
protected List discoverServices(ConfigResponse config) throws PluginException { List<ServiceResource> services = new ArrayList<ServiceResource>(); try { String proto = config.getValue("protocol"); String hostname = config.getValue("hostname"); int port = Integer.parseInt(config.getValue("port")); String path = DEFAULT_BMX_PATH + QUERY_BMX + VHOST_QUERY + "*"; URL bmxUrl = new URL(proto, hostname, port, path); BmxQuery query = new BmxQuery(bmxUrl); BmxResult result = query.getResult(); List<String> names = result.parseForNames(); for (Iterator<String> it = names.iterator(); it.hasNext(); ) { String name = it.next(); String type = getTypeInfo().getName() + " " + VHOST_SERVICE_TYPE; ServiceResource service = new ServiceResource(); String[] ent = name.split(","); if (ent[0].equals("Type=since-start")) { String host = ent[1].split("=")[1]; String servicePort = ent[2].split("=")[1]; path = DEFAULT_BMX_PATH + QUERY_BMX + VHOST_QUERY + name; ConfigResponse cprops = new ConfigResponse(); cprops.setValue("protocol", proto); cprops.setValue("hostname", hostname); cprops.setValue("port", port); cprops.setValue("path", path); service.setProductConfig(cprops); service.setMeasurementConfig(); service.setType(type); service.setServiceName(host + ":" + servicePort); services.add(service); } } } catch (Exception e) { _log.debug("Exception" + e, e); return null; } return services; }
protected boolean configureURL(String urlstr, ConfigResponse config) { if (urlstr == null) { return false; } URL url; try { url = new URL(urlstr); } catch (MalformedURLException e) { log.error("Malformed url=" + urlstr); return false; } config.setValue(Collector.PROP_HOSTNAME, url.getHost()); config.setValue(Collector.PROP_PORT, String.valueOf(url.getPort())); config.setValue(Collector.PROP_PATH, url.getPath()); config.setValue(Collector.PROP_PROTOCOL, Collector.PROTOCOL_HTTP); if (url.getProtocol().equals(Collector.PROTOCOL_HTTPS)) { config.setValue(Collector.PROP_SSL, "true"); } return true; }
/** * Retrieves the listener properties from the server.xml file, then creates the jmx.url based on * the properties. * * @param config The ConfigResponse object. * @param basePath The base file path of the configuration, "/conf/server.xml" is added to this. * @return Whether the configuration was found and set on the config response object. * @throws PluginException */ private boolean configureListenerMxURL(ConfigResponse config, String basePath) throws PluginException { boolean found = false; XmlPropertiesFileRetriever propertiesRetriever = new ServerXmlPropertiesRetriever(); try { Map<String, String> listenerProperties = propertiesRetriever.getPropertiesFromFile( basePath + "/conf/server.xml", "Listener", "className", "com.springsource.tcserver.serviceability.rmi.JmxSocketListener"); if (!listenerProperties.isEmpty()) { String addressProperty = listenerProperties.get("address"); if (addressProperty == null) { addressProperty = listenerProperties.get("bind"); } String bindAddressValue = getValueFromPropertiesFile(basePath, addressProperty); String portValue = getValueFromPropertiesFile(basePath, listenerProperties.get("port")); config.setValue( mxUtil.getJmxUrlProperty(), "service:jmx:rmi:///jndi/rmi://" + bindAddressValue + ":" + portValue + "/jmxrmi"); found = true; } } catch (PluginException e) { // the properties were not accessible config.setValue(mxUtil.getJmxUrlProperty(), DEFAULT_JMX_URL); logger.warn( "Unable to retrieve properties for discovery, using default " + mxUtil.getJmxUrlProperty() + "=" + DEFAULT_JMX_URL); if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } } return found; }
protected List discoverJkServices(ConfigResponse serverConfig) throws PluginException { ConfigResponse config = new ConfigResponse(); // XXX must be defined in agent.properties for now if (!configureURL(getManagerProperty("jkstatus.url"), config)) { return null; } List services = new ArrayList(); JkStatusCollector jkstatus = new JkStatusCollector(); Map stats = jkstatus.getValues(this, config); Set workers = jkstatus.getWorkers(); for (Iterator it = workers.iterator(); it.hasNext(); ) { String name = (String) it.next(); ServiceResource worker = createServiceResource(JkStatusCollector.WORKER_NAME); worker.setServiceName(JkStatusCollector.WORKER_NAME + " " + name); ConfigResponse cprops = new ConfigResponse(); for (int i = 0; i < JkStatusCollector.WORKER_PROPS.length; i++) { String prop = JkStatusCollector.WORKER_PROPS[i]; cprops.setValue(prop, (String) stats.get(name + "." + prop)); } ConfigResponse productConfig = new ConfigResponse(config.toProperties()); // clone productConfig.setValue("name", name); worker.setProductConfig(productConfig); worker.setCustomProperties(cprops); worker.setMeasurementConfig(); services.add(worker); } return services; }
private void setCustomProps(Statement stmt) throws SQLException { ResultSet rs = null; try { // Query for server inventory properties ConfigResponse props = new ConfigResponse(); rs = stmt.executeQuery(VERSION_QUERY); if (rs != null && rs.next()) { String version = rs.getString(1); props.setValue("version", version); } setCustomProperties(props); } finally { DBUtil.closeResultSet(log, rs); } }
private List getProcessServices(ConfigResponse config) { List rtn = new ArrayList(); String ptql = config.getValue(PROP_PROC_PTQL); if (log.isDebugEnabled()) log.debug("using ptql, " + ptql + ", to retrieve processes"); List processes = getProcesses(ptql); for (Iterator i = processes.iterator(); i.hasNext(); ) { String process = (String) i.next(); if (log.isDebugEnabled()) log.debug("adding Process Metrics " + process + " service"); ServiceResource service = new ServiceResource(); service.setType(this, "Process Metrics"); service.setServiceName(process + " process"); ConfigResponse productConfig = new ConfigResponse(); ptql = "State.Name.eq=oracle,Args.0.sw=" + process; productConfig.setValue("process.query", ptql); service.setProductConfig(productConfig); service.setMeasurementConfig(); rtn.add(service); } return rtn; }
/** * Function creates Server Resources by providing static install path & PTQL for Server * Availability. */ @Override public List getServerResources(ConfigResponse platformConfig) throws PluginException { List servers = new ArrayList(); String neutronService = getAvailableNeutronService(); logger.debug("Neutron Server monitoring PTQL:" + neutronService); // Server Resources created if one of monitored process is available. if (neutronService != null) { ServerResource server = createServerResource(NEUTRON_INSTALL_PATH); // server.setName(server.getName()); String platformName = getPlatformName(server.getName()); server.setName(platformName + NEUTRON_CONTROLLER_SERVER); ConfigResponse productConfig = new ConfigResponse(); productConfig.setValue(PROCESS_QUERY, neutronService); setProductConfig(server, productConfig); setMeasurementConfig(server, new ConfigResponse()); servers.add(server); } return servers; }
protected List discoverVHostServices(ConfigResponse serverConfig) throws PluginException { getLog().debug("[discoverVHostServices] serverConfig=" + serverConfig); if (serverConfig.getValue(SNMPClient.PROP_IP) == null) { return null; // server type "Apache httpd" } Map<String, ApacheVHost> vHosts; ApacheConf aConf; try { File ServerConf = new File(serverConfig.getValue("ServerConf")); aConf = new ApacheConf(ServerConf); vHosts = aConf.getVHosts(); } catch (IOException ex) { throw new PluginException("Error getting VHosts", ex); } ApacheSNMP snmp = new ApacheSNMP(); List servers; try { servers = snmp.getServers(serverConfig); } catch (SNMPException e) { throw new PluginException(e.getMessage(), e); } // inherit server hostname if something other than the default String serverHostname = serverConfig.getValue(Collector.PROP_HOSTNAME); String hostname = "localhost".equals(serverHostname) ? this.defaultIp : serverHostname; String serverProtocol = serverConfig.getValue(Collector.PROP_PROTOCOL); String protocol = ("ping".equals(serverProtocol) || // back-compat Collector.PROTOCOL_SOCKET.equals(serverProtocol)) ? serverProtocol : null; List services = new ArrayList(); Map serviceNames = new HashMap(); for (int i = 0; i < servers.size(); i++) { ApacheSNMP.Server server = (ApacheSNMP.Server) servers.get(i); String serviceName = server.toString(); // XXX should not get any duplicates. // but if we do, just fold them, no point in having duplicate // services. if (serviceNames.get(serviceName) == Boolean.TRUE) { log.debug("Discovered duplicate service: " + serviceName); continue; } serviceNames.put(serviceName, Boolean.TRUE); log.debug("Discovered service: " + serviceName); ServiceResource service = new ServiceResource(); service.setType(this, VHOST_NAME); service.setServiceName(VHOST_NAME + " " + serviceName); ConfigResponse config = new ConfigResponse(); String exceptedServerName = server.name + ":" + server.port; ApacheVHost vhost = vHosts.get(exceptedServerName); if (vhost != null) { config.setValue(Collector.PROP_HOSTNAME, vhost.getIp()); config.setValue(Collector.PROP_PORT, vhost.getPort()); } else if (config.getValue(Collector.PROP_HOSTNAME) == null) { ApacheListen parseListen = ApacheConf.parseListen(exceptedServerName); config.setValue(Collector.PROP_HOSTNAME, parseListen.getIp()); config.setValue(Collector.PROP_PORT, parseListen.getPort()); } config.setValue(PROP_SERVER_NAME, server.name); config.setValue(PROP_SERVER_PORT, server.port); // XXX snmp does not tell us the protocol String proto = protocol == null ? getConnectionProtocol(server.port) : protocol; config.setValue(Collector.PROP_PROTOCOL, proto); config.setValue(Collector.PROP_SSL, isSSL(server.port)); service.setProductConfig(config); service.setMeasurementConfig(); services.add(service); } if (servers.size() > 0) { ApacheSNMP.Server server = (ApacheSNMP.Server) servers.get(0); ConfigResponse cprops = new ConfigResponse(); cprops.setValue("version", server.version); cprops.setValue("serverTokens", server.description); cprops.setValue("serverAdmin", server.admin); setCustomProperties(cprops); } return services; }
protected boolean configureServer(ServerResource server, ApacheBinaryInfo binary) throws PluginException { ConfigResponse metricConfig, productConfig, controlConfig; String installpath = server.getInstallPath(); File snmpConfig = getSnmpdConf(installpath); boolean snmpConfigExists = snmpConfig.exists(); controlConfig = getControlConfig(installpath); if (binary != null) { ConfigResponse cprops = new ConfigResponse(binary.toProperties()); server.setCustomProperties(cprops); } getLog() .debug( "[configureServer] snmpConfigExists=" + snmpConfigExists + " this.discoverModSnmp=" + this.discoverModSnmp + " this.discoverModStatus=" + this.discoverModStatus); if (snmpConfigExists || this.discoverModSnmp) { if (!snmpConfigExists) { log.debug(snmpConfig + " does not exist, cannot auto-configure " + server.getName()); } metricConfig = getSnmpConfig(snmpConfig); productConfig = getProductConfig(metricConfig); populateListeningPorts(binary.pid, productConfig, true); if (binary.conf == null) { String cfgPath = installpath; if (snmpConfigExists) { cfgPath = snmpConfig.getParentFile().getParent(); } for (String conf : defaultConfs) { File cf = new File(cfgPath, conf); getLog().debug("[configureServer] cf=" + cf + " (" + (cf.exists() && cf.isFile()) + ")"); if (cf.exists() && cf.isFile()) { binary.conf = cf.getAbsolutePath(); } } } if (productConfig != null) { if (binary.conf != null) { productConfig.setValue("ServerConf", binary.conf); } addTrackConfig(productConfig); setProductConfig(server, productConfig); setMeasurementConfig(server, metricConfig); if (controlConfig != null) { setControlConfig(server, controlConfig); } server.setConnectProperties( new String[] { SNMPClient.PROP_PORT, SNMPClient.PROP_VERSION, // only need to avoid udp port conflicts }); } server.setDescription("mod_snmp monitor"); return true; } else if (this.discoverModStatus) { log.debug(snmpConfig + " does not exist, discovering as type: " + TYPE_HTTPD); productConfig = new ConfigResponse(); populateListeningPorts(binary.pid, productConfig, true); // meant for command-line testing: -Dhttpd.url=http://localhost:8080/ if (configureURL(getManagerProperty("httpd.url"), productConfig)) { server.setMeasurementConfig(); } else if (configureURL(binary, productConfig)) { server.setMeasurementConfig(); if (binary.conf != null) { // ServerRoot location overrides compiled in HTTPD_ROOT ConfigResponse srControlConfig = getControlConfig(binary.root); if (srControlConfig != null) { controlConfig = srControlConfig; } } } addTrackConfig(productConfig); if (controlConfig != null) { String pidfile = productConfig.getValue(ApacheControlPlugin.PROP_PIDFILE); if (pidfile != null) { setPidFile(controlConfig, pidfile); // propagate from httpd.conf } setControlConfig(server, controlConfig); } server.setDescription("mod_status monitor"); server.setType(TYPE_HTTPD); String path = binary.conf; if (path == null) { path = server.getInstallPath(); } else { // use -f file for path and AIID // since binary installpath will be the same // for multiple instances server.setInstallPath(path); } // in the event that mod_snmp is added later, // we won't clash w/ the other types server.setIdentifier(TYPE_HTTPD + " " + path); server.setProductConfig(productConfig); return true; } else { log.debug("Ignoring " + server.getName() + " at " + server.getInstallPath()); return false; } }
private void setPidFile(ConfigResponse config, String file) { config.setValue(ApacheControlPlugin.PROP_PIDFILE, file); }
private void setConfigTrack(ConfigResponse config, String file) { config.setValue(ConfigFileTrackPlugin.PROP_FILES_SERVER, file); }
private List<ServerResource> getServers(List<String> ptqlQueries) { List<ServerResource> servers = new ArrayList<ServerResource>(); // Flag to track success Boolean success = false; for (final Iterator<String> it = ptqlQueries.iterator(); it.hasNext(); ) { String ptql = (String) it.next(); final long[] pids = getPids(ptql); if (null != pids && pids.length > 0) { for (int i = 0; i < pids.length; i++) { Long pid = pids[i]; String installPath = getInstallPath(pid); if (null == installPath) { _log.debug("Found pid " + pid + ", but couldn't identify installpath"); continue; } URL bmxUrl = findBmxUrl(installPath, HTTPD_CONF); if (bmxUrl == null) { _log.debug( "Parsing " + installPath + HTTPD_CONF + " failed to find " + "usable Listen directive."); continue; } URL bmxQueryUrl = getBmxQueryUrl(bmxUrl, QUERY_BMX + SERVER_STATUS); BmxQuery query = new BmxQuery(bmxQueryUrl); BmxResult result = query.getResult(); try { result.parseToProperties(); success = true; } catch (IOException e) { _log.debug("Unable to parse results", e); continue; } Properties serverStatus = result.getProperties(); ServerResource server = createServerResource(installPath); ConfigResponse cprop = new ConfigResponse(); String version = getVersion((String) serverStatus.get("ServerVersion")); if (!version.equals(getTypeInfo().getVersion())) { // Version not matched continue; } cprop.setValue("version", version); cprop.setValue("ServerVersion", (String) serverStatus.get("ServerVersion")); server.setCustomProperties(cprop); ConfigResponse productConfig = new ConfigResponse(); productConfig.setValue("process.query", getProcessQuery(ptql, installPath)); productConfig.setValue("protocol", bmxUrl.getProtocol()); productConfig.setValue("port", bmxUrl.getPort()); productConfig.setValue("hostname", bmxUrl.getHost()); productConfig.setValue("path", bmxUrl.getPath() + QUERY_BMX + SERVER_STATUS); setProductConfig(server, productConfig); // sets a default Measurement Config property with no values setMeasurementConfig(server, new ConfigResponse()); ConfigResponse controlConfig = getControlConfig(installPath); String instanceName = getInstanceName(installPath); setControlConfig(server, controlConfig); server.setName( getPlatformName() + " " + getServerName(RESOURCE_TYPE) + " " + version + " " + instanceName); server.setDescription(getServerDescription(server.getInstallPath())); servers.add(server); } if (!success) { _log.error( "[getServers] Found potential VFWS process however was unable to determine URL of mod_bmx"); _log.error( "[getServers] Make sure -d is specified on command line and that proxying or redirecting isn't including /bmx"); } } } return servers; }
public String update() throws Exception { HttpSession session = request.getSession(); WebUser user = SessionUtils.getWebUser(session); String forwardStr = SUCCESS; String token = (String) session.getAttribute("currentPortletToken"); // For multi-portlet configurations String resKey = JsonLoadCriticalAlertsNG.RESOURCES_KEY; String countKey = PropertiesFormNG.ALERT_NUMBER; String priorityKey = PropertiesFormNG.PRIORITY; String timeKey = PropertiesFormNG.PAST; String selOrAllKey = PropertiesFormNG.SELECTED_OR_ALL; String titleKey = PropertiesFormNG.TITLE; if (token != null) { resKey += token; countKey += token; priorityKey += token; timeKey += token; selOrAllKey += token; titleKey += token; } DashboardConfig dashConfig = dashboardManager.findDashboard( (Integer) session.getAttribute(Constants.SELECTED_DASHBOARD_ID), user, authzBoss); ConfigResponse dashPrefs = dashConfig.getConfig(); if (pForm.isRemoveClicked()) { DashboardUtils.removeResources(pForm.getIds(), resKey, dashPrefs); configurationProxy.setDashboardPreferences(session, user, dashPrefs); forwardStr = "review"; } String forward = checkSubmit(pForm); if (forward != null) { return forward; } Integer numberOfAlerts = pForm.getNumberOfAlerts(); String past = String.valueOf(pForm.getPast()); String prioritity = pForm.getPriority(); String selectedOrAll = pForm.getSelectedOrAll(); dashPrefs.setValue(countKey, numberOfAlerts.toString()); dashPrefs.setValue(timeKey, past); dashPrefs.setValue(priorityKey, prioritity); dashPrefs.setValue(selOrAllKey, selectedOrAll); dashPrefs.setValue(titleKey, pForm.getTitle()); configurationProxy.setDashboardPreferences(session, user, dashPrefs); session.removeAttribute(Constants.USERS_SES_PORTAL); removeValueInSession("currentPortletKey"); removeValueInSession("currentPortletToken"); return forwardStr; }
private ServerResource createTcRuntimeServerResource( String catalinaHome, String catalinaBase, String[] processArgs, MxProcess process) throws PluginException { String query = PROC_JAVA + ",Args.*.eq=-D" + getProcHomeProperty() + "=" + catalinaBase; // Create the server resource ServerResource server = newServerResource(catalinaBase); server.setDescription(getServerDescription(server.getInstallPath())); adjustClassPath(catalinaBase); ConfigResponse config = new ConfigResponse(); ConfigSchema schema = getConfigSchema(getTypeInfo().getName(), ProductPlugin.CFGTYPE_IDX_PRODUCT); if (schema != null) { ConfigOption option = schema.getOption(PROP_PROCESS_QUERY); if (option != null) { // Configure process.query config.setValue(option.getName(), query); } } if (process.getURL() != null) { config.setValue(mxUtil.getJmxUrlProperty(), process.getURL()); } else { String[] args = process.getArgs(); for (int j = 0; j < args.length; j++) { if (configureListenerMxURL(config, catalinaBase)) { break; } else if (configureMxURL(config, args[j])) { break; } else if (configureLocalMxURL(config, args[j], query)) { // continue as .port might come later } } } storeProcessUserAndGroup(process, config); config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_BASE, catalinaBase); config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_HOME, catalinaHome); // default anything not auto-configured config.setValue("jmx.password", getJMXPassword(catalinaBase)); setProductConfig(server, config, process.getPid()); discoverServerConfig(server, process.getPid()); server.setMeasurementConfig(); // must set control config now so user doesn't have to enter config // properties prior to executing control actions server.setControlConfig(); server.setName( getPlatformName() + " " + getServerName("tc Runtime") + " " + getBaseDirectoryName(catalinaBase)); ConfigResponse controlConfig = new ConfigResponse(); String controlProgram = determineControlProgram(catalinaHome, catalinaBase); controlConfig.setValue(ServerControlPlugin.PROP_PROGRAM, controlProgram); server.setControlConfig(controlConfig); return server; }