Search in sources :

Example 31 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory 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)

Example 32 with OnmsCategory

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

the class AvailabilityDatabasePopulator method populateDatabase.

public void populateDatabase() {
    OnmsCategory ac = getCategory("DEV_AC");
    OnmsCategory mid = getCategory("IMP_mid");
    OnmsCategory ops = getCategory("OPS_Online");
    OnmsCategory catRouter = getCategory("Routers");
    @SuppressWarnings("unused") OnmsCategory catSwitches = getCategory("Switches");
    OnmsCategory catServers = getCategory("Servers");
    getCategory("Production");
    getCategory("Test");
    getCategory("Development");
    getServiceType("ICMP");
    getServiceType("SNMP");
    getServiceType("HTTP");
    // m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
    // m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
    // 
    // m_db.update("insert into service (serviceid, servicename) values\n"
    // + "(1, 'ICMP');");
    // m_db.update("insert into service (serviceid, servicename) values\n"
    // + "(2, 'HTTP');");
    // m_db.update("insert into service (serviceid, servicename) values\n"
    // + "(3, 'SNMP');");
    // 
    // m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
    // + "(1, 1,'192.168.100.1','M');");
    // m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
    // + "(2, 2,'192.168.100.2','M');");
    // m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
    // + "(3, 2,'192.168.100.3','M');");
    // 
    // m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
    // + "(1,'192.168.100.1',1,'A', 1);");
    // m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
    // + "(2,'192.168.100.2',1,'A', 2);");
    // /*
    // * m_db.update("insert into ifservices (nodeid, ipaddr, serviceid,
    // * status, ipInterfaceId) values " + "(2,'192.168.100.2',2,'A', 2);");
    // */
    // m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
    // + "(2,'192.168.100.3',1,'A', 3);");
    NetworkBuilder builder = new NetworkBuilder();
    setNode1(builder.addNode("test1.availability.opennms.org").setId(1).setType(NodeType.ACTIVE).getNode());
    Assert.assertNotNull("newly built node 1 should not be null", getNode1());
    builder.addCategory(ac);
    builder.addCategory(mid);
    builder.addCategory(ops);
    builder.addCategory(catRouter);
    builder.setBuilding("HQ");
    builder.addInterface("192.168.100.1").setIsManaged("M");
    // getNodeDao().save(builder.getCurrentNode());
    // getNodeDao().flush();
    builder.addService(getServiceType("ICMP")).setStatus("A");
    getNodeDao().save(builder.getCurrentNode());
    getNodeDao().flush();
    builder.addNode("test2.availability.opennms.org").setId(2).setType(NodeType.ACTIVE);
    builder.addCategory(mid);
    builder.addCategory(catServers);
    builder.setBuilding("HQ");
    builder.addInterface("192.168.100.2").setIsManaged("M").setIsSnmpPrimary("P");
    builder.addService(getServiceType("ICMP")).setStatus("A");
    // builder.addService(getServiceType("SNMP")).setStatus("A");;
    builder.addInterface("192.168.100.3").setIsManaged("M");
    builder.addService(getServiceType("ICMP")).setStatus("A");
    // builder.addService(getServiceType("HTTP")).setStatus("A");
    getNodeDao().save(builder.getCurrentNode());
    getNodeDao().flush();
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(builder.getDistPoller());
    event.setEventUei("uei.opennms.org/test");
    event.setEventTime(new Date());
    event.setEventSource("test");
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    getEventDao().save(event);
    getEventDao().flush();
    // + "(2,2,'192.168.100.2',1,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
    try {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        OnmsMonitoredService node1If1Svc1 = getMonitoredServiceDao().get(1, InetAddressUtils.addr("192.168.100.1"), "ICMP");
        OnmsMonitoredService node2If1Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "ICMP");
        @SuppressWarnings("unused") OnmsMonitoredService node2If1Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "SNMP");
        OnmsMonitoredService node2If2Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "ICMP");
        @SuppressWarnings("unused") OnmsMonitoredService node2If2Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "HTTP");
        OnmsOutage outage1 = new OnmsOutage(df.parse("2005-05-01 09:00:00"), df.parse("2005-05-01 09:30:00"), event, event, node1If1Svc1, null, null);
        getOutageDao().save(outage1);
        getOutageDao().flush();
        OnmsOutage outage2 = new OnmsOutage(df.parse("2005-05-01 10:00:00"), df.parse("2005-05-02 10:00:00"), event, event, node2If1Svc1, null, null);
        getOutageDao().save(outage2);
        getOutageDao().flush();
        // test data for LastMonthsDailyAvailability report
        // // insert 30 minute outage on one node - 99.3056% availability
        // m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
        // + "(3,1,'192.168.100.1',1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
        OnmsOutage outage3 = new OnmsOutage(df.parse("2005-04-02 10:00:00"), df.parse("2005-04-02 10:30:00"), event, event, node1If1Svc1, null, null);
        getOutageDao().save(outage3);
        getOutageDao().flush();
        // // insert 60 minute outage on one interface and 59 minute outages on
        // // another - 97.2454
        // m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
        // + "(4,1,'192.168.100.1',1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
        OnmsOutage outage4 = new OnmsOutage(df.parse("2005-04-03 11:30:00"), df.parse("2005-04-03 12:30:00"), event, event, node1If1Svc1, null, null);
        getOutageDao().save(outage4);
        getOutageDao().flush();
        // m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
        // + "(5,2,'192.168.100.2',1,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
        OnmsOutage outage5 = new OnmsOutage(df.parse("2005-04-03 23:00:00"), df.parse("2005-04-03 23:59:00"), event, event, node2If1Svc1, null, null);
        getOutageDao().save(outage5);
        getOutageDao().flush();
        // // test an outage that spans 60 minutes across midnight - 99.3056% on
        // // each day, well, not exactly
        // // its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on
        // // the second.
        // m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
        // + "(6,2,'192.168.100.3',1,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
        OnmsOutage outage6 = new OnmsOutage(df.parse("2005-04-04 23:30:00"), df.parse("2005-04-05 00:30:00"), event, event, node2If2Svc1, null, null);
        getOutageDao().save(outage6);
        getOutageDao().flush();
    } catch (final ParseException e) {
        LOG.warn("populating database failed", e);
    }
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 33 with OnmsCategory

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

the class DefaultSurveillanceViewService method getNotificationsWithCriterias.

/**
 * Returns a list of notifications for a given list of nodes.
 *
 * @param rowCategories  the row catgories
 * @param colCategories  the column categories
 * @param customSeverity the custom severity mapping for notifications
 * @param severity       the severity for these nodes
 * @param criterias      the restrictions to use
 * @return the list of notifications
 */
private List<OnmsNotification> getNotificationsWithCriterias(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories, final Map<OnmsNotification, String> customSeverity, final String severity, final Restriction... criterias) {
    CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNotification.class);
    criteriaBuilder.alias("node", "node");
    final List<String> parameters = new ArrayList<>(rowCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
    parameters.addAll(colCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
    final Type[] types = new Type[parameters.size()];
    Arrays.fill(types, Type.STRING);
    // Restrict on OnmsNotification.nodeId
    criteriaBuilder.sql(createQuery("{alias}.nodeId", rowCategories, colCategories), parameters.toArray(new String[parameters.size()]), types);
    criteriaBuilder.ne("node.type", "D");
    criteriaBuilder.orderBy("pageTime", false);
    Criteria myCriteria = criteriaBuilder.toCriteria();
    for (Restriction criteria : criterias) {
        myCriteria.addRestriction(criteria);
    }
    List<OnmsNotification> notifications = m_notificationDao.findMatching(myCriteria);
    for (OnmsNotification onmsNotification : notifications) {
        customSeverity.put(onmsNotification, severity);
    }
    return notifications;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Restriction(org.opennms.core.criteria.restrictions.Restriction) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) Type(org.opennms.core.criteria.restrictions.SqlRestriction.Type) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 34 with OnmsCategory

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

the class DefaultProvisionService method saveOrUpdate.

@Transactional
private OnmsNode saveOrUpdate(final OnmsNode node) {
    final Set<OnmsCategory> updatedCategories = new HashSet<>();
    for (final Iterator<OnmsCategory> it = node.getCategories().iterator(); it.hasNext(); ) {
        final OnmsCategory category = it.next();
        if (category.getId() == null) {
            it.remove();
            updatedCategories.add(createCategoryIfNecessary(category.getName()));
        }
    }
    node.getCategories().addAll(updatedCategories);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
    return node;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with OnmsCategory

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

the class DefaultProvisionService method getRequisitionedNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public OnmsNode getRequisitionedNode(final String foreignSource, final String foreignId) throws ForeignSourceRepositoryException {
    OnmsNodeRequisition nodeReq = null;
    try {
        nodeReq = m_foreignSourceRepository.getNodeRequisition(foreignSource, foreignId);
    } catch (ForeignSourceRepositoryException e) {
    // just fall through, nodeReq will be null
    }
    if (nodeReq == null) {
        LOG.warn("nodeReq for node {}:{} cannot be null!", foreignSource, foreignId);
        return null;
    }
    final OnmsNode node = nodeReq.constructOnmsNodeFromRequisition();
    // fill in real database categories
    final HashSet<OnmsCategory> dbCategories = new HashSet<>();
    for (final OnmsCategory category : node.getCategories()) {
        dbCategories.add(createCategoryIfNecessary(category.getName()));
    }
    node.setCategories(dbCategories);
    if (node.getLocation() == null || Strings.isNullOrEmpty(node.getLocation().getLocationName())) {
        node.setLocation(m_monitoringLocationDao.getDefaultLocation());
    }
    // fill in real service types
    node.visit(new ServiceTypeFulfiller());
    return node;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)63 OnmsNode (org.opennms.netmgt.model.OnmsNode)29 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)9 Path (javax.ws.rs.Path)7 LinkedHashSet (java.util.LinkedHashSet)6 HashSet (java.util.HashSet)5 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 Transactional (org.springframework.transaction.annotation.Transactional)4 GET (javax.ws.rs.GET)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 SearchResult (org.opennms.features.topology.api.topo.SearchResult)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3