Search in sources :

Example 6 with OnmsEvent

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

the class InsSession method getEventsByCriteria.

private void getEventsByCriteria() {
    LOG.debug("clearing events");
    clearEvents();
    final BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
    final EventDao eventDao = BeanUtils.getBean(bf, "eventDao", EventDao.class);
    final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
    try {
        transTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) {
                LOG.debug("Entering transaction call back: selection with criteria: {}", criteriaRestriction);
                final OnmsCriteria criteria = new OnmsCriteria(OnmsEvent.class);
                criteria.add(Restrictions.sqlRestriction(criteriaRestriction));
                final List<OnmsEvent> events = eventDao.findMatching(criteria);
                LOG.info("Found {} event(s) with criteria: {}", events.size(), criteriaRestriction);
                for (final OnmsEvent onmsEvent : events) {
                    final Event xmlEvent = getXMLEvent(onmsEvent);
                    if (xmlEvent != null)
                        addEvent(xmlEvent);
                }
            }
        });
    } catch (final RuntimeException e) {
        LOG.error("Error while getting events.", e);
    }
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) ArrayList(java.util.ArrayList) List(java.util.List) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 7 with OnmsEvent

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

the class DaoWebEventRepositoryIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setEventUei("uei.opennms.org/test2");
    event.setEventTime(new Date());
    event.setEventSource("test");
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
    OnmsEvent event2 = new OnmsEvent();
    event2.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event2.setEventUei("uei.opennms.org/test3");
    event2.setEventTime(new Date());
    event2.setEventSource("test");
    event2.setEventCreateTime(new Date());
    event2.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event2.setEventLog("Y");
    event2.setEventDisplay("N");
    m_dbPopulator.getEventDao().save(event2);
    m_dbPopulator.getEventDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Date(java.util.Date) Before(org.junit.Before)

Example 8 with OnmsEvent

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

the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.

protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
    OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
    if (onmsMonitoringLocation == null) {
        onmsMonitoringLocation = new OnmsMonitoringLocation();
        onmsMonitoringLocation.setLocationName(location);
        onmsMonitoringLocation.setLatitude(1.0f);
        onmsMonitoringLocation.setLongitude(1.0f);
        onmsMonitoringLocation.setMonitoringArea(location);
        onmsMonitoringLocation.setPriority(1L);
        m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
    }
    List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
    OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
    if (node == null) {
        node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
        node.setForeignSource(location);
        node.setForeignId(label);
        m_dbPopulator.getNodeDao().save(node);
    }
    int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
    OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
    if (ipInterface == null) {
        ipInterface = new OnmsIpInterface(addr(ip), node);
    }
    OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
    if (monitoredService == null) {
        monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
        m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
    }
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setEventUei("uei.opennms.org/" + location + "/" + label);
    event.setEventTime(new Date());
    event.setEventSource(location + "/" + label);
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("N");
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
    OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
    outage.setServiceLostEvent(event);
    m_dbPopulator.getOutageDao().save(outage);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 9 with OnmsEvent

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

the class WebEventRepositoryFilterIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    final OnmsNode node2 = m_dbPopulator.getNode2();
    final OnmsMonitoringLocation location = m_monitoringLocationDao.get("RDU");
    node2.setLocation(location);
    m_nodeDao.saveOrUpdate(node2);
    m_nodeDao.flush();
    final OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setAlarm(m_dbPopulator.getAlarmDao().get(1));
    event.setNode(node2);
    event.setEventUei("uei.opennms.org/test2");
    event.setEventTime(new Date());
    event.setEventSource("test");
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setIfIndex(11);
    event.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
    event.setEventLogMsg("This is a test log message");
    event.setEventDescr("This is a test event");
    event.setServiceType(m_dbPopulator.getServiceTypeDao().get(1));
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 10 with OnmsEvent

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

the class OutageDaoIT method insertEntitiesAndOutage.

private OnmsOutage insertEntitiesAndOutage(final String ipAddr, final String serviceName, OnmsNode node) {
    OnmsIpInterface ipInterface = getIpInterface(ipAddr, node);
    OnmsServiceType serviceType = getServiceType(serviceName);
    OnmsMonitoredService monitoredService = getMonitoredService(ipInterface, serviceType);
    OnmsEvent event = getEvent();
    OnmsOutage outage = getOutage(monitoredService, event);
    return outage;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

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