Search in sources :

Example 1 with EventDao

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));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Executor(org.apache.http.client.fluent.Executor) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) Criteria(org.opennms.core.criteria.Criteria) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) Date(java.util.Date) Test(org.junit.Test)

Example 2 with EventDao

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));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test)

Example 3 with EventDao

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);
    }
}
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 4 with EventDao

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;
        }
    });
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test)

Example 5 with EventDao

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Parm(org.opennms.netmgt.xml.event.Parm) Criteria(org.opennms.core.criteria.Criteria) NodeDao(org.opennms.netmgt.dao.api.NodeDao) EventDao(org.opennms.netmgt.dao.api.EventDao) Value(org.opennms.netmgt.xml.event.Value) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Event(org.opennms.netmgt.xml.event.Event) OnmsEvent(org.opennms.netmgt.model.OnmsEvent)

Aggregations

EventDao (org.opennms.netmgt.dao.api.EventDao)5 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)5 Criteria (org.opennms.core.criteria.Criteria)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 InetSocketAddress (java.net.InetSocketAddress)3 Date (java.util.Date)3 Test (org.junit.Test)3 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)3 ArrayList (java.util.ArrayList)2 Event (org.opennms.netmgt.xml.event.Event)2 List (java.util.List)1 HttpHost (org.apache.http.HttpHost)1 HttpClient (org.apache.http.client.HttpClient)1 Executor (org.apache.http.client.fluent.Executor)1 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 NodeDao (org.opennms.netmgt.dao.api.NodeDao)1 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Parm (org.opennms.netmgt.xml.event.Parm)1