use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class PersistRegexSelectorStrategyTest method setUp.
@Before
public void setUp() throws Exception {
ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
String localhost = InetAddress.getLocalHost().getHostAddress();
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("myNode");
builder.addInterface(localhost).setIsManaged("M").setIsSnmpPrimary("P");
OnmsNode node = builder.getCurrentNode();
node.setId(1);
OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next();
EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes();
EasyMock.replay(ipInterfaceDao);
Package pkg = new Package();
pkg.setName("junitTestPackage");
Filter filter = new Filter();
filter.setContent("IPADDR != '0.0.0.0'");
pkg.setFilter(filter);
Service service = new Service();
service.setName("SNMP");
pkg.addService(service);
Map<String, Object> map = new TreeMap<String, Object>();
List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters();
for (org.opennms.netmgt.config.collectd.Parameter p : params) {
map.put(p.getKey(), p.getValue());
}
map.put("collection", "default");
serviceParams = new ServiceParameters(map);
LocationAwareSnmpClient locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory());
PlatformTransactionManager ptm = new MockPlatformTransactionManager();
SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(1, ipInterfaceDao, ptm);
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, serviceParams, new MockDataCollectionConfigDao(), locationAwareSnmpClient);
org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
rt.setName("myResourceType");
StorageStrategy storageStrategy = new StorageStrategy();
storageStrategy.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
rt.setStorageStrategy(storageStrategy);
PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
persistenceSelectorStrategy.setClazz("org.opennms.netmgt.collectd.PersistRegexSelectorStrategy");
Parameter param = new Parameter();
param.setKey(PersistRegexSelectorStrategy.MATCH_EXPRESSION);
param.setValue("#name matches '^agalue.*$'");
persistenceSelectorStrategy.addParameter(param);
rt.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, snmpCollection, rt);
resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));
AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
MibObject mibObject = new MibObject();
mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
mibObject.setInstance("1");
mibObject.setAlias("name");
mibObject.setType("string");
StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType);
SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
resourceA.setAttributeValue(attributeType, snmpValue);
resourceB = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.2"));
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class SnmpCollectorIT method setUp.
@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();
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);
builder.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true).addIpInterface(m_testHostName).setIsSnmpPrimary("P");
testNode = builder.getCurrentNode();
assertNotNull(testNode);
m_nodeDao.save(testNode);
m_nodeDao.flush();
} else {
testNode = testNodes.iterator().next();
}
Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
assertEquals(1, 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);
m_agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.getLocalHostAddress());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.
public void testGetCategoriesStatus() {
View view = new View();
Section section = new Section();
section.setSectionName("Section One");
section.addCategory("Category One");
OnmsOutage outage = new OnmsOutage();
Collection<OnmsOutage> outages = new ArrayList<>();
outage.setId(300);
OnmsServiceType svcType = new OnmsServiceType();
svcType.setId(3);
svcType.setName("HTTP");
OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("superLabel");
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
iface.setSnmpInterface(snmpIface);
// iface.setId(9);
OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
outage.setMonitoredService(monSvc);
outages.add(outage);
view.addSection(section);
List<String> services = new ArrayList<>();
services.add("HTTP");
// ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
expect(viewDisplayDao.getView()).andReturn(view);
expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
replay(categoryDao);
replay(viewDisplayDao);
replay(outageDao);
Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
verify(viewDisplayDao);
verify(categoryDao);
verify(outageDao);
assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
for (StatusSection statusSection : statusSections) {
assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
Collection<StatusCategory> statusCategorys = statusSection.getCategories();
for (StatusCategory statusCategory : statusCategorys) {
assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
// assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());
assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
for (StatusNode statusNode : statusCategory.getNodes()) {
assertEquals("Label does not match", "superLabel", statusNode.getLabel());
}
}
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class DefaultCategoryStatusService method createCategory.
private StatusCategory createCategory(String category) {
Collection<OnmsOutage> outages;
CategoryBuilder categoryBuilder = new CategoryBuilder();
StatusCategory statusCategory = new StatusCategory();
Category categoryDetail = m_categoryConfigDao.getCategoryByLabel(category);
// statusCategory.setComment(categoryDetail.getCategoryComment());
statusCategory.setLabel(category);
ServiceSelector selector = new ServiceSelector(categoryDetail.getRule(), getServicesForCategory(categoryDetail));
outages = m_outageDao.matchingCurrentOutages(selector);
for (OnmsOutage outage : outages) {
OnmsMonitoredService monitoredService = outage.getMonitoredService();
OnmsServiceType serviceType = monitoredService.getServiceType();
OnmsIpInterface ipInterface = monitoredService.getIpInterface();
final String ipAddress = InetAddressUtils.str(ipInterface.getIpAddress());
categoryBuilder.addOutageService(monitoredService.getNodeId(), ipAddress, ipAddress, ipInterface.getNode().getLabel(), serviceType.getName());
}
for (StatusNode node : categoryBuilder.getNodes()) {
statusCategory.addNode(node);
}
return statusCategory;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NetworkElementFactory method getInterfaceArrayWithSnmpData.
private Interface[] getInterfaceArrayWithSnmpData(List<OnmsIpInterface> ipIfaces) {
List<Interface> intfs = new LinkedList<>();
for (OnmsIpInterface iface : ipIfaces) {
Interface intf = new Interface(iface);
if (iface.getSnmpInterface() != null) {
OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
intf.createSnmpInterface(snmpIface);
}
intfs.add(intf);
}
Collections.sort(intfs, INTERFACE_COMPARATOR);
return intfs.toArray(new Interface[intfs.size()]);
}
Aggregations