Search in sources :

Example 1 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DefaultLocationDataService method getStatusDetailsForAllLocations.

@Override
public Map<String, StatusDetails> getStatusDetailsForAllLocations() {
    final Collection<OnmsMonitoringLocation> definitions = m_monitoringLocationDao.findAll();
    AllMonitorStatusTracker tracker = new AllMonitorStatusTracker();
    MonitorTracker monTracker = new MonitorTracker();
    for (OnmsLocationSpecificStatus status : m_locationDao.getAllMostRecentStatusChanges()) {
        tracker.onStatus(status);
    }
    for (OnmsLocationMonitor monitor : m_locationDao.findAll()) {
        monTracker.onMonitor(monitor);
    }
    Map<String, StatusDetails> statusDetails = new LinkedHashMap<String, StatusDetails>();
    for (final OnmsMonitoringLocation def : definitions) {
        LocationMonitorState monitorState = new LocationMonitorState(monTracker.drain(def.getLocationName()), tracker.drain(def.getLocationName()));
        final StatusDetails monitorStatus = monitorState.getStatusDetails();
        statusDetails.put(def.getLocationName(), monitorStatus);
    }
    return statusDetails;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) StatusDetails(org.opennms.features.poller.remote.gwt.client.StatusDetails) LocationMonitorState(org.opennms.features.poller.remote.gwt.client.LocationMonitorState) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class MonitoringLocationsRestService method updateMonitoringLocation.

@PUT
@Path("{monitoringLocation}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateMonitoringLocation(@PathParam("monitoringLocation") String monitoringLocation, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocation);
        LOG.debug("updateMonitoringLocation: updating monitoring location {}", monitoringLocation);
        if (params.isEmpty())
            return Response.notModified().build();
        boolean modified = false;
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(def);
        wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                Object value = null;
                String stringValue = params.getFirst(key);
                value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateMonitoringLocation: monitoring location {} updated", monitoringLocation);
            m_monitoringLocationDao.save(def);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) StringIntervalPropertyEditor(org.opennms.netmgt.provision.persist.StringIntervalPropertyEditor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 4 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DatabasePopulator method doPopulateDatabase.

private void doPopulateDatabase() {
    LOG.debug("==== DatabasePopulator Starting ====");
    final NetworkBuilder builder = new NetworkBuilder();
    final OnmsNode node1 = buildNode1(builder);
    getNodeDao().save(node1);
    getNodeDao().flush();
    OnmsNode node2 = buildNode2(builder);
    getNodeDao().save(node2);
    getNodeDao().flush();
    setNode2(node2);
    OnmsNode node3 = buildNode3(builder);
    getNodeDao().save(node3);
    getNodeDao().flush();
    setNode3(node3);
    OnmsNode node4 = buildNode4(builder);
    getNodeDao().save(node4);
    getNodeDao().flush();
    setNode4(node4);
    OnmsNode node5 = buildNode5(builder);
    getNodeDao().save(node5);
    getNodeDao().flush();
    setNode5(node5);
    OnmsNode node6 = buildNode6(builder);
    getNodeDao().save(node6);
    getNodeDao().flush();
    setNode6(node6);
    final OnmsEvent event = buildEvent(builder.getDistPoller());
    event.setEventCreateTime(new Date(1436881548292L));
    event.setEventTime(new Date(1436881548292L));
    getEventDao().save(event);
    getEventDao().flush();
    final OnmsNotification notif = buildTestNotification(builder, event);
    getNotificationDao().save(notif);
    getNotificationDao().flush();
    final OnmsUserNotification userNotif = buildTestUserNotification(notif);
    getUserNotificationDao().save(userNotif);
    getUserNotificationDao().flush();
    final OnmsUserNotification userNotif2 = buildTestUser2Notification(notif);
    getUserNotificationDao().save(userNotif2);
    getUserNotificationDao().flush();
    final OnmsMonitoredService svc = getMonitoredServiceDao().get(node1.getId(), InetAddressUtils.addr("192.168.1.1"), "SNMP");
    final OnmsOutage resolved = new OnmsOutage(new Date(1436881548292L), new Date(1436881548292L), event, event, svc, null, null);
    getOutageDao().save(resolved);
    getOutageDao().flush();
    final OnmsOutage unresolved = new OnmsOutage(new Date(1436881548292L), event, svc);
    getOutageDao().save(unresolved);
    getOutageDao().flush();
    final OnmsAlarm alarm = buildAlarm(event);
    getAlarmDao().save(alarm);
    getAlarmDao().flush();
    final OnmsAcknowledgment ack = new OnmsAcknowledgment();
    ack.setAckTime(new Date(1437073152156L));
    ack.setAckType(AckType.UNSPECIFIED);
    ack.setAckAction(AckAction.UNSPECIFIED);
    ack.setAckUser("admin");
    getAcknowledgmentDao().save(ack);
    getAcknowledgmentDao().flush();
    final OnmsMonitoringLocation def = new OnmsMonitoringLocation();
    def.setLocationName("RDU");
    def.setMonitoringArea("East Coast");
    def.setPollingPackageNames(Collections.singletonList("example1"));
    def.setCollectionPackageNames(Collections.singletonList("example1"));
    def.setGeolocation("Research Triangle Park, NC");
    def.setLatitude(35.715751f);
    def.setLongitude(-79.16262f);
    def.setPriority(1L);
    def.setTags(Collections.singletonList("blah"));
    m_monitoringLocationDao.save(def);
    LOG.debug("= DatabasePopulatorExtension Populate Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null ? daoSupport.getDao() : null;
        Class<? super OnmsDao<?, ?>> daoClass = daoSupport != null ? daoSupport.getDaoClass() : null;
        registerDao(daoClass, dao);
        dao = lookupDao(daoClass);
        eachExtension.onPopulate(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Populate Finished =");
    LOG.debug("==== DatabasePopulator Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 5 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DefaultProvisionService method createLocationIfNecessary.

@Override
public OnmsMonitoringLocation createLocationIfNecessary(final String locationName) {
    if (locationName == null) {
        return createLocationIfNecessary(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    } else {
        OnmsMonitoringLocation location = new OnmsMonitoringLocation();
        location.setLocationName(locationName);
        // NMS-7968: Set monitoring area too because it is a non-null field
        location.setMonitoringArea(locationName);
        return createLocationDefIfNecessary(location);
    }
}
Also used : OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)58 OnmsNode (org.opennms.netmgt.model.OnmsNode)19 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)18 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)13 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)12 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)10 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)8 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)8 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)7 HashSet (java.util.HashSet)5 Before (org.junit.Before)5 InetAddress (java.net.InetAddress)4 HashMap (java.util.HashMap)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 LinkedHashMap (java.util.LinkedHashMap)3