Search in sources :

Example 1 with OnmsDistPoller

use of org.opennms.netmgt.model.OnmsDistPoller in project opennms by OpenNMS.

the class NewSuspectScanIT method setUp.

@Before
public void setUp() throws Exception {
    m_eventSubscriber.getEventAnticipator().reset();
    if (m_distPollerDao.findAll().size() == 0) {
        OnmsDistPoller distPoller = new OnmsDistPoller(DistPollerDao.DEFAULT_DIST_POLLER_ID);
        distPoller.setLabel("localhost");
        distPoller.setLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
        distPoller.setType(OnmsMonitoringSystem.TYPE_OPENNMS);
        m_distPollerDao.save(distPoller);
    }
    m_foreignSource = new ForeignSource();
    m_foreignSource.setName("imported:");
    m_foreignSource.setScanInterval(Duration.standardDays(1));
    final PluginConfig detector = new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector");
    detector.addParameter("timeout", "1000");
    detector.addParameter("retries", "0");
    m_foreignSource.addDetector(detector);
    m_foreignSourceRepository = new MockForeignSourceRepository();
    m_foreignSourceRepository.putDefaultForeignSource(m_foreignSource);
    m_provisionService.setForeignSourceRepository(m_foreignSourceRepository);
    m_provisioner.start();
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Before(org.junit.Before)

Example 2 with OnmsDistPoller

use of org.opennms.netmgt.model.OnmsDistPoller in project opennms by OpenNMS.

the class DistPollerDaoIT method testGet.

@Test
@Transactional
public void testGet() {
    assertNull(getDistPollerDao().get("otherpoller"));
    testCreate();
    OnmsDistPoller distPoller = getDistPollerDao().get("otherpoller");
    assertNotNull(distPoller);
}
Also used : OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsDistPoller

use of org.opennms.netmgt.model.OnmsDistPoller in project opennms by OpenNMS.

the class OutageRestServiceIT method setUp.

@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    Assert.assertNotNull(populator);
    Assert.assertNotNull(applicationDao);
    populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {

        private OnmsOutage unresolvedOutage;

        private OnmsEvent outageEvent;

        private OnmsApplication application;

        @Override
        public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
            return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
        }

        @Override
        public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
            OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
            outageEvent = populator.buildEvent(distPoller);
            outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
            outageEvent.setEventCreateTime(new Date(1436881548292L));
            outageEvent.setEventTime(new Date(1436881548292L));
            populator.getEventDao().save(outageEvent);
            populator.getEventDao().flush();
            // create the application
            application = new OnmsApplication();
            application.setName("Awesome Application");
            dao.save(application);
            // get the SNMP service from node 1 and assign the application to it
            final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
            svc.addApplication(application);
            application.addMonitoredService(svc);
            populator.getMonitoredServiceDao().saveOrUpdate(svc);
            populator.getMonitoredServiceDao().flush();
            // create a unresolved outage
            unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
            populator.getOutageDao().save(unresolvedOutage);
            populator.getOutageDao().flush();
        }

        @Override
        public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
            // Delete OnmsApplications
            for (OnmsApplication application : dao.findAll()) {
                dao.delete(application);
            }
        }
    });
    populator.populateDatabase();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) ApplicationDao(org.opennms.netmgt.dao.api.ApplicationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 4 with OnmsDistPoller

use of org.opennms.netmgt.model.OnmsDistPoller in project opennms by OpenNMS.

the class AlarmRepositoryFilterIT method testParmsLikeFilter.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testParmsLikeFilter() {
    List<OnmsEvent> events = m_dbPopulator.getEventDao().findAll();
    assertNotNull(events);
    OnmsEvent event = events.get(0);
    OnmsDistPoller poller = m_dbPopulator.getDistPollerDao().whoami();
    assertNotNull(poller);
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
    alarm.setLastEvent(event);
    alarm.setSeverityId(3);
    alarm.setDistPoller(poller);
    alarm.setCounter(100);
    alarm.setEventParms("url=http://localhost:8980/opennms/rtc/post/Network+Interfaces(string,text);user=rtc(string,text);passwd=rtc(string,text);catlabel=Network Interfaces(string,text)");
    AlarmDao alarmDao = m_dbPopulator.getAlarmDao();
    alarmDao.save(alarm);
    alarmDao.flush();
    OnmsAlarm alarm2 = new OnmsAlarm();
    alarm2.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
    alarm2.setLastEvent(event);
    alarm2.setSeverityId(3);
    alarm2.setDistPoller(poller);
    alarm2.setCounter(100);
    alarm2.setEventParms("componentType=serviceElement(string,text);url=http://localhost:8980/opennms/rtc/post/Network+Interfaces(string,text);user=rtcbomb(string,text);passwd=rtc(string,text);catlabel=Network Interfaces(string,text)");
    alarmDao.save(alarm2);
    alarmDao.flush();
    EventParmLikeFilter eventParmFilter = new EventParmLikeFilter("user=rtc");
    assertEquals("user=\"rtc\"", eventParmFilter.getTextDescription());
    AlarmCriteria criteria = new AlarmCriteria(eventParmFilter);
    OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(criteria));
    assertEquals(1, alarms.length);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OnmsDistPoller

use of org.opennms.netmgt.model.OnmsDistPoller in project opennms by OpenNMS.

the class BundleContextHistoryManagerTest method initProvidersAndCriteria.

/**
     * In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
     */
private void initProvidersAndCriteria() {
    // Preparing SearchProviders
    CategoryProvider vertexProvider = new CategoryProvider() {

        @Override
        public Collection<OnmsCategory> getAllCategories() {
            return Lists.newArrayList(findCategoryByName("somename"));
        }

        @Override
        public OnmsCategory findCategoryByName(String m_categoryName) {
            OnmsCategory cat = new OnmsCategory("test", "test");
            cat.setId(Integer.valueOf(idCategory));
            return cat;
        }

        @Override
        public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
            return new ArrayList<>();
        }
    };
    IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {

        @Override
        public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
            OnmsNode node = new OnmsNode();
            node.setId(Integer.valueOf(idIpLike));
            String ipAddr = "127.0.0.1";
            OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
            return Lists.newArrayList(ipInterface);
        }
    };
    AlarmProvider alarmProvider = new AlarmProvider() {

        @Override
        public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
            Date eventTime = new Date();
            OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
            OnmsEvent event = new OnmsEvent();
            OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
            return Lists.newArrayList(alarm);
        }
    };
    // Creating SearchResults to be used in testing
    SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
    this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
    this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
    // Initializing available (initial) SearchProviders
    this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(vertexProvider));
    this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
    this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
    // Initializing available (initial) Criteria
    this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider));
    this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
    this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Also used : CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpInterfaceProvider(org.opennms.features.topology.app.internal.IpInterfaceProvider) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Date(java.util.Date) CategorySearchProvider(org.opennms.features.topology.app.internal.CategorySearchProvider) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AlarmSearchProvider(org.opennms.features.topology.app.internal.AlarmSearchProvider) AlarmProvider(org.opennms.features.topology.app.internal.AlarmProvider) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) IpLikeSearchProvider(org.opennms.features.topology.app.internal.IpLikeSearchProvider)

Aggregations

OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)11 Test (org.junit.Test)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Before (org.junit.Before)3 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)3 Date (java.util.Date)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)2 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)2 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)2 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)2 ArrayList (java.util.ArrayList)1 Message (org.opennms.core.ipc.sink.api.Message)1 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)1 ProxySnmpAgentConfigFactory (org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)1 SearchResult (org.opennms.features.topology.api.topo.SearchResult)1 AlarmProvider (org.opennms.features.topology.app.internal.AlarmProvider)1