use of org.opennms.core.criteria.CriteriaBuilder 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.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class SyslogKafkaElasticsearch5OutageIT method testMinionSyslogsOverKafkaToEsRest.
@Test
public void testMinionSyslogsOverKafkaToEsRest() throws Exception {
Date startOfTest = new Date();
int numMessages = 10000;
int packetsPerSecond = 250;
InetSocketAddress minionSshAddr = testEnvironment.getServiceAddress(ContainerAlias.MINION, 8201);
InetSocketAddress opennmsSshAddr = testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8101);
InetSocketAddress kafkaAddress = testEnvironment.getServiceAddress(ContainerAlias.KAFKA, 9092);
InetSocketAddress zookeeperAddress = testEnvironment.getServiceAddress(ContainerAlias.KAFKA, 2181);
// Install the Kafka syslog and trap handlers on the Minion system
installFeaturesOnMinion(minionSshAddr, kafkaAddress);
// Install the Kafka and Elasticsearch features on the OpenNMS system
installFeaturesOnOpenNMS(opennmsSshAddr, kafkaAddress, zookeeperAddress);
final String sender = testEnvironment.getContainerInfo(ContainerAlias.SNMPD).networkSettings().ipAddress();
// Wait for the minion to show up
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
LOG.info("Warming up syslog routes by sending 100 packets");
// Warm up the routes
sendMessage(ContainerAlias.MINION, sender, 100);
for (int i = 0; i < 10; i++) {
LOG.info("Slept for " + i + " seconds");
Thread.sleep(1000);
}
LOG.info("Resetting statistics");
resetRouteStatistics(opennmsSshAddr, minionSshAddr);
for (int i = 0; i < 20; i++) {
LOG.info("Slept for " + i + " seconds");
Thread.sleep(1000);
}
// Make sure that this evenly divides into the numMessages
final int chunk = 250;
// Make sure that this is an even multiple of chunk
final int logEvery = 1000;
int count = 0;
long start = System.currentTimeMillis();
AtomicInteger restartCounter = new AtomicInteger();
// Start a timer that occasionally restarts Elasticsearch
Timer restarter = new Timer("Elasticsearch-Restarter", true);
restarter.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final DockerClient docker = ((AbstractTestEnvironment) testEnvironment).getDockerClient();
final String id = testEnvironment.getContainerInfo(ContainerAlias.ELASTICSEARCH_5).id();
try {
LOG.info("Restarting container: {}", id);
docker.restartContainer(id);
restartCounter.incrementAndGet();
LOG.info("Container restarted: {}", id);
} catch (DockerException | InterruptedException e) {
LOG.warn("Unexpected exception while restarting container {}", id, e);
}
}
}, 0L, TimeUnit.SECONDS.toMillis(29));
// Send ${numMessages} syslog messages
RateLimiter limiter = RateLimiter.create(packetsPerSecond);
for (int i = 0; i < (numMessages / chunk); i++) {
limiter.acquire(chunk);
sendMessage(ContainerAlias.MINION, sender, chunk);
count += chunk;
if (count % logEvery == 0) {
long mid = System.currentTimeMillis();
LOG.info(String.format("Sent %d packets in %d milliseconds", logEvery, mid - start));
start = System.currentTimeMillis();
}
}
// Stop restarting Elasticsearch
restarter.cancel();
// 100 warm-up messages plus ${numMessages} messages
pollForElasticsearchEventsUsingJest(this::getEs5Address, 100 + numMessages);
assertTrue("Elasticsearch was never restarted", restartCounter.get() > 0);
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class HibernateCriteriaConverterIT method testDistinctQuery.
@Test
@JUnitTemporaryDatabase
public void testDistinctQuery() {
List<OnmsNode> nodes = null;
final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.isNotNull("id").distinct();
cb.eq("label", "node1").join("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN).eq("ipInterface.ipAddress", "192.168.1.1");
nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(1, nodes.size());
assertEquals(Integer.valueOf(1), nodes.get(0).getId());
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class HibernateCriteriaConverterIT method testNodeIlikeQuery.
@Test
@JUnitTemporaryDatabase
public void testNodeIlikeQuery() {
final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.isNotNull("id").eq("label", "node1").alias("ipInterfaces", "iface").ilike("iface.ipAddress", "1%");
final List<OnmsNode> nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(3, nodes.size());
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AlarmHopCriteria method findAlarms.
private List<OnmsAlarm> findAlarms() {
CriteriaBuilder bldr = new CriteriaBuilder(OnmsAlarm.class);
String query = getSearchResult().getQuery();
if (isSeverityQuery()) {
bldr.eq("severity", OnmsSeverity.get(query));
} else {
bldr.eq("id", getSearchResult().getAlarmId());
}
return alarmProvider.findMatchingAlarms(bldr.toCriteria());
}
Aggregations