From: <gla...@hy...> - 2010-04-19 18:53:51
|
Author: glaullon Date: 2010-04-19 11:27:13 -0700 (Mon, 19 Apr 2010) New Revision: 14518 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14518 Added: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseProductPlugin.java Removed: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SysbaseProductPlugin.java Modified: trunk/plugins/sybase/ trunk/plugins/sybase/etc/hq-plugin.xml trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseMeasurementPlugin.java trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseServerDetector.java trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseSysmonCollector.java Log: [HHQ-3790] Upgrading hq-agent through UI does not maintain Sybase functionality; all Sybase resources become unavailable [HHQ-3791] UI does not validate Sybase connection settings within Configuration Properties Property changes on: trunk/plugins/sybase ___________________________________________________________________ Name: svn:ignore - manifest.mf build bin nbproject build.xml sybase-plugin.jar hq.properties test + manifest.mf ToDo.txt test build.xml sybase-plugin.jar nbproject bin hq.properties build Modified: trunk/plugins/sybase/etc/hq-plugin.xml =================================================================== --- trunk/plugins/sybase/etc/hq-plugin.xml 2010-04-19 07:53:07 UTC (rev 14517) +++ trunk/plugins/sybase/etc/hq-plugin.xml 2010-04-19 18:27:13 UTC (rev 14518) @@ -29,33 +29,22 @@ USA. --> -<plugin package="org.hyperic.hq.plugin.sybase" class="SysbaseProductPlugin"> - <classpath> +<plugin package="org.hyperic.hq.plugin.sybase" class="SybaseProductPlugin"> + <!--classpath> <include name="pdk/lib/jdbc/jconn3.jar"/> <include name="pdk/lib/jdbc/jconn4.jar"/> <include name="pdk/lib/jdbc/jTDS3.jar"/> <include name="pdk/lib/jdbc/jTDS4.jar"/> - </classpath> + </classpath--> <!-- we use a dummy jmx object name --> <filter name="domain" value="sybase"/> <!-- appended to each template by MeasurementInfoXML --> <property name="template-config" - value="jdbcUrl=%jdbcUrl%,jdbcUser=%jdbcUser%,jdbcPassword=%jdbcPassword%"/> + value="interval=%interval%,jdbcUrl=%jdbcUrl%,jdbcUser=%jdbcUser%,jdbcPassword=%jdbcPassword%"/> <filter name="template" - value="${domain}:Type=Server:${alias}"/> - <metrics name="ServerMetrics"> - <metric name="Availability" - category="AVAILABILITY" - indicator="true" - units="percentage" - collectionType="dynamic"/> - - </metrics> - - <filter name="template" value="${domain}:Type=Service,instance=%instance%:${alias}"/> <metrics name="Sybase 12.x Instance"> <metric name="Availability" @@ -157,9 +146,9 @@ collectionType="dynamic"/> </metrics> - <filter name="template"> - sbSysmon:interval=%interval%,jdbcUrl=%jdbcUrl%,jdbcUser=%jdbcUser%,jdbcPassword=%jdbcPassword%:${alias} - </filter> + <filter name="template" + value="${domain}:Type=Server:${alias}"/> + <metrics name="SybaseAvailability"> <metric name="Availability" category="AVAILABILITY" @@ -168,6 +157,9 @@ collectionType="dynamic"/> </metrics> + <filter name="template"> + sbSysmon:interval=%interval%,jdbcUrl=%jdbcUrl%,jdbcUser=%jdbcUser%,jdbcPassword=%jdbcPassword%:${alias} + </filter> <metrics name="sp_sysmon"> <metric name="Deadlocks" category="THROUGHPUT" @@ -217,7 +209,6 @@ <plugin type="autoinventory" class="SybaseServerDetector"/> <metrics include="SybaseAvailability"/> - <metrics include="ServerMetrics"/> <metrics include="sp_sysmon"/> <properties> @@ -241,9 +232,6 @@ <option name="interval" description="sp_sysmon interval" default="00:05:00"/> - <option name="timeout" - description="Timeout for sp_sysmon, must be greater than the interval" - default="3500"/> </config> <service name="sp_sysmonEngine"> Modified: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseMeasurementPlugin.java =================================================================== --- trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseMeasurementPlugin.java 2010-04-19 07:53:07 UTC (rev 14517) +++ trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseMeasurementPlugin.java 2010-04-19 18:27:13 UTC (rev 14518) @@ -35,8 +35,9 @@ import java.sql.ResultSetMetaData; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.logging.Log; -import org.hyperic.hq.product.Collector; import org.hyperic.hq.product.JDBCMeasurementPlugin; import org.hyperic.hq.product.Metric; @@ -53,7 +54,7 @@ public class SybaseMeasurementPlugin extends JDBCMeasurementPlugin { - private final Log _log = getLog(); + private final Log log = getLog(); private static final String JDBC_DRIVER = "com.sybase.jdbc3.jdbc.SybDriver"; @@ -289,6 +290,14 @@ try { // do not close cached connection conn = getCachedConnection(url, user, pass); + } catch (SQLException e) { + removeCachedConnection(url, user, pass); + DBUtil.closeConnection("[getValue]", conn); + String msg = "Commection failed for '" + alias + "': " + e.getMessage(); + throw new MetricNotFoundException(msg, e); + } + + try { if (objectName.indexOf(TYPE_SP_MONITOR_CONFIG) != -1) { res = getSP_MonitorConfigValue(metric, alias, conn); } else if (objectName.indexOf(TYPE_STORAGE) != -1) { @@ -299,7 +308,7 @@ } catch (SQLException e) { removeCachedConnection(url, user, pass); DBUtil.closeConnection(null, conn); - String msg = "Query failed for " + alias + ": " + e.getMessage(); + String msg = "Query failed for '" + alias + "': " + e.getMessage(); if (metric.isAvail()) { res = new MetricValue(Metric.AVAIL_DOWN); } else { @@ -309,7 +318,9 @@ if (res == null) { throw new MetricNotFoundException("cannot find metric " + metric); } - _log.debug("[getValue] alias='"+alias+"' res='"+res+"'"); + if (log.isDebugEnabled()) { + log.debug("[getValue] alias='" + alias + "' res='" + res + "' metric="+metric); + } return res; } @@ -326,10 +337,10 @@ res=Metric.AVAIL_UP; } catch (SQLException e) { - _log.debug("Query failed for Availability "+e.getMessage(),e); + log.debug("Query failed for Availability "+e.getMessage(),e); } finally { - DBUtil.closeJDBCObjects(_log, null, stmt, rs); + DBUtil.closeJDBCObjects(log, null, stmt, rs); } return new MetricValue(res, System.currentTimeMillis()); } @@ -377,7 +388,7 @@ } finally { if(stmt!=null) stmt.execute("use master"); // XXX why? - DBUtil.closeJDBCObjects(_log, null, stmt, rs); + DBUtil.closeJDBCObjects(log, null, stmt, rs); } return res; } @@ -458,9 +469,9 @@ res = Metric.AVAIL_UP; } } catch (SQLException e) { - _log.debug("[getAvail] configOpt='" + configOpt + "' -> " + e.getMessage()); + log.debug("[getAvail] configOpt='" + configOpt + "' -> " + e.getMessage()); } finally { - DBUtil.closeJDBCObjects(_log, null, stmt, rs); + DBUtil.closeJDBCObjects(log, null, stmt, rs); } return res; } @@ -495,7 +506,7 @@ } } finally { - DBUtil.closeJDBCObjects(_log, null, stmt, rs); + DBUtil.closeJDBCObjects(log, null, stmt, rs); } throw new SQLException(); } @@ -526,7 +537,7 @@ } catch (SQLException e) { throw new MetricUnreachableException(e.getMessage(), e); } finally { - DBUtil.closeJDBCObjects(_log, null, stmt, rs); + DBUtil.closeJDBCObjects(log, null, stmt, rs); } } } Copied: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseProductPlugin.java (from rev 14282, trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SysbaseProductPlugin.java) =================================================================== --- trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseProductPlugin.java (rev 0) +++ trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseProductPlugin.java 2010-04-19 18:27:13 UTC (rev 14518) @@ -0,0 +1,98 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.hyperic.hq.plugin.sybase; + +import java.io.File; +import java.util.Arrays; +import java.util.Properties; +import org.apache.commons.logging.Log; +import org.hyperic.hq.product.PluginException; +import org.hyperic.hq.product.PluginManager; +import org.hyperic.hq.product.ProductPlugin; +import org.hyperic.hq.product.ProductPluginManager; +import org.hyperic.sigar.Sigar; +import org.hyperic.sigar.SigarException; +import org.hyperic.sigar.ptql.ProcessFinder; +import org.hyperic.util.file.FileUtil; + +/** + * + * @author laullon + */ +public class SybaseProductPlugin extends ProductPlugin { + + private static String[] jars = {"jConnect-6_0/classes/jconn3.jar", + "jConnect-7_0/classes/jconn4.jar"}; + private static String saRole; + private static boolean originalAIID = true; + private static String PROP_CLASSPATH = "sybase.classpath"; + private static String PROP_INSTALLPATH = "sybase.installpath"; + Log log = getLog(); + + protected static boolean isOriginalAIID() { + return originalAIID; + } + + protected static String getSaRole(){ + return saRole; + } + + public void init(PluginManager manager) throws PluginException { + super.init(manager); + Properties props = manager.getProperties(); + originalAIID = "true".equals(props.getProperty("sysbase.aiid.orginal", "true").toLowerCase()); + saRole = props.getProperty("sysbase.sa_role", "sa_role"); + } + + public String[] getClassPath(ProductPluginManager manager) { + String[] res=_getClassPath(manager); + log.debug("[getClassPath] res="+Arrays.asList(res)); + return res; + } + + private String[] _getClassPath(ProductPluginManager manager) { + Properties props = manager.getProperties(); + + if (props.getProperty(PROP_CLASSPATH) != null) { + return props.getProperty(PROP_CLASSPATH).split(","); + } + + if (props.getProperty(PROP_INSTALLPATH) != null) { + return findJDBCJar(props.getProperty(PROP_INSTALLPATH)); + } + + String[] res = null; + try { + Sigar sigar = new Sigar(); + long[] pids = ProcessFinder.find(sigar, SybaseServerDetector.PTQL_QUERY); + for (int n = 0; ((n < pids.length) && (res == null)); n++) { + String installPath = sigar.getProcArgs(pids[n])[0]; + installPath = FileUtil.getParentDir(installPath, 3); + res = findJDBCJar(installPath); + } + } catch (SigarException ex) { + ex.printStackTrace(); + } + if (res == null) { + res = new String[]{}; + } + return res; + } + + private String[] findJDBCJar(String installPath) { + log.debug("[getClassPath] testing " + PROP_INSTALLPATH + "='" + installPath + "'"); + String[] res = null; + File ip = new File(installPath); + if (ip.exists()) { + for (int i = 0; ((i < jars.length) && (res == null)); i++) { + File jar = new File(ip, jars[i]); + if (jar.exists() && jar.canRead()) { + res = new String[]{jar.getAbsolutePath()}; + } + } + } + return res; + } +} Modified: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseServerDetector.java =================================================================== --- trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseServerDetector.java 2010-04-19 07:53:07 UTC (rev 14517) +++ trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseServerDetector.java 2010-04-19 18:27:13 UTC (rev 14518) @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hyperic.hq.product.AutoServerDetector; import org.hyperic.hq.product.PluginException; @@ -62,7 +63,7 @@ PROP_URL = SybaseMeasurementPlugin.PROP_URL, PROP_USER = SybaseMeasurementPlugin.PROP_USER, PROP_PASSWORD = SybaseMeasurementPlugin.PROP_PASSWORD; - private static String PTQL_QUERY; + public static String PTQL_QUERY; static { if (isWin32()) { PTQL_QUERY = @@ -90,7 +91,7 @@ VERSION_12_5 = "12.5.x", VERSION_12_0 = "12.x"; - private Log log=getLog(); + private Log log=LogFactory.getLog(SybaseServerDetector.class); public List getServerResources(ConfigResponse config) throws PluginException { log.debug("[getServerResources] config=" + config); @@ -139,11 +140,6 @@ String installdir = getParentDir(path, 3); - ConfigResponse productConfig = new ConfigResponse(); - productConfig.setValue(PROP_USER, "sa"); - productConfig.setValue(PROP_PASSWORD, ""); - productConfig.setValue("serverName", name); - String version = ""; @@ -163,20 +159,24 @@ if (!version.equals(getTypeInfo().getVersion())) { return servers; } + + ConfigResponse measurementConfig = new ConfigResponse(); + measurementConfig.setValue("serverName", name); + ServerResource server = createServerResource(installpath); // Set custom properties ConfigResponse cprop = new ConfigResponse(); cprop.setValue("version", version); server.setCustomProperties(cprop); - setProductConfig(server, productConfig); - server.setMeasurementConfig(); + setProductConfig(server, new ConfigResponse()); + setMeasurementConfig(server,measurementConfig); server.setName(getPlatformName() + " " + SERVER_NAME + " " + version + " " + name); servers.add(server); - log.debug("sysbase.aiid.orginal=" + SysbaseProductPlugin.isOriginalAIID()); + log.debug("sysbase.aiid.orginal=" + SybaseProductPlugin.isOriginalAIID()); log.debug("installdir=" + installdir); log.debug("installpath=" + installpath); - if (SysbaseProductPlugin.isOriginalAIID()) { + if (SybaseProductPlugin.isOriginalAIID()) { server.setIdentifier(installdir); } else { server.setIdentifier(installpath); Modified: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseSysmonCollector.java =================================================================== --- trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseSysmonCollector.java 2010-04-19 07:53:07 UTC (rev 14517) +++ trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SybaseSysmonCollector.java 2010-04-19 18:27:13 UTC (rev 14518) @@ -7,6 +7,7 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.Arrays; @@ -29,6 +30,7 @@ */ public class SybaseSysmonCollector extends Collector { + public static final String INTERVAL = "interval"; static Log trace = LogFactory.getLog("trace." + SybaseSysmonCollector.class); static Log log = LogFactory.getLog(SybaseSysmonCollector.class); private CallableStatement stmt; @@ -37,32 +39,49 @@ protected void init() throws PluginException { Properties props = getProperties(); - String url = props.getProperty(JDBCMeasurementPlugin.PROP_URL, ""), - user = props.getProperty(JDBCMeasurementPlugin.PROP_USER, ""), - pass = props.getProperty(JDBCMeasurementPlugin.PROP_PASSWORD, ""); - + Connection c = null; + ResultSet rs = null; + CallableStatement st = null; + String sa_role = SybaseProductPlugin.getSaRole(); + try { - conn = createConnection(url, user, pass); - } catch(SQLException e) { - throw new PluginException("Create connection failed:" + e.getMessage(), e); + c = createConnection(props); + st = c.prepareCall("{call sp_displayroles}"); + rs = st.executeQuery(); + boolean roleOK = false; + while (rs.next() && !roleOK) { + roleOK = rs.getString(1).equals(sa_role); + } + if (!roleOK) { + throw new PluginException("Could not connect using information provided: The user must have System Administrator ('" + sa_role + "') role"); + } + } catch (SQLException e) { + throw new PluginException("Could not connect using information provided", e); + } finally { + DBUtil.closeJDBCObjects(log, c, st, rs); } - + + String interval = props.getProperty(SybaseSysmonCollector.INTERVAL); + Pattern p = Pattern.compile("^\\d\\d:\\d\\d:\\d\\d$"); + Matcher m = p.matcher(interval); + if (!m.matches()) { + String msg = "Configuration failed: bad INTERVAL format ##:##:## (" + interval + ")"; + throw new PluginException(msg); + } + super.init(); } public void collect() { - Properties props = getProperties(); + log.debug("[collect] props=" + props); - String url = props.getProperty(JDBCMeasurementPlugin.PROP_URL, ""), - user = props.getProperty(JDBCMeasurementPlugin.PROP_USER, ""), - pass = props.getProperty(JDBCMeasurementPlugin.PROP_PASSWORD, ""); try { setAvailability(Metric.AVAIL_DOWN); if (conn == null) { - conn = createConnection(url, user, pass); + conn = createConnection(props); } - stmt = conn.prepareCall("{call sp_sysmon '" + props.getProperty("interval") + "'}"); + stmt = conn.prepareCall("{call sp_sysmon '" + props.getProperty(INTERVAL) + "'}"); stmt.executeUpdate(); StringBuffer response = new StringBuffer(); @@ -79,8 +98,10 @@ Matcher m = pat.matcher(res); while (m.find()) { final String cacheName = m.group(1).trim().replaceAll(" ", "_"); - trace.debug("->'" + cacheName + "'"); - trace.debug("->" + m.start()); + if (trace.isDebugEnabled()) { + trace.debug("->'" + cacheName + "'"); + trace.debug("->" + m.start()); + } String sec = res.substring(m.start()); setValue(cacheName + ".Availability", Metric.AVAIL_UP); setValue(cacheName + ".CacheHitsRatio", get(sec, "Cache Hits", 5) / 100); @@ -130,11 +151,13 @@ Matcher lm = pat.matcher(txt); if (lm.find()) { String line = lm.group(); - log.debug(line); line = line.trim().replaceAll(" +", " "); vals = line.split(" "); - log.debug(line); - log.debug(Arrays.asList(vals)); + if (trace.isDebugEnabled()) { + trace.debug(line); + trace.debug(line); + trace.debug(Arrays.asList(vals)); + } if (!vals[index].equals("n/a")) { res = Double.parseDouble(vals[index]); } else { @@ -143,15 +166,17 @@ } } catch (ArrayIndexOutOfBoundsException e) { res = Double.NaN; - log.debug("vals=> '" + Arrays.asList(vals) + "' pro='" + pro + "' index='" + index + "'"); + trace.debug("vals=> '" + Arrays.asList(vals) + "' pro='" + pro + "' index='" + index + "'"); } return res; } - protected Connection createConnection(String url, String user, String password) throws SQLException { - String pass = (password == null) ? "" : password; + protected Connection createConnection(Properties p) throws SQLException { + String url = p.getProperty(JDBCMeasurementPlugin.PROP_URL, ""); + String user = p.getProperty(JDBCMeasurementPlugin.PROP_USER, ""); + String pass = p.getProperty(JDBCMeasurementPlugin.PROP_PASSWORD, ""); pass = (pass.matches("^\\s*$")) ? "" : pass; - java.util.Properties props = new java.util.Properties(); + Properties props = new java.util.Properties(); props.put("CHARSET_CONVERTER_CLASS", "com.sybase.jdbc3.utils.TruncationConverter"); props.put("user", user); props.put("password", pass); Deleted: trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SysbaseProductPlugin.java =================================================================== --- trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SysbaseProductPlugin.java 2010-04-19 07:53:07 UTC (rev 14517) +++ trunk/plugins/sybase/src/org/hyperic/hq/plugin/sybase/SysbaseProductPlugin.java 2010-04-19 18:27:13 UTC (rev 14518) @@ -1,31 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.hyperic.hq.plugin.sybase; - -import java.util.Properties; -import org.apache.commons.logging.Log; -import org.hyperic.hq.product.PluginException; -import org.hyperic.hq.product.PluginManager; -import org.hyperic.hq.product.ProductPlugin; - -/** - * - * @author laullon - */ -public class SysbaseProductPlugin extends ProductPlugin { - - private static boolean originalAIID = true; - Log log = getLog(); - - protected static boolean isOriginalAIID() { - return originalAIID; - } - - public void init(PluginManager manager) throws PluginException { - super.init(manager); - Properties props = manager.getProperties(); - originalAIID = "true".equals(props.getProperty("sysbase.aiid.orginal", "true").toLowerCase()); - } -} |