use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class NodeDaoHibernate method getHierarchy.
/**
* {@inheritDoc}
*/
@Override
public OnmsNode getHierarchy(Integer id) {
OnmsNode node = findUnique("select distinct n from OnmsNode as n " + "left join fetch n.assetRecord " + "where n.id = ?", id);
initialize(node.getIpInterfaces());
for (OnmsIpInterface i : node.getIpInterfaces()) {
initialize(i.getMonitoredServices());
}
initialize(node.getSnmpInterfaces());
for (OnmsSnmpInterface i : node.getSnmpInterfaces()) {
initialize(i.getIpInterfaces());
}
return node;
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class VacuumdIT method createNode.
/**
* Creates the node.
*
* @return the node
* @throws Exception the exception
*/
@Transactional
public OnmsNode createNode() throws Exception {
OnmsNode node = new OnmsNode();
node.setLocation(m_location);
node.setForeignSource("Servers-MacOS");
node.setForeignId("1");
node.setLabel("my-test-server");
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 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.setIfIndex(1);
onmsIf.setIpHostName("my-test-server");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.getIpInterfaces().add(onmsIf);
m_nodeDao.save(node);
m_nodeDao.flush();
return node;
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EmailNorthbounderTest method testNorthbounderForServers.
/**
* Test northbounder for servers.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounderForServers() 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");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
}
});
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
// Verify the nortbound alarm and send it to the test receiver
Assert.assertTrue(nbi.accepts(alarm));
SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
Assert.assertEquals("noc@networksRus.com", sendmail.getSendmailMessage().getTo());
Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS", sendmail.getSendmailMessage().getSubject());
Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS: Test log message\nDescription: Test description", sendmail.getSendmailMessage().getBody());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class EmailNorthbounderTest method testNorthbounderForRouters.
/**
* Test northbounder for routers.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounderForRouters() throws Exception {
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Routers-Cisco");
node.setForeignId("1");
node.setId(1);
node.setLabel("my-test-router");
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-router");
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");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
}
});
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
// Verify the nortbound alarm and send it to the test receiver
Assert.assertTrue(nbi.accepts(alarm));
SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
Assert.assertEquals("tarus@opennms.org, jeff@opennms.org", sendmail.getSendmailMessage().getTo());
Assert.assertEquals("my-test-router : Something is wrong!", sendmail.getSendmailMessage().getSubject());
Assert.assertEquals("Test log message - Test description", sendmail.getSendmailMessage().getBody());
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class SnmpTrapNorthbounderConfigDaoTest method createAlarm.
/**
* Creates the alarm.
*
* @return the northbound alarm
* @throws UnknownHostException the unknown host exception
*/
private NorthboundAlarm createAlarm() throws UnknownHostException {
// Build a test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Servers");
node.setForeignId("AAA11122");
node.setId(1);
node.setLabel("my-server");
// Build a test SNMP interface
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");
// Build a test IP interface
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("p-brane");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.addIpInterface(onmsIf);
// Build a test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(10);
onmsAlarm.setNode(node);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
onmsAlarm.setLogMsg("everything is good");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "99", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is just a test", "String"), new OnmsEventParameter(this, "forwardAlarmToUserSnmpTrap", "true", "String")));
}
});
// Build a test northbound alarm
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(node.getForeignSource(), alarm.getForeignSource());
Assert.assertEquals(node.getForeignId(), alarm.getForeignId());
return alarm;
}
Aggregations