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);
}
}
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();
}
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);
}
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();
}
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;
}
Aggregations