Search in sources :

Example 1 with Definition

use of org.opennms.netmgt.config.wsman.Definition in project opennms by OpenNMS.

the class WsManCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", null);
    if (collectionName == null) {
        throw new IllegalArgumentException("Collector configuration does not include the required 'collection' parameter.");
    }
    final Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException("No collection found with name: " + collectionName);
    }
    final OnmsNode node = m_nodeDao.get(agent.getNodeId());
    if (node == null) {
        throw new IllegalArgumentException("Could not find node with id: " + agent.getNodeId());
    }
    final Definition agentConfig = m_wsManConfigDao.getAgentConfig(agent.getAddress());
    final Groups groups = new Groups(m_wsManDataCollectionConfigDao.getGroupsForAgent(collection, agent, agentConfig, node));
    runtimeAttributes.put(WSMAN_AGENT_CONFIG_KEY, agentConfig);
    runtimeAttributes.put(WSMAN_GROUPS_KEY, groups);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) Groups(org.opennms.netmgt.config.wsman.Groups) Definition(org.opennms.netmgt.config.wsman.Definition) Collection(org.opennms.netmgt.config.wsman.Collection)

Example 2 with Definition

use of org.opennms.netmgt.config.wsman.Definition in project opennms by OpenNMS.

the class WSManDataCollectionConfigDaoJaxbTest method canEvaluteSystemDefinitionRules.

@Test
public void canEvaluteSystemDefinitionRules() throws UnknownHostException {
    OnmsNode node = mock(OnmsNode.class);
    CollectionAgent agent = mock(CollectionAgent.class);
    Definition config = new Definition();
    config.setProductVendor("Dell Inc.");
    config.setProductVersion(" iDRAC 6");
    SystemDefinition sysDef = new SystemDefinition();
    sysDef.addRule("#productVendor matches 'Dell.*' and #productVersion matches '.*DRAC.*'");
    assertTrue("agent should be matched", WSManDataCollectionConfigDaoJaxb.isAgentSupportedBySystemDefinition(sysDef, agent, config, node));
}
Also used : SystemDefinition(org.opennms.netmgt.config.wsman.SystemDefinition) OnmsNode(org.opennms.netmgt.model.OnmsNode) SystemDefinition(org.opennms.netmgt.config.wsman.SystemDefinition) Definition(org.opennms.netmgt.config.wsman.Definition) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 3 with Definition

use of org.opennms.netmgt.config.wsman.Definition in project opennms by OpenNMS.

the class WSManCollectorComplianceTest method getRequiredBeans.

public Map<String, Object> getRequiredBeans() {
    OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(anyInt())).thenReturn(node);
    Definition agentConfig = new Definition();
    WSManConfigDao wsManConfigDao = mock(WSManConfigDao.class);
    when(wsManConfigDao.getAgentConfig(InetAddrUtils.getLocalHostAddress())).thenReturn(agentConfig);
    WsmanDatacollectionConfig config = new WsmanDatacollectionConfig();
    config.setRrdRepository("target");
    Collection collection = new Collection();
    collection.setRrd(new Rrd());
    WSManDataCollectionConfigDao wsManDataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
    when(wsManDataCollectionConfigDao.getCollectionByName(COLLECTION)).thenReturn(collection);
    when(wsManDataCollectionConfigDao.getConfig()).thenReturn(config);
    return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("wsManConfigDao", wsManConfigDao).put("wsManDataCollectionConfigDao", wsManDataCollectionConfigDao).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) WsmanDatacollectionConfig(org.opennms.netmgt.config.wsman.WsmanDatacollectionConfig) Rrd(org.opennms.netmgt.config.wsman.Rrd) Definition(org.opennms.netmgt.config.wsman.Definition) Collection(org.opennms.netmgt.config.wsman.Collection) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao)

Example 4 with Definition

use of org.opennms.netmgt.config.wsman.Definition in project opennms by OpenNMS.

the class WSManCollectorTest method canSuccesfullyCollectFromGroupWithNoAttributes.

@Test
public void canSuccesfullyCollectFromGroupWithNoAttributes() throws CollectionInitializationException, CollectionException {
    OnmsNode node = mock(OnmsNode.class);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(0)).thenReturn(node);
    WSManConfigDao configDao = mock(WSManConfigDao.class);
    when(configDao.getAgentConfig(any())).thenReturn(new Definition());
    Collection collection = new Collection();
    WSManDataCollectionConfigDao dataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
    when(dataCollectionConfigDao.getCollectionByName("default")).thenReturn(collection);
    WsManCollector collector = new WsManCollector();
    collector.setWSManClientFactory(mock(WSManClientFactory.class));
    collector.setWSManConfigDao(configDao);
    collector.setWSManDataCollectionConfigDao(dataCollectionConfigDao);
    collector.setNodeDao(nodeDao);
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
    Map<String, Object> collectionParams = Maps.newHashMap();
    collectionParams.put("collection", "default");
    collectionParams.putAll(collector.getRuntimeAttributes(agent, collectionParams));
    CollectionSet collectionSet = collector.collect(agent, collectionParams);
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    assertEquals(0, CollectionSetUtils.getAttributesByName(collectionSet).size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) NodeDao(org.opennms.netmgt.dao.api.NodeDao) Collection(org.opennms.netmgt.config.wsman.Collection) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 5 with Definition

use of org.opennms.netmgt.config.wsman.Definition in project opennms by OpenNMS.

the class WSManMonitorTest method poll.

private static PollStatus poll(String rule, Node response) {
    String resourceUri = "mock-resource-uri";
    Map<String, String> selectors = Maps.newHashMap();
    selectors.put("mock-selector-a", "a1");
    selectors.put("mock-selector-b", "b1");
    Definition agentConfig = new Definition();
    WSManConfigDao configDao = mock(WSManConfigDao.class);
    when(configDao.getAgentConfig(anyObject())).thenReturn(agentConfig);
    WSManClient client = mock(WSManClient.class);
    when(client.get(resourceUri, selectors)).thenReturn(response);
    WSManClientFactory clientFactory = mock(WSManClientFactory.class);
    when(clientFactory.getClient(anyObject())).thenReturn(client);
    WsManMonitor monitor = new WsManMonitor();
    monitor.setWSManConfigDao(configDao);
    monitor.setWSManClientFactory(clientFactory);
    Map<String, Object> parameters = Maps.newHashMap();
    parameters.put(WsManMonitor.RESOURCE_URI_PARAM, resourceUri);
    selectors.entrySet().stream().forEach(e -> parameters.put(WsManMonitor.SELECTOR_PARAM_PREFIX + e.getKey(), e.getValue()));
    parameters.put(WsManMonitor.RULE_PARAM, rule);
    InetAddress localhost;
    try {
        localhost = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        throw new RuntimeException(e);
    }
    MonitoredService svc = mock(MonitoredService.class);
    when(svc.getAddress()).thenReturn(localhost);
    return monitor.poll(svc, parameters);
}
Also used : UnknownHostException(java.net.UnknownHostException) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) Matchers.anyObject(org.mockito.Matchers.anyObject) WSManClient(org.opennms.core.wsman.WSManClient) InetAddress(java.net.InetAddress)

Aggregations

Definition (org.opennms.netmgt.config.wsman.Definition)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Collection (org.opennms.netmgt.config.wsman.Collection)3 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)3 Test (org.junit.Test)2 WSManClientFactory (org.opennms.core.wsman.WSManClientFactory)2 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)2 WSManDataCollectionConfigDao (org.opennms.netmgt.dao.WSManDataCollectionConfigDao)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 WSManClient (org.opennms.core.wsman.WSManClient)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 Groups (org.opennms.netmgt.config.wsman.Groups)1 Rrd (org.opennms.netmgt.config.wsman.Rrd)1 SystemDefinition (org.opennms.netmgt.config.wsman.SystemDefinition)1 WsmanDatacollectionConfig (org.opennms.netmgt.config.wsman.WsmanDatacollectionConfig)1 MonitoredService (org.opennms.netmgt.poller.MonitoredService)1