コード例 #1
0
ファイル: WmiCollector.java プロジェクト: nemi1990/opennms
 /** {@inheritDoc} */
 @Override
 public void release(final CollectionAgent agent) {
   final WmiAgentState nodeState = m_scheduledNodes.get((Integer) agent.getNodeId());
   if (nodeState != null) {
     m_scheduledNodes.remove((Integer) agent.getNodeId());
   }
 }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    jmxNodeInfo = new JMXNodeInfo(0);
    jmxCollector = new JMXCollectorImpl();
    platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("org.opennms.netmgt.collectd.jmxhelper:type=JmxTest");
    JmxTestMBean testMBean = new JmxTest();
    platformMBeanServer.registerMBean(testMBean, objectName);

    collectionAgent = EasyMock.createMock(CollectionAgent.class);
    EasyMock.expect(collectionAgent.getAddress()).andReturn(InetAddress.getLocalHost()).anyTimes();
    EasyMock.expect(
            collectionAgent.getAttribute("org.opennms.netmgt.collectd.JMXCollector.nodeInfo"))
        .andReturn(jmxNodeInfo)
        .anyTimes();
    EasyMock.expect(collectionAgent.getNodeId()).andReturn(0).anyTimes();
    EasyMock.expect(collectionAgent.getStorageDir()).andReturn(new File("")).anyTimes();

    EasyMock.replay(collectionAgent);

    FileInputStream configFileStream =
        new FileInputStream("src/test/resources/etc/JmxCollectorConfigTest.xml");
    logger.debug("ConfigFileStream check '{}'", configFileStream.available());
    jmxConfigFactory = new JMXDataCollectionConfigFactory(configFileStream);
    JMXDataCollectionConfigFactory.setInstance(jmxConfigFactory);
  }
コード例 #3
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);
  }
コード例 #4
0
ファイル: WmiCollector.java プロジェクト: nemi1990/opennms
  /** {@inheritDoc} */
  @Override
  public void initialize(final CollectionAgent agent, final Map<String, Object> parameters) {
    LOG.debug("initialize: Initializing WMI collection for agent: {}", agent);
    final Integer scheduledNodeKey = new Integer(agent.getNodeId());
    WmiAgentState nodeState = m_scheduledNodes.get(scheduledNodeKey);

    if (nodeState != null) {
      LOG.info(
          "initialize: Not scheduling interface for WMI collection: {}", nodeState.getAddress());
      final StringBuffer sb = new StringBuffer();
      sb.append("initialize service: ");
      sb.append(" for address: ");
      sb.append(nodeState.getAddress());
      sb.append(" already scheduled for collection on node: ");
      sb.append(agent);
      LOG.debug(sb.toString());
      throw new IllegalStateException(sb.toString());
    } else {
      nodeState = new WmiAgentState(agent.getInetAddress(), parameters);
      LOG.info("initialize: Scheduling interface for collection: {}", nodeState.getAddress());
      m_scheduledNodes.put(scheduledNodeKey, nodeState);
    }
  }
コード例 #5
0
ファイル: JMXCollector.java プロジェクト: garylai578/opennms
 JMXCollectionResource(CollectionAgent agent, String resourceName) {
   super(agent);
   m_resourceName = resourceName;
   m_nodeId = agent.getNodeId();
 }
コード例 #6
0
ファイル: WmiCollector.java プロジェクト: nemi1990/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(agent);
    collectionSet.setCollectionTimestamp(new Date());

    // 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 = new WmiSingleInstanceCollectionResource(agent);
              }

              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.getResources().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;
  }