コード例 #1
0
 public int getSnmpMaxRepetitions(int current) {
   int maxRepetitions = ParameterMap.getKeyedInteger(m_parameters, "max-repetitions", -1);
   if (maxRepetitions == -1) {
     // in case someone is using an ancient config file
     maxRepetitions = ParameterMap.getKeyedInteger(m_parameters, "maxRepetitions", current);
   }
   return maxRepetitions;
 }
コード例 #2
0
 public String getSnmpReadCommunity(String current) {
   String readCommunity = ParameterMap.getKeyedString(getParameters(), "read-community", null);
   if (readCommunity == null) {
     // incase someone is using an ancient config file
     readCommunity = ParameterMap.getKeyedString(m_parameters, "readCommunity", current);
   }
   return readCommunity;
 }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  public boolean checkStatus(Connection con, Map<String, Object> qualifiers) {
    Statement st = null;
    String query = ParameterMap.getKeyedString(qualifiers, "query", null);

    if (query == null) return false;

    try {
      st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(query);
      rs.first();

      if (rs.getRow() == 1) return true;

    } catch (SQLException exp) {
      return false;

    } catch (Throwable exp) {
      return false;
    } finally {
      closeStmt(st);
    }

    return false;
  }
コード例 #4
0
ファイル: JMXCollector.java プロジェクト: garylai578/opennms
  /**
   * {@inheritDoc}
   *
   * <p>Responsible for performing all necessary initialization for the specified interface in
   * preparation for data collection.
   */
  @Override
  public void initialize(CollectionAgent agent, Map<String, Object> parameters) {
    InetAddress ipAddr = agent.getAddress();
    int nodeID = agent.getNodeId();

    // Retrieve the name of the JMX data collector
    String collectionName = ParameterMap.getKeyedString(parameters, "collection", serviceName);

    final String hostAddress = InetAddressUtils.str(ipAddr);
    LogUtils.debugf(
        this, "initialize: InetAddress=%s, collectionName=%s", hostAddress, collectionName);

    JMXNodeInfo nodeInfo = new JMXNodeInfo(nodeID);
    LogUtils.debugf(this, "nodeInfo: %s %d %s", hostAddress, nodeID, agent);

    /*
     * Retrieve list of MBean objects to be collected from the
     * remote agent which are to be stored in the node-level RRD file.
     * These objects pertain to the node itself not any individual
     * interfaces.
     */
    Map<String, List<Attrib>> attrMap =
        JMXDataCollectionConfigFactory.getInstance()
            .getAttributeMap(collectionName, serviceName, hostAddress);
    nodeInfo.setAttributeMap(attrMap);

    Map<String, JMXDataSource> dsList = buildDataSourceList(collectionName, attrMap);
    nodeInfo.setDsMap(dsList);
    nodeInfo.setMBeans(JMXDataCollectionConfigFactory.getInstance().getMBeanInfo(collectionName));

    // Add the JMXNodeInfo object as an attribute of the interface
    agent.setAttribute(NODE_INFO_KEY, nodeInfo);
    agent.setAttribute("collectionName", collectionName);
  }
コード例 #5
0
ファイル: TcpPlugin.java プロジェクト: garylai578/opennms
  /**
   * {@inheritDoc}
   *
   * <p>Returns true if the protocol defined by this plugin is supported. If the protocol is not
   * supported then a false value is returned to the caller. The qualifier map passed to the method
   * is used by the plugin to return additional information by key-name. These key-value pairs can
   * be added to service events if needed.
   */
  public boolean isProtocolSupported(InetAddress address, Map<String, Object> qualifiers) {
    int retries = DEFAULT_RETRY;
    int timeout = DEFAULT_TIMEOUT;
    int port = -1;

    String banner = null;
    String match = null;

    if (qualifiers != null) {
      retries = ParameterMap.getKeyedInteger(qualifiers, "retry", DEFAULT_RETRY);
      timeout = ParameterMap.getKeyedInteger(qualifiers, "timeout", DEFAULT_TIMEOUT);
      port = ParameterMap.getKeyedInteger(qualifiers, "port", -1);
      banner = ParameterMap.getKeyedString(qualifiers, "banner", null);
      match = ParameterMap.getKeyedString(qualifiers, "match", null);
    }

    // verify the port
    //
    if (port == -1)
      throw new IllegalArgumentException("The port must be specified when doing TCP discovery");

    try {
      StringBuffer bannerResult = null;
      RE regex = null;
      if (match == null && (banner == null || banner.equals("*"))) {
        regex = null;
      } else if (match != null) {
        regex = new RE(match);
        bannerResult = new StringBuffer();
      } else if (banner != null) {
        regex = new RE(banner);
        bannerResult = new StringBuffer();
      }

      boolean result = isServer(address, port, retries, timeout, regex, bannerResult);
      if (result && qualifiers != null) {
        if (bannerResult != null && bannerResult.length() > 0)
          qualifiers.put("banner", bannerResult.toString());
      }

      return result;
    } catch (RESyntaxException e) {
      throw new java.lang.reflect.UndeclaredThrowableException(e);
    }
  }
コード例 #6
0
ファイル: SmtpPlugin.java プロジェクト: RangerRick/opennms
  /**
   * {@inheritDoc}
   *
   * <p>Returns true if the protocol defined by this plugin is supported. If the protocol is not
   * supported then a false value is returned to the caller. The qualifier map passed to the method
   * is used by the plugin to return additional information by key-name. These key-value pairs can
   * be added to service events if needed.
   */
  @Override
  public boolean isProtocolSupported(InetAddress address, Map<String, Object> qualifiers) {
    int retries = DEFAULT_RETRY;
    int timeout = DEFAULT_TIMEOUT;
    int port = DEFAULT_PORT;

    if (qualifiers != null) {
      retries = ParameterMap.getKeyedInteger(qualifiers, "retry", DEFAULT_RETRY);
      timeout = ParameterMap.getKeyedInteger(qualifiers, "timeout", DEFAULT_TIMEOUT);
      port = ParameterMap.getKeyedInteger(qualifiers, "port", DEFAULT_PORT);
    }

    boolean result = isServer(address, port, retries, timeout);
    if (result && qualifiers != null && !qualifiers.containsKey("port"))
      qualifiers.put("port", port);

    return result;
  }
コード例 #7
0
 public String getCollectionName() {
   // icky hard coded old names; we need to handle some old cases where configs might be not yet
   // updated, but they should
   // still work
   if (getParameters().containsKey("collection")) {
     return ParameterMap.getKeyedString(getParameters(), "collection", "default");
   } else if (getParameters().containsKey("http-collection")) {
     return ParameterMap.getKeyedString(getParameters(), "http-collection", "default");
   } else if (getParameters().containsKey("nsclient-collection")) {
     return ParameterMap.getKeyedString(getParameters(), "nsclient-collection", "default");
   } else if (m_parameters.containsKey("wmi-collection")) {
     return ParameterMap.getKeyedString(getParameters(), "wmi-collection", "default");
   } else {
     return "default";
   }
   // Previous code:  we can return to this in time (maybe 1.6, or even 2.0) when all old
   // configs should be long gone
   // return ParameterMap.getKeyedString(getParameters(), "collection", "default");
 }
コード例 #8
0
 public InetAddress getSnmpProxyFor(InetAddress current) {
   String address = ParameterMap.getKeyedString(getParameters(), "proxy-host", null);
   InetAddress addr = null;
   if (address != null) {
     addr = InetAddressUtils.addr(address);
     if (addr == null) {
       LOG.error("determineProxyHost: Problem converting proxy host string to InetAddress");
     }
   }
   return addr == null ? current : addr;
 }
コード例 #9
0
  private SnmpAgentConfig getAgentConfig(InetAddress ipaddr) {
    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr);
    if (agentConfig == null) {
      throw new IllegalStateException(
          "SnmpAgentConfig object not available for interface " + ipaddr);
    }

    agentConfig.hashCode();

    // Set timeout and retries on SNMP peer object
    agentConfig.setTimeout(
        ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout()));
    agentConfig.setRetries(
        ParameterMap.getKeyedInteger(
            m_parameters,
            "retry",
            ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries())));
    agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort()));

    return agentConfig;
  }
コード例 #10
0
 public int getSnmpVersion(int current) {
   String version = ParameterMap.getKeyedString(getParameters(), "version", null);
   if (version != null) {
     if (version.equals("v1")) {
       return SnmpAgentConfig.VERSION1;
     } else if (version.equals("v2c")) {
       return SnmpAgentConfig.VERSION2C;
     } else if (version.equals("v3")) {
       return SnmpAgentConfig.VERSION3;
     }
   }
   return current;
 }
コード例 #11
0
ファイル: TcaCollector.java プロジェクト: nemi1990/opennms
 /* (non-Javadoc)
  * @see org.opennms.netmgt.collectd.ServiceCollector#collect(org.opennms.netmgt.collectd.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, java.util.Map)
  */
 @Override
 public CollectionSet collect(
     CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters)
     throws CollectionException {
   try {
     String collectionName = ParameterMap.getKeyedString(parameters, "collection", null);
     if (collectionName == null) {
       collectionName = ParameterMap.getKeyedString(parameters, "tca-collection", null);
     }
     if (collectionName == null) {
       throw new CollectionException("Parameter collection is required for the TCA Collector!");
     }
     TcaCollectionSet collectionSet =
         new TcaCollectionSet(agent, getRrdRepository(collectionName));
     collectionSet.setCollectionTimestamp(new Date());
     collectionSet.collect();
     return collectionSet;
   } catch (Throwable t) {
     throw new CollectionException(
         "Unexpected error during node TCA collection for: " + agent.getHostAddress() + ": " + t,
         t);
   }
 }
コード例 #12
0
 public String getSnmpPrivPassPhrase(String current) {
   return ParameterMap.getKeyedString(getParameters(), "privacy-passphrase", current);
 }
コード例 #13
0
 public String getSnmpAuthProtocol(String current) {
   return ParameterMap.getKeyedString(getParameters(), "auth-protocol", current);
 }
コード例 #14
0
 public String getSnmpAuthPassPhrase(String current) {
   return ParameterMap.getKeyedString(getParameters(), "auth-passphrase", current);
 }
コード例 #15
0
 public String getSnmpSecurityName(String current) {
   return ParameterMap.getKeyedString(getParameters(), "security-name", current);
 }
コード例 #16
0
ファイル: WmiCollector.java プロジェクト: nathanr123/opennms
  /** {@inheritDoc} */
  @Override
  public CollectionSet collect(
      final CollectionAgent agent, final EventProxy eproxy, final Map<String, Object> parameters) {

    String collectionName =
        ParameterMap.getKeyedString(
            parameters,
            "collection",
            ParameterMap.getKeyedString(parameters, "wmi-collection", null));
    // Find attributes to collect - check groups in configuration. For each,
    // check scheduled nodes to see if that group should be collected
    final WmiCollection collection =
        WmiDataCollectionConfigFactory.getInstance().getWmiCollection(collectionName);
    final WmiAgentState agentState = m_scheduledNodes.get(agent.getNodeId());

    // Load the attribute group types.
    loadAttributeGroupList(collection);

    // Load the attribute types.
    loadAttributeTypeList(collection);

    // Create a new collection set.
    final WmiCollectionSet collectionSet = new WmiCollectionSet();
    collectionSet.setCollectionTimestamp(new Date());
    final WmiSingleInstanceCollectionResource nodeResource =
        new WmiSingleInstanceCollectionResource(agent);

    // Iterate through the WMI collection groups.
    for (final Wpm wpm : collection.getWpms().getWpm()) {
      // A wpm consists of a list of attributes, identified by name
      if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) {
        if (!isGroupAvailable(agentState, wpm)) {
          continue;
        }
      }

      if (agentState.groupIsAvailable(wpm.getName())) {
        WmiClient client = null;
        // Collect the data
        try {
          // Tell the agent to connect
          agentState.connect(wpm.getWmiNamespace());

          // And retrieve the client object for working.
          client = (WmiClient) agentState.getWmiClient();

          // Retrieve the WbemObjectSet from the class defined on the group.
          final OnmsWbemObjectSet wOS = client.performInstanceOf(wpm.getWmiClass());

          // If we received a WbemObjectSet result, lets go through it and collect it.
          if (wOS != null) {
            //  Go through each object (class instance) in the object set.
            for (int i = 0; i < wOS.count(); i++) {
              // Create a new collection resource.
              WmiCollectionResource resource = null;

              // Fetch our WBEM Object
              final OnmsWbemObject obj = wOS.get(i);

              // If this is multi-instance, fetch the instance name and store it.
              if (wOS.count() > 1) {
                // Fetch the value of the key value. e.g. Name.
                final OnmsWbemProperty prop = obj.getWmiProperties().getByName(wpm.getKeyvalue());
                final Object propVal = prop.getWmiValue();
                String instance = null;
                if (propVal instanceof String) {
                  instance = (String) propVal;
                } else {
                  instance = propVal.toString();
                }
                resource =
                    new WmiMultiInstanceCollectionResource(agent, instance, wpm.getResourceType());
              } else {
                resource = nodeResource;
              }

              for (final Attrib attrib : wpm.getAttrib()) {
                final OnmsWbemProperty prop =
                    obj.getWmiProperties().getByName(attrib.getWmiObject());
                final WmiCollectionAttributeType attribType =
                    m_attribTypeList.get(attrib.getName());
                resource.setAttributeValue(attribType, prop.getWmiValue().toString());
              }
              collectionSet.getCollectionResources().add(resource);
            }
          }
        } catch (final WmiException e) {
          LOG.info("unable to collect params for wpm '{}'", wpm.getName(), e);
        } finally {
          if (client != null) {
            try {
              client.disconnect();
            } catch (final WmiException e) {
              LOG.warn("An error occurred disconnecting while collecting from WMI.", e);
            }
          }
        }
      }
    }
    collectionSet.setStatus(ServiceCollector.COLLECTION_SUCCEEDED);
    return collectionSet;
  }
コード例 #17
0
 public String getStorFlagOverride() {
   return ParameterMap.getKeyedString(getParameters(), "storFlagOverride", "false");
 }
コード例 #18
0
 public String getStoreByNodeID() {
   return ParameterMap.getKeyedString(getParameters(), "storeByNodeID", "normal");
 }
コード例 #19
0
 public String getSnmpWriteCommunity(String current) {
   return ParameterMap.getKeyedString(getParameters(), "write-community", current);
 }
コード例 #20
0
ファイル: WebMonitor.java プロジェクト: garylai578/opennms
  /** {@inheritDoc} */
  @Override
  public PollStatus poll(MonitoredService svc, Map<String, Object> map) {
    PollStatus pollStatus = PollStatus.unresponsive();
    DefaultHttpClient httpClient = new DefaultHttpClient();

    try {
      final String hostAddress = InetAddressUtils.str(svc.getAddress());

      URIBuilder ub = new URIBuilder();
      ub.setScheme(ParameterMap.getKeyedString(map, "scheme", DEFAULT_SCHEME));
      ub.setHost(hostAddress);
      ub.setPort(ParameterMap.getKeyedInteger(map, "port", DEFAULT_PORT));
      ub.setPath(ParameterMap.getKeyedString(map, "path", DEFAULT_PATH));
      HttpGet getMethod = new HttpGet(ub.build());
      httpClient
          .getParams()
          .setIntParameter(
              CoreConnectionPNames.CONNECTION_TIMEOUT,
              ParameterMap.getKeyedInteger(map, "timeout", DEFAULT_TIMEOUT));
      httpClient
          .getParams()
          .setIntParameter(
              CoreConnectionPNames.SO_TIMEOUT,
              ParameterMap.getKeyedInteger(map, "timeout", DEFAULT_TIMEOUT));
      httpClient
          .getParams()
          .setParameter(
              CoreProtocolPNames.USER_AGENT,
              ParameterMap.getKeyedString(map, "user-agent", DEFAULT_USER_AGENT));

      // Set the virtual host to the 'virtual-host' parameter or the host address if 'virtual-host'
      // is not present
      getMethod
          .getParams()
          .setParameter(
              ClientPNames.VIRTUAL_HOST,
              new HttpHost(
                  ParameterMap.getKeyedString(map, "virtual-host", hostAddress),
                  ParameterMap.getKeyedInteger(map, "port", DEFAULT_PORT)));

      if (ParameterMap.getKeyedBoolean(map, "http-1.0", false)) {
        httpClient
            .getParams()
            .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
      }

      for (Object okey : map.keySet()) {
        String key = okey.toString();
        if (key.matches("header_[0-9]+$")) {
          String headerName = ParameterMap.getKeyedString(map, key, null);
          String headerValue = ParameterMap.getKeyedString(map, key + "_value", null);
          getMethod.setHeader(headerName, headerValue);
        }
      }

      if (ParameterMap.getKeyedBoolean(map, "auth-enabled", false)) {
        httpClient
            .getCredentialsProvider()
            .setCredentials(
                AuthScope.ANY,
                new UsernamePasswordCredentials(
                    ParameterMap.getKeyedString(map, "auth-user", DEFAULT_USER),
                    ParameterMap.getKeyedString(map, "auth-password", DEFAULT_PASSWORD)));
        if (ParameterMap.getKeyedBoolean(map, "auth-preemptive", true)) {
          /**
           * Add an HttpRequestInterceptor that will perform preemptive auth
           *
           * @see http://hc.apache.org/httpcomponents-client-4.0.1/tutorial/html/authentication.html
           */
          HttpRequestInterceptor preemptiveAuth =
              new HttpRequestInterceptor() {

                public void process(final HttpRequest request, final HttpContext context)
                    throws IOException {

                  AuthState authState =
                      (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
                  CredentialsProvider credsProvider =
                      (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
                  HttpHost targetHost =
                      (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

                  // If not auth scheme has been initialized yet
                  if (authState.getAuthScheme() == null) {
                    AuthScope authScope =
                        new AuthScope(targetHost.getHostName(), targetHost.getPort());
                    // Obtain credentials matching the target host
                    Credentials creds = credsProvider.getCredentials(authScope);
                    // If found, generate BasicScheme preemptively
                    if (creds != null) {
                      authState.update(new BasicScheme(), creds);
                    }
                  }
                }
              };
          httpClient.addRequestInterceptor(preemptiveAuth, 0);
        }
      }

      log().debug("httpClient request with the following parameters: " + httpClient);
      log().debug("getMethod parameters: " + getMethod);
      HttpResponse response = httpClient.execute(getMethod);
      int statusCode = response.getStatusLine().getStatusCode();
      String statusText = response.getStatusLine().getReasonPhrase();
      String expectedText = ParameterMap.getKeyedString(map, "response-text", null);

      log().debug("returned results are:");

      if (!inRange(
          ParameterMap.getKeyedString(map, "response-range", DEFAULT_HTTP_STATUS_RANGE),
          statusCode)) {
        pollStatus = PollStatus.unavailable(statusText);
      } else {
        pollStatus = PollStatus.available();
      }

      if (expectedText != null) {
        String responseText = EntityUtils.toString(response.getEntity());
        if (expectedText.charAt(0) == '~') {
          if (!responseText.matches(expectedText.substring(1))) {
            pollStatus = PollStatus.unavailable("Regex Failed");
          } else pollStatus = PollStatus.available();
        } else {
          if (expectedText.equals(responseText)) pollStatus = PollStatus.available();
          else pollStatus = PollStatus.unavailable("Did not find expected Text");
        }
      }

    } catch (IOException e) {
      log().info(e.getMessage());
    } catch (URISyntaxException e) {
      log().info(e.getMessage());
    } finally {
      if (httpClient != null) {
        httpClient.getConnectionManager().shutdown();
      }
    }
    return pollStatus;
  }
コード例 #21
0
 public int getSnmpTimeout(int current) {
   return ParameterMap.getKeyedInteger(getParameters(), "timeout", current);
 }
コード例 #22
0
 public int getSnmpRetries(int current) {
   return ParameterMap.getKeyedInteger(getParameters(), "retry", current);
 }
コード例 #23
0
 public int getSnmpPort(int current) {
   return ParameterMap.getKeyedInteger(getParameters(), "port", current);
 }
コード例 #24
0
 public String getSnmpPrivProtocol(String current) {
   return ParameterMap.getKeyedString(getParameters(), "privacy-protocol", current);
 }
コード例 #25
0
 public String getDomain() {
   return ParameterMap.getKeyedString(getParameters(), "domain", "default");
 }
コード例 #26
0
 public int getSnmpMaxVarsPerPdu(int current) {
   return ParameterMap.getKeyedInteger(getParameters(), "max-vars-per-pdu", current);
 }
コード例 #27
0
 public String getStoreByIfAlias() {
   return ParameterMap.getKeyedString(getParameters(), "storeByIfAlias", "false");
 }
コード例 #28
0
 public int getSnmpMaxRequestSize(int current) {
   return ParameterMap.getKeyedInteger(getParameters(), "max-request-size", current);
 }
コード例 #29
0
  /**
   * {@inheritDoc}
   *
   * <p>Poll the specified address for service availability.
   *
   * <p>During the poll an attempt is made to call the specified external script or program. If the
   * connection request is successful, the banner line returned as standard output by the script or
   * program is parsed for a partial match with the banner string specified in the poller
   * configuration. Provided that the script's response is valid we set the service status to
   * SERVICE_AVAILABLE and return.
   *
   * <p>The timeout is handled by ExecRunner and is also passed as a parameter to the script or
   * program being called.
   */
  public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    NetworkInterface<InetAddress> iface = svc.getNetInterface();

    //
    // Process parameters
    //
    ThreadCategory log = ThreadCategory.getInstance(getClass());

    //
    // Get interface address from NetworkInterface
    //
    if (iface.getType() != NetworkInterface.TYPE_INET)
      throw new NetworkInterfaceNotSupportedException(
          "Unsupported interface type, only TYPE_INET currently supported");

    TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT);

    String hoption = ParameterMap.getKeyedString(parameters, "hoption", "--hostname");
    String toption = ParameterMap.getKeyedString(parameters, "toption", "--timeout");
    //
    // convert timeout to seconds for ExecRunner
    //
    String args = ParameterMap.getKeyedString(parameters, "args", null);

    // Script
    //
    String script = ParameterMap.getKeyedString(parameters, "script", null);
    if (script == null) {
      throw new RuntimeException(
          "GpMonitor: required parameter 'script' is not present in supplied properties.");
    }

    // BannerMatch
    //
    String strBannerMatch = (String) parameters.get("banner");

    // Script standard output
    //
    String scriptoutput = "";

    // Script error output
    //
    String scripterror = "";

    // Get the address instance.
    //
    InetAddress ipv4Addr = (InetAddress) iface.getAddress();

    final String hostAddress = InetAddressUtils.str(ipv4Addr);
    if (log.isDebugEnabled())
      log.debug(
          "poll: address = "
              + hostAddress
              + ", script = "
              + script
              + ", arguments = "
              + args
              + ", "
              + tracker);

    // Give it a whirl
    //
    PollStatus serviceStatus = PollStatus.unavailable();

    for (tracker.reset();
        tracker.shouldRetry() && !serviceStatus.isAvailable();
        tracker.nextAttempt()) {
      try {
        tracker.startAttempt();

        int exitStatus = 100;

        // Some scripts, such as Nagios check scripts, look for -H and -t versus --hostname and
        // --timeout. If the optional parameter option-type is set to short, then the former
        // will be used.

        int timeoutInSeconds = (int) tracker.getTimeoutInSeconds();

        ExecRunner er = new ExecRunner();
        er.setMaxRunTimeSecs(timeoutInSeconds);
        if (args == null)
          exitStatus =
              er.exec(
                  script
                      + " "
                      + hoption
                      + " "
                      + hostAddress
                      + " "
                      + toption
                      + " "
                      + timeoutInSeconds);
        else
          exitStatus =
              er.exec(
                  script
                      + " "
                      + hoption
                      + " "
                      + hostAddress
                      + " "
                      + toption
                      + " "
                      + timeoutInSeconds
                      + " "
                      + args);

        double responseTime = tracker.elapsedTimeInMillis();

        if (exitStatus != 0) {
          scriptoutput = er.getOutString();
          serviceStatus =
              logDown(
                  Level.DEBUG,
                  script
                      + " failed with exit code "
                      + exitStatus
                      + ". Standard out: "
                      + scriptoutput);
        }
        if (er.isMaxRunTimeExceeded()) {

          serviceStatus = logDown(Level.DEBUG, script + " failed. Timeout exceeded");

        } else {
          if (exitStatus == 0) {
            scriptoutput = er.getOutString();
            scripterror = er.getErrString();
            if (!scriptoutput.equals("")) log.debug(script + " output  = " + scriptoutput);
            else log.debug(script + " returned no output");
            if (!scripterror.equals("")) log.debug(script + " error = " + scripterror);
            if (strBannerMatch == null || strBannerMatch.equals("*")) {

              serviceStatus = PollStatus.available(responseTime);

            } else {
              if (scriptoutput.indexOf(strBannerMatch) > -1) {
                serviceStatus = PollStatus.available(responseTime);
              } else {
                serviceStatus =
                    PollStatus.unavailable(
                        script
                            + "banner not contained in output banner='"
                            + strBannerMatch
                            + "' output='"
                            + scriptoutput
                            + "'");
              }
            }
          }
        }

      } catch (ArrayIndexOutOfBoundsException e) {

        serviceStatus = logDown(Level.DEBUG, script + " ArrayIndexOutOfBoundsException", e);

      } catch (IOException e) {

        serviceStatus =
            logDown(
                Level.DEBUG, "IOException occurred. Check for proper operation of " + script, e);

      } catch (Throwable e) {

        serviceStatus = logDown(Level.DEBUG, script + "Exception occurred", e);
      }
    }

    //
    // return the status of the service
    //
    log.debug("poll: GP - serviceStatus= " + serviceStatus + "  " + hostAddress);
    return serviceStatus;
  }
コード例 #30
0
 public String getIfAliasComment() {
   return ParameterMap.getKeyedString(getParameters(), "ifAliasComment", null);
 }