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