use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.
the class HttpCollectorIT method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
if (m_nodeDao.findByLabel("testnode").size() == 0) {
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("testnode");
builder.addInterface(InetAddressUtils.normalize(m_testHostName)).setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(getServiceType("ICMP"));
builder.addService(getServiceType("HTTP"));
builder.addService(getServiceType("HTTPS"));
OnmsNode n = builder.getCurrentNode();
assertNotNull(n);
m_nodeDao.save(n);
m_nodeDao.flush();
}
m_collector = new HttpCollector();
Collection<OnmsIpInterface> ifaces = m_ipInterfaceDao.findByIpAddress(m_testHostName);
assertEquals(1, ifaces.size());
OnmsIpInterface iface = ifaces.iterator().next();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("collection", "default");
m_collector.initialize();
m_collectionSpecification = CollectorTestUtils.createCollectionSpec("HTTP", m_collector, "default");
m_httpsCollectionSpecification = CollectorTestUtils.createCollectionSpec("HTTPS", m_collector, "default");
m_collectionAgent = DefaultCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
m_resourceStorageDao.setRrdDirectory(snmpRrdDirectory.getParentFile());
}
use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.
the class SnmpCollectorMinMaxValIT method setUp.
@Before
public void setUp() throws Exception {
final Properties p = new Properties();
p.setProperty("log4j.logger.org.opennms.netmgt.snmp.SnmpUtils", "DEBUG");
MockLogAppender.setupLogging(p);
assertTrue(m_snmpPeerFactory instanceof ProxySnmpAgentConfigFactory);
SnmpPeerFactory.setInstance(m_snmpPeerFactory);
m_agentConfig = m_snmpPeerFactory.getAgentConfig(InetAddressUtils.addr(TEST_HOST_ADDRESS));
m_rrdStrategy = new JRobinRrdStrategy();
m_resourceStorageDao = new FilesystemResourceStorageDao();
File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
m_resourceStorageDao.setRrdDirectory(snmpRrdDirectory.getParentFile());
OnmsIpInterface iface = null;
OnmsNode testNode = null;
Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
if (testNodes == null || testNodes.size() < 1) {
NetworkBuilder builder = new NetworkBuilder();
builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
builder.addSnmpInterface(1).setIfName("lo0").setPhysAddr("00:11:22:33:44");
builder.addSnmpInterface(2).setIfName("gif0").setPhysAddr("00:11:22:33:45").setIfType(55);
builder.addSnmpInterface(3).setIfName("stf0").setPhysAddr("00:11:22:33:46").setIfType(57);
InterfaceBuilder ifBldr = builder.addInterface(TEST_HOST_ADDRESS).setIsSnmpPrimary("P");
ifBldr.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true);
testNode = builder.getCurrentNode();
assertNotNull(testNode);
m_nodeDao.save(testNode);
m_nodeDao.flush();
} else {
testNode = testNodes.iterator().next();
}
final Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
assertEquals(1, ifaces.size());
iface = ifaces.iterator().next();
LOG.debug("iface = {}", iface);
final SnmpCollector collector = new SnmpCollector();
collector.initialize();
m_collectionSpecification = CollectorTestUtils.createCollectionSpec("SNMP", collector, "default");
m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
}
use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.
the class SnmpCollectorWithMibPropertiesIT method setUp.
/**
* Sets up the test.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
MockServiceCollector.setDelegate(null);
MockLogAppender.setupLogging();
m_rrdStrategy = new JRobinRrdStrategy();
m_resourceStorageDao = new FilesystemResourceStorageDao();
File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
m_resourceStorageDao.setRrdDirectory(snmpRrdDirectory.getParentFile());
m_testHostName = InetAddressUtils.str(InetAddress.getLocalHost());
OnmsIpInterface iface = null;
OnmsNode testNode = null;
Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
if (testNodes == null || testNodes.size() < 1) {
NetworkBuilder builder = new NetworkBuilder();
// Fake Cisco SysOID
builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.9.1.9999");
builder.addSnmpInterface(1).setIfName("Fa0/0").setPhysAddr("44:33:22:11:00").setIfType(6).setCollectionEnabled(true).addIpInterface(m_testHostName).setIsSnmpPrimary("P");
builder.addSnmpInterface(18).setIfName("Se1/0.102").setIfAlias("Conexion Valencia").setIfType(32).setCollectionEnabled(true).addIpInterface("10.0.0.1").setIsSnmpPrimary("N");
testNode = builder.getCurrentNode();
assertNotNull(testNode);
m_nodeDao.save(testNode);
m_nodeDao.flush();
} else {
testNode = testNodes.iterator().next();
}
Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
assertEquals(2, ifaces.size());
iface = ifaces.iterator().next();
SnmpPeerFactory.setInstance(m_snmpPeerFactory);
SnmpCollector collector = new SnmpCollector();
collector.initialize();
m_collectionSpecification = CollectorTestUtils.createCollectionSpec("SNMP", collector, "default");
m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
}
use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.
the class EnLinkdIT method testDeleteBridgeC.
@Test
public void testDeleteBridgeC() {
ABCTopology topology = new ABCTopology();
NetworkBuilder nb = new NetworkBuilder();
nb.addNode("nodeA").setForeignSource("linkd").setForeignId("nodeA").setSysObjectId("0.0").setSysName("nodeA").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.1").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
nb.addNode("nodeB").setForeignSource("linkd").setForeignId("nodeB").setSysObjectId("0.0").setSysName("nodeB").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.2").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
nb.addNode("nodeC").setForeignSource("linkd").setForeignId("nodeC").setSysObjectId("0.0").setSysName("nodeC").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.3").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
topology.nodeAId = nodeA.getId();
topology.nodeBId = nodeB.getId();
topology.nodeCId = nodeC.getId();
topology.nodeA = nodeA;
topology.nodeB = nodeB;
topology.nodeC = nodeC;
BridgeBridgeLink ablink = new BridgeBridgeLink();
ablink.setNode(nodeA);
ablink.setBridgePort(topology.portAB);
ablink.setDesignatedNode(nodeB);
ablink.setDesignatedPort(topology.portBA);
ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(ablink);
BridgeBridgeLink bclink = new BridgeBridgeLink();
bclink.setNode(nodeC);
bclink.setBridgePort(topology.portCB);
bclink.setDesignatedNode(nodeB);
bclink.setDesignatedPort(topology.portBC);
bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(bclink);
BridgeMacLink mac1 = new BridgeMacLink();
mac1.setNode(nodeA);
mac1.setBridgePort(topology.portA);
mac1.setMacAddress(topology.mac1);
mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac1);
BridgeMacLink mac2 = new BridgeMacLink();
mac2.setNode(nodeB);
mac2.setBridgePort(topology.portB);
mac2.setMacAddress(topology.mac2);
mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac2);
BridgeMacLink mac3 = new BridgeMacLink();
mac3.setNode(nodeC);
mac3.setBridgePort(topology.portC);
mac3.setMacAddress(topology.mac3);
mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac3);
m_bridgeMacLinkDao.flush();
m_bridgeBridgeLinkDao.flush();
assertEquals(3, m_bridgeMacLinkDao.countAll());
assertEquals(2, m_bridgeBridgeLinkDao.countAll());
assertNotNull(m_bridgeTopologyDao);
m_linkd.getQueryManager().loadBridgeTopology();
assertEquals(1, m_linkd.getQueryManager().getAllBroadcastDomains().size());
BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
assertNotNull(nodeAbd);
BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
assertNotNull(nodeBbd);
assertEquals(nodeAbd, nodeBbd);
BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
assertNotNull(nodeCbd);
assertEquals(nodeAbd, nodeCbd);
assertTrue(nodeAbd.hasRootBridge());
assertEquals(nodeAbd.getRootBridgeId().intValue(), nodeB.getId().intValue());
assertTrue(nodeAbd.containBridgeId(nodeA.getId()));
assertTrue(nodeAbd.containBridgeId(nodeB.getId()));
assertTrue(nodeAbd.containBridgeId(nodeC.getId()));
nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
assertNotNull(nodeAbd.getRootBridgeId());
topology.check(nodeAbd);
m_linkd.deleteNode(nodeC.getId());
assertEquals(1, m_linkd.getQueryManager().getAllBroadcastDomains().size());
BroadcastDomain domain = m_linkd.getQueryManager().getAllBroadcastDomains().iterator().next();
topology.checkAB(domain);
}
use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.
the class AlarmRestServiceIT method afterServletStart.
@Override
protected void afterServletStart() throws Exception {
ALARM_COUNTER.set(0);
MockLogAppender.setupLogging(true, "DEBUG");
final OnmsCategory linux = createCategory("Linux");
final OnmsCategory servers = createCategory("LinuxServers");
final OnmsCategory macOS = createCategory("macOS");
final OnmsServiceType icmp = new OnmsServiceType("ICMP");
m_databasePopulator.getServiceTypeDao().save(icmp);
m_databasePopulator.getServiceTypeDao().flush();
final NetworkBuilder builder = new NetworkBuilder();
// Add a node with 2 categories, since this will really exercise the Criteria
// aliases since node-to-category is a many-to-many relationship
node1 = createNode(builder, "server01", "192.168.1.1", new OnmsCategory[] { linux, servers });
// simpler node to have multi-node matching
node2 = createNode(builder, "server02", "192.168.1.2", new OnmsCategory[] { macOS });
// node with strange values to test double-decoding of the FIQL engine
node3 = createNode(builder, SERVER3_NAME, "192.168.1.3", new OnmsCategory[] {});
createAlarm(node1, "uei.opennms.org/test/somethingWentWrong", OnmsSeverity.MAJOR, 0);
createAlarm(node1, "uei.opennms.org/test/somethingIsStillHappening", OnmsSeverity.WARNING, 1);
createAlarm(node1, "uei.opennms.org/test/somethingIsOkNow", OnmsSeverity.NORMAL, 2);
createAlarm(node2, "uei.opennms.org/test/somethingWentWrong", OnmsSeverity.MAJOR, 10);
createAlarm(node2, "uei.opennms.org/test/somethingIsStillHappening", OnmsSeverity.WARNING, 11);
createAlarm(node2, "uei.opennms.org/test/somethingIsOkNow", OnmsSeverity.NORMAL, 12);
createAlarm(node2, "uei.opennms.org/test/somethingIsStillOk", OnmsSeverity.NORMAL, 13);
createAlarm(node3, "uei.opennms.org/test/somethingIsStillOk", OnmsSeverity.NORMAL, 20);
}
Aggregations