Exemple #1
0
 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;
 }
  public static List<ConfigValues> getConfigValues(ConfigSchema schema, ConfigResponse config) {
    List<ConfigValues> values = new ArrayList<ConfigValues>();

    if (schema == null) {
      return values;
    }

    List options = schema.getOptions();
    int size = options.size();

    for (int i = 0; i < size; i++) {
      ConfigOption option = (ConfigOption) options.get(i);
      String value = config.getValue(option.getName(), true);

      if (option instanceof StringConfigOption) {
        StringConfigOption strOption = (StringConfigOption) option;

        if (strOption.isHidden()) {
          continue; // Ignore
        }
      } else if (option instanceof BooleanConfigOption) {
        if (value == null) {
          value = String.valueOf(false);
        }
      }

      values.add(new ConfigValues(option.getName(), value));
    }

    return values;
  }
 /** Shortcut, same as getConfig().getValue(key) */
 public String getConfig(String key) {
   ConfigResponse config = getConfig();
   if (config == null) {
     return null;
   }
   return config.getValue(key);
 }
 private void addProperties(final ServiceType serviceType) {
   // TODO for now, since property names are prepended with serviceType
   // name, we may be leaving some unused properties in Map if some are
   // removed on service type update...
   ConfigResponse properties = serviceType.getProperties();
   for (Iterator propertyKeys = properties.getKeys().iterator(); propertyKeys.hasNext(); ) {
     String propertyName = (String) propertyKeys.next();
     PluginData.getGlobalProperties().put(propertyName, properties.getValue(propertyName));
   }
 }
  public void addMetricConnectHashCode(ConfigResponse config, String key) {
    if (config == null) {
      return;
    }
    String value = config.getValue(key);
    if (value == null) {
      return;
    }

    addMetricConnectHashCode(value);
  }
 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);
     }
   }
 }
 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;
 }
 private void addPlugins(ProductPlugin productPlugin, ServiceType serviceType) {
   productPlugin.getPluginData().removePlugins(serviceType.getInfo().getName());
   ConfigResponse pluginClasses = serviceType.getPluginClasses();
   for (Iterator pluginKeys = pluginClasses.getKeys().iterator(); pluginKeys.hasNext(); ) {
     String pluginName = (String) pluginKeys.next();
     productPlugin
         .getPluginData()
         .addPlugin(
             pluginName, serviceType.getInfo().getName(), pluginClasses.getValue(pluginName));
   }
   productPlugin
       .getPluginData()
       .addServiceInventoryPlugin(
           serviceType.getInfo().getServerName(), serviceType.getInfo().getName(), null);
 }
Exemple #9
0
 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;
 }
  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;
    }
  }
Exemple #12
0
  // Discover Oracle services
  @Override
  protected List discoverServices(ConfigResponse config) throws PluginException {
    // HHQ-3577 allow listener names in tnsnames.ora to be used in the url
    String tnsDir =
        getTnsNamesDir(
            config.getValue(ProductPlugin.PROP_INSTALLPATH), config.getValue(PROP_TNSNAMES));
    if (log.isDebugEnabled()) log.debug("using tns dir as " + tnsDir);
    System.setProperty("oracle.net.tns_admin", tnsDir);

    String url = config.getValue(OracleMeasurementPlugin.PROP_URL);
    if (url == null) {
      log.warn(
          "No value for config property "
              + OracleMeasurementPlugin.PROP_URL
              + ", no services will be discovered.");
      return null;
    }

    String user = config.getValue(OracleMeasurementPlugin.PROP_USER);
    if (user == null) {
      log.info("No value for config property " + OracleMeasurementPlugin.PROP_USER);
    }

    String pass = config.getValue(OracleMeasurementPlugin.PROP_PASSWORD);
    if (pass == null) {
      log.info("No value for config property " + OracleMeasurementPlugin.PROP_PASSWORD);
    }

    ArrayList services = new ArrayList();
    Connection conn = null;
    Statement stmt = null;
    try {
      String instance = url.substring(url.lastIndexOf(':') + 1);
      conn = DriverManager.getConnection(url, user, pass);
      stmt = conn.createStatement();
      services.addAll(getUserServices(stmt, instance));
      services.addAll(getTablespaceServices(stmt, instance));
      // turning this off by default.
      // There are too many table that this will discover
      // most of which the user probably won't care about.
      // Also work needs to be done by the user to enable
      // scheduled control actions to do an Anaylze per table
      // so that the system info gets updated before the
      // size is calc'd.
      // services.addAll(getSegmentServices(stmt, instance));
      services.addAll(getProcessServices(config));
      // this requires extra config on the user side to set ORACLE_HOME
      // env var, so to avoid confusion disabling
      // services.addAll(getTnsServices(config));
      setCustomProps(stmt);
    } catch (SQLException e) {
      // Try to do some investigation of what went wrong
      if (e.getMessage().indexOf("table or view does not exist") != -1) {
        log.error(
            "System table does not exist, make sure that "
                + " the Oracle user specified has the correct "
                + " privileges.  See the HQ server configuration "
                + " page for more information");
        return services;
      }
      // Otherwise, dump the error.
      throw new PluginException("Error querying for Oracle " + "services: " + e.getMessage(), e);
    } finally {
      DBUtil.closeJDBCObjects(log, conn, stmt, null);
    }
    return services;
  }