use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class DefaultPollingContext method getNodeIpAddress.
/*
* Return the IP address of the first interface on the node
*/
protected InetAddress getNodeIpAddress(OnmsNode node) {
final Criteria criteria = new Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", node.getId()));
List<OnmsIpInterface> matchingIfaces = getIpInterfaceDao().findMatching(criteria);
return matchingIfaces.get(0).getIpAddress();
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AbstractDaoRestService method getCriteria.
protected Criteria getCriteria(UriInfo uriInfo, SearchContext searchContext) {
final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
final CriteriaBuilder builder = getCriteriaBuilder();
if (searchContext != null) {
try {
SearchCondition<T> condition = searchContext.getCondition(getDaoClass());
if (condition != null) {
SearchConditionVisitor<T, CriteriaBuilder> visitor = new CriteriaBuilderSearchVisitor<T>(builder, getDaoClass());
condition.accept(visitor);
}
} catch (PropertyNotFoundException | ArrayIndexOutOfBoundsException e) {
LOG.warn(e.getClass().getSimpleName() + " while parsing FIQL search, ignoring: " + e.getMessage(), e);
}
}
// Apply limit, offset, orderBy, order params
applyLimitOffsetOrderBy(params, builder);
Criteria crit = builder.toCriteria();
return crit;
}
use of org.opennms.core.criteria.Criteria 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.core.criteria.Criteria 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.core.criteria.Criteria in project opennms by OpenNMS.
the class BusinessServiceSearchProvider method queryVertices.
@Override
public List<? extends VertexRef> queryVertices(SearchQuery searchQuery, GraphContainer container) {
List<BusinessServiceVertex> results = Lists.newArrayList();
String queryString = searchQuery.getQueryString();
CriteriaBuilder bldr = new CriteriaBuilder(BusinessService.class);
if (queryString != null && queryString.length() > 0) {
bldr.ilike("name", String.format("%%%s%%", queryString));
}
bldr.orderBy("name", true);
bldr.limit(10);
Criteria dbQueryCriteria = bldr.toCriteria();
for (BusinessService bs : businessServiceManager.findMatching(dbQueryCriteria)) {
final BusinessServiceVertex businessServiceVertex = new BusinessServiceVertex(bs, 0);
// Only consider results which are available in the Topology Provider, see BSM-191
if (container.getTopologyServiceClient().getVertex(businessServiceVertex) != null) {
results.add(businessServiceVertex);
}
}
return results;
}
Aggregations