Search in sources :

Example 26 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class LocationBroadcastProcessor method afterPropertiesSet.

/**
 * <p>afterPropertiesSet</p>
 *
 * @throws java.lang.Exception if any.
 */
@Override
public void afterPropertiesSet() throws Exception {
    BeanUtils.assertAutowiring(this);
    m_task = new TimerTask() {

        private Date m_lastRun = new Date();

        @Override
        public void run() {
            final Date now = new Date();
            final Criteria criteria = new Criteria(OnmsEvent.class).addRestriction(new BetweenRestriction("eventTime", m_lastRun, now)).addRestriction(new InRestriction("eventUei", m_events));
            for (final OnmsEvent e : m_eventDao.findMatching(criteria)) {
                handleLocationEvent(e);
            }
            m_lastRun = now;
        }
    };
// m_timer.schedule(m_task, UPDATE_PERIOD, UPDATE_PERIOD);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) TimerTask(java.util.TimerTask) BetweenRestriction(org.opennms.core.criteria.restrictions.BetweenRestriction) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date)

Example 27 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class DefaultAckServiceIT method getEvent.

private OnmsEvent getEvent(OnmsNode node) {
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_populator.getDistPollerDao().whoami());
    event.setEventUei(EventConstants.NODE_DOWN_EVENT_UEI);
    event.setEventTime(new Date());
    event.setEventSource("test");
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setNode(node);
    m_eventDao.save(event);
    m_eventDao.flush();
    return event;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Date(java.util.Date)

Example 28 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class HypericAckProcessorIT method testParseMethods.

@Test
public void testParseMethods() throws Exception {
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "platform.id", "10001", "string"), new OnmsEventParameter(event, "platform.commentText", "", "string"), new OnmsEventParameter(event, "platform.platformType.os", "null", "string"), new OnmsEventParameter(event, "platform.platformType.osVersion", "null", "string"), new OnmsEventParameter(event, "platform.platformType.arch", "null(", "tring"), new OnmsEventParameter(event, "platform.agent.address", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.agent.port", "2144", "string"), new OnmsEventParameter(event, "platform.fqdn", "192.0.2.143", "string"), new OnmsEventParameter(event, "platform.name", "delta", "string"), new OnmsEventParameter(event, "platform.description", "Fedora 12", "string"), new OnmsEventParameter(event, "platform.location", "", "string"), new OnmsEventParameter(event, "alert.id", "11757", "string"), new OnmsEventParameter(event, "alert.fixed", "false", "string"), new OnmsEventParameter(event, "alert.ctime", "1267219500000", "string"), new OnmsEventParameter(event, "alert.timestamp", "1267219500000", "string"), new OnmsEventParameter(event, "alert.ackedBy", "null", "string"), new OnmsEventParameter(event, "alert.stateId", "null", "string"), new OnmsEventParameter(event, "alert.url", "http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757", "string"), new OnmsEventParameter(event, "alert.baseURL", "http://192.168.0.5:7080", "string"), new OnmsEventParameter(event, "alert.source", "HQ", "string"), new OnmsEventParameter(event, "alertDef.id", "10002", "string"), new OnmsEventParameter(event, "alertDef.name", "Load Above 2", "string"), new OnmsEventParameter(event, "alertDef.description", "", "string"), new OnmsEventParameter(event, "alertDef.priority", "2", "string"), new OnmsEventParameter(event, "alertDef.appdefType", "1", "string"), new OnmsEventParameter(event, "alertDef.appdefId", "10001", "string"), new OnmsEventParameter(event, "alertDef.notifyFiltered", "false", "string"), new OnmsEventParameter(event, "action.shortReason", "Load Above 2 delta Load Average 5 Minutes (1.4)", "string"), new OnmsEventParameter(event, "action.longReason", "If Load Average 5 Minutes > 0.5 (actual value %61 1.4)", "string"), new OnmsEventParameter(event, "resource.instanceId", "10001", "string"), new OnmsEventParameter(event, "resource.name", "delta", "string"), new OnmsEventParameter(event, "resource.url", "http://192.168.0.5:7080/Resource.do?eid%611:10001", "string"), new OnmsEventParameter(event, "resource.resourceType.name", "covalentEAMPlatform", "string")));
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setLastEvent(event);
    /*
        OnmsAlarm alarm = createMock(OnmsAlarm.class);
        expect(alarm.getEventParms()).andReturn(
                "platform.id=10001(string,text);platform.commentText=(string,text);platform.platformType.os=null(string,text);platform.platformType.osVersion=null(string,text);platform.platformType.arch=null(string,text);platform.agent.address=192.0.2.143(string,text);platform.agent.port=2144(string,text);platform.fqdn=192.0.2.143(string,text);platform.name=delta(string,text);platform.description=Fedora 12(string,text);platform.location=(string,text);alert.id=11757(string,text);alert.fixed=false(string,text);alert.ctime=1267219500000(string,text);alert.timestamp=1267219500000(string,text);alert.ackedBy=null(string,text);alert.stateId=null(string,text);alert.url=http://192.168.0.5:7080/alerts/Alerts.do?mode%61viewAlert&eid%611:10001&a%6111757(string,text);alert.baseURL=http://192.168.0.5:7080(string,text);alert.source=HQ(string,text);alertDef.id=10002(string,text);alertDef.name=Load Above 2(string,text);alertDef.description=(string,text);alertDef.priority=2(string,text);alertDef.appdefType=1(string,text);alertDef.appdefId=10001(string,text);alertDef.notifyFiltered=false(string,text);action.shortReason=Load Above 2 delta Load Average 5 Minutes (1.4)(string,text);action.longReason=If Load Average 5 Minutes > 0.5 (actual value %61 1.4)(string,text);resource.instanceId=10001(string,text);resource.name=delta(string,text);resource.url=http://192.168.0.5:7080/Resource.do?eid%611:10001(string,text);resource.resourceType.name=covalentEAMPlatform(string,text)"
        ).times(2);
        replay(alarm);
         */
    assertEquals("Alert source not parsed properly", "HQ", HypericAckProcessor.getAlertSourceParmValue(alarm));
    assertEquals("Alert ID not parsed properly", "11757", HypericAckProcessor.getAlertIdParmValue(alarm));
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Test(org.junit.Test)

Example 29 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent 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();
}
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) Test(org.junit.Test)

Example 30 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent 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();
}
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) Test(org.junit.Test)

Aggregations

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5