use of org.opennms.netmgt.dao.api.EventDao in project opennms by OpenNMS.
the class DiscoveryIT method canDiscoverRemoteNodes.
@Test
public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException {
Date startOfTest = new Date();
final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress();
final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980);
final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort());
HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(// Ignore the 302 response to the POST
new LaxRedirectStrategy()).build();
Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin").authPreemptive(opennmsHttpHost);
// Configure Discovery with the specific address of our Tomcat server
// No REST endpoint is currently available to configure the Discovery daemon
// so we resort to POSTin nasty form data
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000").add("specificretries", "1").add("initialsleeptime", "30000").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
executor.execute(Request.Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION").add("retries", "1").add("timeout", "2000").build())).returnContent();
InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
use of org.opennms.netmgt.dao.api.EventDao in project opennms by OpenNMS.
the class SyslogIT method canReceiveSyslogMessages.
@Test
public void canReceiveSyslogMessages() throws Exception {
final Date startOfTest = new Date();
// Send a syslog packet to the Minion syslog listener
sendMessage(ContainerAlias.MINION, "myhost", 1);
// Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
final EventDao eventDao = getDaoFactory().getDao(EventDaoHibernate.class);
final Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).toCriteria();
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}
use of org.opennms.netmgt.dao.api.EventDao 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.dao.api.EventDao in project opennms by OpenNMS.
the class TrapIT method canReceiveTraps.
@Test
public void canReceiveTraps() throws Exception {
Date startOfTest = new Date();
final InetSocketAddress trapAddr = minionSystem.getServiceAddress(ContainerAlias.MINION, 1162, "udp");
// Connect to the postgresql container
InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
// Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/generic/traps/SNMP_Warm_Start").ge("eventTime", startOfTest).toCriteria();
// Send traps to the Minion listener until one makes it through
await().atMost(5, MINUTES).pollInterval(30, SECONDS).pollDelay(0, SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
sendTrap(trapAddr);
try {
await().atMost(30, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThanOrEqualTo(1));
} catch (final Exception e) {
return false;
}
return true;
}
});
}
use of org.opennms.netmgt.dao.api.EventDao in project opennms by OpenNMS.
the class JtiTelemetryIT method sendnewSuspectEvent.
public static OnmsNode sendnewSuspectEvent(Executor executor, InetSocketAddress opennmsHttp, TestEnvironment m_testEnvironment, boolean isMinion, Date startOfTest) throws ClientProtocolException, IOException {
Event minionEvent = new Event();
minionEvent.setUei("uei.opennms.org/internal/discovery/newSuspect");
minionEvent.setHost(SENDER_IP);
minionEvent.setInterface(SENDER_IP);
minionEvent.setInterfaceAddress(Inet4Address.getByName(SENDER_IP));
minionEvent.setSource("system-test");
minionEvent.setSeverity("4");
if (isMinion) {
Parm parm = new Parm();
parm.setParmName("location");
Value minion = new Value("MINION");
parm.setValue(minion);
List<Parm> parms = new ArrayList<>();
parms.add(parm);
minionEvent.setParmCollection(parms);
}
String xmlString = JaxbUtils.marshal(minionEvent);
executor.execute(Request.Post(String.format("http://%s:%d/opennms/rest/events", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyString(xmlString, ContentType.APPLICATION_XML)).returnContent();
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).eq("ipAddr", Inet4Address.getByName(SENDER_IP)).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
final OnmsNode onmsNode = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("label", SENDER_IP).ge("createTime", startOfTest).toCriteria()), notNullValue());
assertNotNull(onmsNode);
if (isMinion) {
assertThat(onmsNode.getLocation().getLocationName(), is("MINION"));
}
LOG.info(" New suspect event has been sent and node has been created for IP : {}", SENDER_IP);
return onmsNode;
}
Aggregations