Ejemplo n.º 1
1
 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;
 }
Ejemplo n.º 2
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;
 }
  private void addMeasurementConfig(
      List<MeasurementConfigEntity> ents, AppdefEntityID id, String typeName) {
    MeasurementConfigEntity ent = new MeasurementConfigEntity();
    ConfigResponse response;
    byte[] config;

    try {
      response =
          configManager.getMergedConfigResponse(
              authzSubjectManager.getOverlordPojo(), ProductPlugin.TYPE_MEASUREMENT, id, true);

      // Only send the configuration to the agent if log or
      // config file tracking has been enabled.
      if (ConfigTrackPlugin.isEnabled(response, id.getType())
          || LogTrackPlugin.isEnabled(response, id.getType())) {

        config = response.encode();

        ent.setPluginName(id.getAppdefKey());
        ent.setPluginType(typeName);
        ent.setConfig(config);

        ents.add(ent);
      }

    } catch (Exception exc) {
      return; // Not a fatal condition
    }
  }
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
0
 /** 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 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);
  }
Ejemplo n.º 7
0
 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 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));
   }
 }
Ejemplo n.º 11
0
 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);
     }
   }
 }
Ejemplo n.º 12
0
  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;
  }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
 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);
   }
 }
Ejemplo n.º 16
0
  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;
  }
  /**
   * Return the array of Integer ids for the given <code>notificationType</code> contained in the
   * alert definition notification actions.
   *
   * <p>This method also sets the alert definition object on the form and places it in the request.
   * It also puts the resource id and resource type in the request.
   *
   * @param addForm the form being prepared
   * @param notificationType the type of notification
   * @return the array of ids for already existing notifications based on the notificationType, or a
   *     zero-length array if there are not yet any notifications of this type
   * @throws ServletException
   * @throws RemoteException
   * @throws PermissionException
   * @throws SessionTimeoutException
   * @throws SessionNotFoundException
   * @throws EncodingException
   * @throws InvalidActionDataException
   */
  public Integer[] getNotificationIds(
      HttpServletRequest request,
      AddNotificationsFormNG addForm,
      AppdefEntityID aeid,
      int notificationType)
      throws ServletException, SessionNotFoundException, SessionTimeoutException,
          PermissionException, RemoteException, EncodingException, InvalidActionDataException {
    Integer[] ids = new Integer[0];

    Integer sessionId = RequestUtils.getSessionId(request);

    Integer alertDefId = addForm.getAd();
    log.debug("(1) alertDefId=" + alertDefId);
    if (alertDefId == null) throw new ParameterNotFoundException("alert definition id not found");

    log.debug("(2) alertDefId=" + alertDefId);
    AlertDefinitionValue alertDef =
        (AlertDefinitionValue) request.getAttribute(Constants.ALERT_DEFS_ATTR);
    if (alertDef == null) {
      alertDef = eventsBoss.getAlertDefinition(sessionId.intValue(), alertDefId);
    }
    request.setAttribute(Constants.ALERT_DEFINITION_ATTR, alertDef);

    ActionValue[] actions = alertDef.getActions();
    for (int i = 0; i < actions.length; ++i) {
      if (actions[i].classnameHasBeenSet()
          && !(actions[i].getClassname().equals(null) || actions[i].getClassname().equals(""))) {
        EmailActionConfig emailCfg = new EmailActionConfig();
        ConfigResponse configResponse = ConfigResponse.decode(actions[i].getConfig());

        try {
          emailCfg.init(configResponse);
        } catch (InvalidActionDataException e) {
          // Not an EmailAction
          log.debug("Action is " + actions[i].getClassname());
          continue;
        }

        if (emailCfg.getType() == notificationType) {
          ids = new Integer[emailCfg.getUsers().size()];
          ids = (Integer[]) emailCfg.getUsers().toArray(ids);
          break;
        }
      }
    }

    if (aeid instanceof AppdefEntityTypeID) {
      addForm.setAetid(aeid.getAppdefKey());
      request.setAttribute(Constants.APPDEF_RES_TYPE_ID, aeid.getAppdefKey());
    } else {
      addForm.setRid(aeid.getId());
      addForm.setType(new Integer(aeid.getType()));
      request.setAttribute(Constants.ENTITY_ID_PARAM, aeid.getAppdefKey());
    }

    return ids;
  }
Ejemplo n.º 18
0
  public void addMetricConnectHashCode(ConfigResponse config, String key) {
    if (config == null) {
      return;
    }
    String value = config.getValue(key);
    if (value == null) {
      return;
    }

    addMetricConnectHashCode(value);
  }
Ejemplo n.º 19
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;
 }
  /**
   * 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;
  }
Ejemplo n.º 21
0
  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;
 }
Ejemplo n.º 23
0
  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;
  }
Ejemplo n.º 24
0
 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;
 }
Ejemplo n.º 25
0
  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;
  }
Ejemplo n.º 26
0
  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;
  }
Ejemplo n.º 27
0
  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;
  }
Ejemplo n.º 28
0
  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;
    }
  }
Ejemplo n.º 29
0
 private void setPidFile(ConfigResponse config, String file) {
   config.setValue(ApacheControlPlugin.PROP_PIDFILE, file);
 }
Ejemplo n.º 30
0
 private void setConfigTrack(ConfigResponse config, String file) {
   config.setValue(ConfigFileTrackPlugin.PROP_FILES_SERVER, file);
 }