Search in sources :

Example 51 with OnmsEvent

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

the class RestClient method getEvents.

public List<OnmsEvent> getEvents() {
    GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
    };
    final WebTarget target = getTarget().path("events");
    return getBuilder(target).get(events);
}
Also used : GenericType(javax.ws.rs.core.GenericType) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 52 with OnmsEvent

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

the class RestClient method getAllEvents.

public List<OnmsEvent> getAllEvents() {
    GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
    };
    final WebTarget target = getTarget().path("events").queryParam("limit", 0);
    return getBuilder(target).get(events);
}
Also used : GenericType(javax.ws.rs.core.GenericType) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 53 with OnmsEvent

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

the class Poller method scheduleService.

private boolean scheduleService(OnmsMonitoredService service) {
    final OnmsIpInterface iface = service.getIpInterface();
    final Set<OnmsOutage> outages = service.getCurrentOutages();
    final OnmsOutage outage = (outages == null || outages.size() < 1 ? null : outages.iterator().next());
    final OnmsEvent event = (outage == null ? null : outage.getServiceLostEvent());
    final String ipAddr = InetAddressUtils.str(iface.getIpAddress());
    final String serviceName = service.getServiceName();
    boolean active = "A".equals(service.getStatus());
    final Number svcLostEventId = event == null ? null : event.getId();
    final Date ifLostService = outage == null ? null : outage.getIfLostService();
    final String svcLostUei = event == null ? null : event.getEventUei();
    closeOutageIfSvcLostEventIsMissing(outage);
    // We don't want to adjust the management state of the service if we're
    // on a machine that uses multiple servers with access to the same database
    // so check the value of OpennmsServerConfigFactory.getInstance().verifyServer()
    // before doing any updates.
    final Package pkg = findPackageForService(ipAddr, serviceName);
    final boolean verifyServer = OpennmsServerConfigFactory.getInstance().verifyServer();
    if (pkg == null) {
        if (active && !verifyServer) {
            LOG.warn("Active service {} on {} not configured for any package. Marking as Not Polled.", serviceName, ipAddr);
            updateServiceStatus(service, "N");
        }
        return false;
    } else if (!active && !verifyServer) {
        LOG.info("Active service {} on {} is now configured for a package. Marking as active.", serviceName, ipAddr);
        updateServiceStatus(service, "A");
    }
    ServiceMonitor monitor = m_pollerConfig.getServiceMonitor(serviceName);
    if (monitor == null) {
        LOG.info("Could not find service monitor associated with service {}", serviceName);
        return false;
    }
    InetAddress addr;
    addr = InetAddressUtils.addr(ipAddr);
    if (addr == null) {
        LOG.error("Could not convert {} as an InetAddress {}", ipAddr, ipAddr);
        return false;
    }
    PollableService svc = getNetwork().createService(service.getNodeId(), iface.getNode().getLabel(), iface.getNode().getLocation().getLocationName(), addr, serviceName);
    PollableServiceConfig pollConfig = new PollableServiceConfig(svc, m_pollerConfig, m_pollOutagesConfig, pkg, getScheduler(), m_persisterFactory, m_resourceStorageDao, m_locationAwarePollerClient);
    svc.setPollConfig(pollConfig);
    synchronized (svc) {
        if (svc.getSchedule() == null) {
            Schedule schedule = new Schedule(svc, pollConfig, getScheduler());
            svc.setSchedule(schedule);
        }
    }
    if (svcLostEventId == null) {
        if (svc.getParent().getStatus().isUnknown()) {
            svc.updateStatus(PollStatus.up());
        } else {
            svc.updateStatus(svc.getParent().getStatus());
        }
    } else {
        svc.updateStatus(PollStatus.down());
        PollEvent cause = new DbPollEvent(svcLostEventId.intValue(), svcLostUei, ifLostService);
        svc.setCause(cause);
    }
    svc.schedule();
    return true;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) DbPollEvent(org.opennms.netmgt.poller.pollables.DbPollEvent) Date(java.util.Date) PollEvent(org.opennms.netmgt.poller.pollables.PollEvent) DbPollEvent(org.opennms.netmgt.poller.pollables.DbPollEvent) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) PollableServiceConfig(org.opennms.netmgt.poller.pollables.PollableServiceConfig) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) PollableService(org.opennms.netmgt.poller.pollables.PollableService) Schedule(org.opennms.netmgt.scheduler.Schedule) Package(org.opennms.netmgt.config.poller.Package) InetAddress(java.net.InetAddress)

Example 54 with OnmsEvent

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

the class InvalidRequisitionDataIT method setUp.

@Before
public void setUp() throws Exception {
    // clean out any existing nodes
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    m_nodeDao.flush();
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    MockLogAppender.setupLogging(true, "DEBUG");
    m_eventManager.setSynchronous(true);
    m_provisioner.start();
    // make sure node scan scheduler is running initially
    getScanExecutor().resume();
    getScheduledExecutor().resume();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) Before(org.junit.Before)

Example 55 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent 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
    final DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(serviceLocatorMock);
    this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(topologyService, 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, graphContainerMock));
    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) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) 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

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5