Search in sources :

Example 46 with OnmsSnmpInterface

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;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 47 with OnmsSnmpInterface

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;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) InetAddress(java.net.InetAddress) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with OnmsSnmpInterface

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 49 with OnmsSnmpInterface

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 50 with OnmsSnmpInterface

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)73 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)39 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 Test (org.junit.Test)17 InetAddress (java.net.InetAddress)16 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)10 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)9 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)8 LinkedHashSet (java.util.LinkedHashSet)5 LinkedList (java.util.LinkedList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Before (org.junit.Before)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4