use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class ProvisionerIT method testSaveCategoriesOnUpdateNodeAttributes.
@Test(timeout = 300000)
public void testSaveCategoriesOnUpdateNodeAttributes() throws Exception {
final EventAnticipator eventAnticipator = m_mockEventIpcManager.getEventAnticipator();
final String TEST_CATEGORY = "TEST_CATEGORY";
final String OLD_LABEL = "apknd";
final String NEW_LABEL = "apknd-new";
importFromResource("classpath:/tec_dump.xml.smalltest", Boolean.TRUE.toString());
getScanExecutor().pause();
m_provisioner.scheduleRescanForExistingNodes();
final Collection<OnmsNode> nodes = m_nodeDao.findByLabel(OLD_LABEL);
assertNotNull(nodes);
assertEquals(1, nodes.size());
OnmsNode node = nodes.iterator().next();
assertNotNull(node);
OnmsNode nodeCopy = new OnmsNode(m_locationDao.getDefaultLocation(), OLD_LABEL);
nodeCopy.setId(node.getId());
nodeCopy.setLabelSource(NodeLabelSource.USER);
assertNotSame(node, nodeCopy);
assertEquals(OLD_LABEL, node.getLabel());
assertFalse(node.hasCategory(TEST_CATEGORY));
// Create a policy that will apply the category to the node
final NodeCategorySettingPolicy policy = new NodeCategorySettingPolicy();
policy.setCategory(TEST_CATEGORY);
policy.setLabel(OLD_LABEL);
// Apply the policy
nodeCopy = policy.apply(nodeCopy);
assertTrue(nodeCopy.getRequisitionedCategories().contains(TEST_CATEGORY));
final EventBuilder eb = new EventBuilder(EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "OnmsNode.mergeNodeAttributes");
eb.setNodeid(node.getId());
eb.addParam("oldNodeLabel", OLD_LABEL);
eb.addParam("oldNodeLabelSource", "U");
eb.addParam("newNodeLabel", NEW_LABEL);
eb.addParam("newNodeLabelSource", "U");
eventAnticipator.anticipateEvent(eb.getEvent());
// Change the label of the node so that we can trigger a NODE_LABEL_CHANGED_EVENT_UEI event
nodeCopy.setLabel(NEW_LABEL);
nodeCopy.setLabelSource(NodeLabelSource.USER);
assertFalse(node.getLabel().equals(nodeCopy.getLabel()));
m_provisionService.updateNodeAttributes(nodeCopy);
// Flush here to force a write so we are sure that the OnmsCategoryCollection are correctly created
m_nodeDao.flush();
// Query by the new node label
final OnmsNode node2 = m_nodeDao.findByLabel(NEW_LABEL).iterator().next();
assertTrue(node2.hasCategory(TEST_CATEGORY));
eventAnticipator.resetUnanticipated();
eventAnticipator.verifyAnticipated();
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class DragonWaveNodeSwitchingIT method testInitialSetup.
@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "192.168.255.22", port = 161, resource = "classpath:/dw/walks/node1-walk.properties") })
public void testInitialSetup() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
final InetAddress iface = InetAddressUtils.addr("192.168.255.22");
final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("SNMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("ICMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
importResource("classpath:/dw/import/dw_test_import.xml");
anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
final OnmsNode onmsNode = m_nodeDao.findByForeignId("dw", "arthur");
final String sysObjectId = onmsNode.getSysObjectId();
assertEquals(".1.3.6.1.4.1.7262.2.3", sysObjectId);
m_mockSnmpDataProvider.setDataForAddress(new SnmpAgentAddress(iface, 161), m_resourceLoader.getResource("classpath:/dw/walks/node3-walk.properties"));
assertEquals(".1.3.6.1.4.1.7262.1", SnmpUtils.get(m_snmpPeerFactory.getAgentConfig(iface), SnmpObjId.get(".1.3.6.1.2.1.1.2.0")).toDisplayString());
anticipator.reset();
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_UPDATED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
importResource("classpath:/dw/import/dw_test_import.xml");
anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
anticipator.reset();
anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
final NodeScan scan2 = m_provisioner.createNodeScan(nextNodeId, onmsNode.getForeignSource(), onmsNode.getForeignId(), onmsNode.getLocation());
runScan(scan2);
m_nodeDao.flush();
anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
final OnmsNode node = m_nodeDao.findByForeignId("dw", "arthur");
final String sysObjectId2 = node.getSysObjectId();
assertEquals(".1.3.6.1.4.1.7262.1", sysObjectId2);
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class NewSuspectScanIT method testScanNewSuspect.
@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "198.51.100.201", resource = "classpath:/snmpTestData3.properties"), @JUnitSnmpAgent(host = "198.51.100.204", resource = "classpath:/snmpTestData3.properties") })
public void testScanNewSuspect() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
//Verify empty database
assertEquals(1, getDistPollerDao().countAll());
assertEquals(0, getNodeDao().countAll());
assertEquals(0, getInterfaceDao().countAll());
assertEquals(0, getMonitoredServiceDao().countAll());
assertEquals(0, getServiceTypeDao().countAll());
assertEquals(0, getSnmpInterfaceDao().countAll());
final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).setService("SNMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).setService("SNMP").getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, "my-custom-location");
runScan(scan);
anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
//Verify distpoller count
assertEquals(1, getDistPollerDao().countAll());
//Verify node count
assertEquals(1, getNodeDao().countAll());
OnmsNode onmsNode = getNodeDao().get(nextNodeId);
assertEquals(null, onmsNode.getForeignSource());
assertEquals(null, onmsNode.getForeignId());
assertEquals("my-custom-location", onmsNode.getLocation().getLocationName());
final StringBuffer errorMsg = new StringBuffer();
//Verify ipinterface count
for (final OnmsIpInterface iface : getInterfaceDao().findAll()) {
errorMsg.append(iface.toString());
}
assertEquals(errorMsg.toString(), 2, getInterfaceDao().countAll());
//Verify ifservices count - discover snmp service on other if
assertEquals("Unexpected number of services found.", 2, getMonitoredServiceDao().countAll());
//Verify service count
assertEquals(1, getServiceTypeDao().countAll());
//Verify snmpInterface count
assertEquals(6, getSnmpInterfaceDao().countAll());
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class ThresholdingVisitorIT method setUp.
@Before
public void setUp() throws Exception {
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_hrStorageProperties = new HashMap<Integer, File>();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(new File(m_fileAnticipator.getTempDir(), "snmp"));
m_filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(m_filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
m_filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(m_filterDao);
EasyMock.replay(m_filterDao);
m_anticipator = new EventAnticipator();
MockEventIpcManager eventMgr = new MockEventIpcManager();
eventMgr.setEventAnticipator(m_anticipator);
eventMgr.setSynchronous(true);
EventIpcManager eventdIpcMgr = (EventIpcManager) eventMgr;
EventIpcManagerFactory.setIpcManager(eventdIpcMgr);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<Event>();
}
use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.
the class MockNetworkTest method testEventProcessing.
/**
* @param element
*/
private void testEventProcessing(MockElement element) {
m_pollerConfig.setNodeOutageProcessingEnabled(false);
EventAnticipator anticipator = m_eventMgr.getEventAnticipator();
String nlsUei = EventConstants.NODE_LOST_SERVICE_EVENT_UEI;
String nrsUei = EventConstants.NODE_REGAINED_SERVICE_EVENT_UEI;
anticipateServiceEvents(anticipator, element, nlsUei);
element.bringDown();
assertFalse(0 == anticipator.waitForAnticipated(0).size());
anticipator.reset();
anticipateServiceEvents(anticipator, element, nrsUei);
element.bringUp();
assertFalse(0 == anticipator.waitForAnticipated(0).size());
anticipator.reset();
anticipateServiceEvents(anticipator, element, nlsUei);
element.bringDown();
MockVisitor lostSvcSender = new MockVisitorAdapter() {
@Override
public void visitService(MockService svc) {
Event event = MockEventUtil.createEvent("Test", EventConstants.NODE_LOST_SERVICE_EVENT_UEI, svc.getNodeId(), svc.getIpAddr(), svc.getSvcName(), String.valueOf(PollStatus.SERVICE_UNAVAILABLE));
m_eventMgr.sendNow(event);
}
};
element.visit(lostSvcSender);
assertEquals(0, anticipator.waitForAnticipated(0).size());
anticipator.reset();
anticipateServiceEvents(anticipator, element, nrsUei);
element.bringUp();
MockVisitor gainedSvcSender = new MockVisitorAdapter() {
@Override
public void visitService(MockService svc) {
Event event = MockEventUtil.createEvent("Test", EventConstants.NODE_REGAINED_SERVICE_EVENT_UEI, svc.getNodeId(), svc.getIpAddr(), svc.getSvcName(), null);
m_eventMgr.sendNow(event);
}
};
element.visit(gainedSvcSender);
m_eventMgr.finishProcessingEvents();
assertEquals(0, anticipator.waitForAnticipated(0).size());
assertEquals(0, anticipator.getUnanticipatedEvents().size());
MockNode node = m_network.getNode(1);
Event nodeEvent = MockEventUtil.createNodeDownEvent("Test", node);
anticipator.reset();
m_eventMgr.sendNow(nodeEvent);
m_eventMgr.finishProcessingEvents();
assertEquals(0, anticipator.waitForAnticipated(0).size());
assertEquals(1, anticipator.getUnanticipatedEvents().size());
}
Aggregations