use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class InterfaceSnmpByIfIndexResourceType method getChildByName.
/**
* {@inheritDoc}
*/
@Override
public OnmsResource getChildByName(final OnmsResource parent, final String name) {
// Grab the node entity
final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
// Determine the ifIndex from the given name
final int ifIndex = Integer.parseInt(name);
// Find the associated SNMP interface
final OnmsSnmpInterface snmpInterface = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (snmpInterface == null) {
return null;
}
// Compute the set of possible keys at which the interface resource may be stored
final Set<String> candidateInterfaceKeys = Sets.newHashSet();
candidateInterfaceKeys.addAll(Arrays.asList(InterfaceSnmpResourceType.getKeysFor(snmpInterface)));
// Enumerate all of the available interfaces on the parent, and use the first match
final Optional<String> path = m_interfaceSnmpResourceType.getQueryableInterfaces(parent).stream().filter(candidateInterfaceKeys::contains).findFirst();
if (!path.isPresent()) {
return null;
}
// queried directly by name
return m_interfaceSnmpResourceType.getChildByName(parent, path.get());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class InterfaceSnmpResourceType method getNodeResources.
private List<OnmsResource> getNodeResources(ResourcePath parent, Set<String> intfNames, OnmsNode node) {
ArrayList<OnmsResource> resources = new ArrayList<>();
Set<OnmsSnmpInterface> snmpInterfaces = node.getSnmpInterfaces();
Map<String, OnmsSnmpInterface> intfMap = new HashMap<String, OnmsSnmpInterface>();
for (OnmsSnmpInterface snmpInterface : snmpInterfaces) {
for (String key : getKeysFor(snmpInterface)) {
if (!intfMap.containsKey(key)) {
intfMap.put(key, snmpInterface);
}
}
}
for (String intfName : intfNames) {
String key = getKeyFor(intfName);
OnmsSnmpInterface snmpInterface = intfMap.get(key);
String label;
Long ifSpeed = null;
String ifSpeedFriendly = null;
if (snmpInterface == null) {
label = intfName + " (*)";
} else {
final StringBuilder descr = new StringBuilder();
final StringBuilder parenString = new StringBuilder();
if (snmpInterface.getIfAlias() != null) {
parenString.append(snmpInterface.getIfAlias());
}
// Append all of the IP addresses on this ifindex
for (OnmsIpInterface ipif : snmpInterface.getIpInterfaces()) {
String ipaddr = InetAddressUtils.str(ipif.getIpAddress());
if (!"0.0.0.0".equals(ipaddr)) {
if (parenString.length() > 0) {
parenString.append(", ");
}
parenString.append(ipaddr);
}
}
if ((snmpInterface.getIfSpeed() != null) && (snmpInterface.getIfSpeed() != 0)) {
ifSpeed = snmpInterface.getIfSpeed();
ifSpeedFriendly = SIUtils.getHumanReadableIfSpeed(ifSpeed);
if (parenString.length() > 0) {
parenString.append(", ");
}
parenString.append(ifSpeedFriendly);
}
if (snmpInterface.getIfName() != null) {
descr.append(snmpInterface.getIfName());
} else if (snmpInterface.getIfDescr() != null) {
descr.append(snmpInterface.getIfDescr());
} else {
/*
* Should never reach this point, since ifLabel is based on
* the values of ifName and ifDescr but better safe than sorry.
*/
descr.append(intfName);
}
/* Add the extended information in parenthesis after the ifLabel,
* if such information was found.
*/
if (parenString.length() > 0) {
descr.append(" (");
descr.append(parenString);
descr.append(")");
}
label = descr.toString();
}
OnmsResource resource = getResourceByParentPathAndInterface(parent, intfName, label, ifSpeed, ifSpeedFriendly);
if (snmpInterface != null) {
Set<OnmsIpInterface> ipInterfaces = snmpInterface.getIpInterfaces();
if (ipInterfaces.size() > 0) {
int id = ipInterfaces.iterator().next().getId();
resource.setLink("element/interface.jsp?ipinterfaceid=" + id);
} else {
int ifIndex = snmpInterface.getIfIndex();
if (ifIndex > -1) {
resource.setLink("element/snmpinterface.jsp?node=" + node.getNodeId() + "&ifindex=" + ifIndex);
}
}
resource.setEntity(snmpInterface);
} else {
LOG.debug("populateResourceList: snmpInterface is null");
}
LOG.debug("populateResourceList: adding resource toString {}", resource.toString());
resources.add(resource);
}
return resources;
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class MeasurementRestServiceIT method setUp.
@Before
public void setUp() throws Throwable {
super.setUp();
BeanUtils.assertAutowiring(this);
assertNotNull(restService);
assertNotNull(service);
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "node1");
node.setId(1);
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 12);
snmpInterface.setIfName("eth0");
snmpInterface.setPhysAddr("04013f75f101");
m_nodeDao.save(node);
m_nodeDao.flush();
File rrdDirectory = new File("src/test/resources/share/jrb");
assertTrue(rrdDirectory.canRead());
m_resourceStorageDao.setRrdDirectory(rrdDirectory);
System.setProperty("rrd.base.dir", rrdDirectory.getAbsolutePath());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class BSFNorthbounderIT method testNorthbounder.
/**
* Test northbounder.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounder() throws Exception {
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Servers-MacOS");
node.setForeignId("1");
node.setId(1);
node.setLabel("my-test-server");
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
snmpInterface.setId(1);
snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
snmpInterface.setIfDescr("en1");
snmpInterface.setIfName("en1/0");
snmpInterface.setPhysAddr("00:00:00:00:00:01");
InetAddress address = InetAddress.getByName("10.0.1.1");
OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
onmsIf.setSnmpInterface(snmpInterface);
onmsIf.setId(1);
onmsIf.setIfIndex(1);
onmsIf.setIpHostName("my-test-server");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.getIpInterfaces().add(onmsIf);
// Setup test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(100);
onmsAlarm.setNode(node);
onmsAlarm.setIpAddr(address);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
onmsAlarm.setLastEvent(event);
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
Assert.assertTrue(nbi.accepts(alarm));
nbi.forwardAlarms(Lists.newArrayList(alarm));
nbi.stop();
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class DroolsNorthbounderIT method testNorthbounder.
/**
* Test northbounder.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounder() throws Exception {
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Servers-MacOS");
node.setForeignId("1");
node.setId(1);
node.setLabel("my-test-server");
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
snmpInterface.setId(1);
snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
snmpInterface.setIfDescr("en1");
snmpInterface.setIfName("en1/0");
snmpInterface.setPhysAddr("00:00:00:00:00:01");
InetAddress address = InetAddress.getByName("10.0.1.1");
OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
onmsIf.setSnmpInterface(snmpInterface);
onmsIf.setId(1);
onmsIf.setIfIndex(1);
onmsIf.setIpHostName("my-test-server");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.getIpInterfaces().add(onmsIf);
// Setup test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(100);
onmsAlarm.setNode(node);
onmsAlarm.setIpAddr(address);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
onmsAlarm.setLastEvent(event);
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
Assert.assertTrue(nbi.accepts(alarm));
nbi.forwardAlarms(Lists.newArrayList(alarm));
nbi.stop();
}
Aggregations