Search in sources :

Example 11 with ResourceId

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

the class AbstractThresholdEvaluatorState method createBasicEvent.

/**
 * <p>createBasicEvent</p>
 *
 * @param uei a {@link java.lang.String} object.
 * @param date a {@link java.util.Date} object.
 * @param dsValue a double.
 * @param resource a {@link org.opennms.netmgt.threshd.CollectionResourceWrapper} object.
 * @param additionalParams a {@link java.util.Map} object.
 * @return a {@link org.opennms.netmgt.xml.event.Event} object.
 */
protected Event createBasicEvent(String uei, Date date, double dsValue, CollectionResourceWrapper resource, Map<String, String> additionalParams) {
    if (resource == null) {
        // Still works, mimic old code when instance value is null.
        resource = new CollectionResourceWrapper(date, 0, null, null, null, null, null, null);
    }
    String dsLabelValue = resource.getFieldValue(resource.getDsLabel());
    if (dsLabelValue == null)
        dsLabelValue = UNKNOWN;
    // create the event to be sent
    EventBuilder bldr = new EventBuilder(uei, "OpenNMS.Threshd." + getThresholdConfig().getDatasourceExpression(), date);
    bldr.setNodeid(resource.getNodeId());
    bldr.setService(resource.getServiceName());
    // As a suggestion from Bug2711. Host Address will contain Interface IP Address for Interface Resource
    bldr.setInterface(addr(resource.getHostAddress()));
    if (resource.isAnInterfaceResource()) {
        // Update threshold label if it is unknown. This is useful because usually reduction-key is associated to label parameter
        if (UNKNOWN.equals(dsLabelValue))
            dsLabelValue = resource.getIfLabel();
        // Set interface specific parameters
        bldr.addParam("ifLabel", resource.getIfLabel());
        bldr.addParam("ifIndex", resource.getIfIndex());
        String ipaddr = resource.getIfInfoValue("ipaddr");
        if (ipaddr != null && !"0.0.0.0".equals(ipaddr)) {
            bldr.addParam("ifIpAddress", ipaddr);
        }
    }
    if (resource.isNodeResource() && UNKNOWN.equals(dsLabelValue)) {
        dsLabelValue = CollectionResource.RESOURCE_TYPE_NODE;
    }
    // Set resource label
    bldr.addParam("label", dsLabelValue);
    // Set event host
    bldr.setHost(InetAddressUtils.getLocalHostName());
    // Add datasource name
    bldr.addParam("ds", getThresholdConfig().getDatasourceExpression());
    // Add threshold description
    final String descr = getThresholdConfig().getBasethresholddef().getDescription().orElse(getThresholdConfig().getDatasourceExpression());
    bldr.addParam("description", descr);
    // Add last known value of the datasource fetched from its RRD file
    bldr.addParam("value", formatValue(dsValue));
    String defaultInstance = resource.isNodeResource() ? CollectionResource.RESOURCE_TYPE_NODE : UNKNOWN;
    // Add the instance name of the resource in question
    bldr.addParam("instance", resource.getInstance() == null ? defaultInstance : resource.getInstance());
    // Add the instance label of the resource in question
    bldr.addParam("instanceLabel", resource.getInstanceLabel() == null ? defaultInstance : resource.getInstanceLabel());
    // Add the resource ID required to call the Graph API.
    final ResourceId resourceId = resource.getResourceId();
    bldr.addParam("resourceId", resourceId != null ? resourceId.toString() : null);
    // Add additional parameters
    if (additionalParams != null) {
        for (String p : additionalParams.keySet()) {
            bldr.addParam(p, additionalParams.get(p));
        }
    }
    return bldr.getEvent();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) ResourceId(org.opennms.netmgt.model.ResourceId)

Example 12 with ResourceId

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

the class DefaultKscReportService method buildDomainReport.

/**
 * {@inheritDoc}
 */
@Override
public Report buildDomainReport(String domain) {
    ResourceId resourceId = ResourceId.get("domain", domain);
    OnmsResource res = getResourceService().getResourceById(resourceId);
    return buildResourceReport(getResourceService(), res, "Domain Report for Domain " + domain);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId)

Example 13 with ResourceId

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

the class CustomGraphChooseParentResourceController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView modelAndView = new ModelAndView("KSC/customGraphChooseResource");
    ResourceId selectedResourceId = ResourceId.fromString(request.getParameter(Parameters.selectedResourceId.toString()));
    if (selectedResourceId != null) {
        OnmsResource selectedResource = m_resourceService.getResourceById(selectedResourceId);
        Map<ResourceId, OnmsResource> selectedResourceAndParents = new HashMap<>();
        OnmsResource r = selectedResource;
        while (r != null) {
            selectedResourceAndParents.put(r.getId(), r);
            r = r.getParent();
        }
        modelAndView.addObject("selectedResourceAndParents", selectedResourceAndParents);
    }
    modelAndView.addObject("resources", getResourceService().findTopLevelResources());
    return modelAndView;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 14 with ResourceId

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

the class DefaultResourceDaoTest method testGetResourceDomainInterfaceExists.

@Test
public void testGetResourceDomainInterfaceExists() throws IOException {
    File snmp = m_fileAnticipator.tempDir("snmp");
    File domain = m_fileAnticipator.tempDir(snmp, "example1");
    File intf = m_fileAnticipator.tempDir(domain, "server1");
    m_fileAnticipator.tempFile(intf, "ifInOctects" + m_rrdFileExtension);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis() - 86400000l)).anyTimes();
    ResourceId resourceId = ResourceId.get("domain", "example1").resolve("interfaceSnmp", "server1");
    m_easyMockUtils.replayAll();
    OnmsResource resource = m_resourceDao.getResourceById(resourceId);
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource should not be null", resource);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 15 with ResourceId

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

the class CustomSpringConfiguration method createResourceDao.

@Bean(name = "resourceDao")
public ResourceDao createResourceDao() {
    return new ResourceDao() {

        @Override
        public Collection<OnmsResourceType> getResourceTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List<OnmsResource> findTopLevelResources() {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceById(ResourceId id) {
            if (id.toString().startsWith("node[1]")) {
                final OnmsResource onmsResource = new OnmsResource(id.toString(), id.toString(), new InterfaceSnmpResourceType(null), new HashSet<OnmsAttribute>(), new ResourcePath());
                if (id.toString().contains("interfaceSnmp[127.0.0.1]")) {
                    final RrdGraphAttribute attribute = new RrdGraphAttribute();
                    attribute.setName("ifInErrors");
                    attribute.setResource(onmsResource);
                    onmsResource.getAttributes().add(attribute);
                }
                return onmsResource;
            }
            return null;
        }

        @Override
        public OnmsResource getResourceForNode(OnmsNode node) {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locationMonitor) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean deleteResourceById(ResourceId resourceId) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) InterfaceSnmpResourceType(org.opennms.netmgt.dao.support.InterfaceSnmpResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Bean(org.springframework.context.annotation.Bean)

Aggregations

ResourceId (org.opennms.netmgt.model.ResourceId)16 OnmsResource (org.opennms.netmgt.model.OnmsResource)11 Date (java.util.Date)3 Test (org.junit.Test)3 Source (org.opennms.netmgt.measurements.model.Source)3 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)3 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ResourceDao (org.opennms.netmgt.dao.api.ResourceDao)2 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)2 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)2 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)2 MissingParameterException (org.opennms.web.servlet.MissingParameterException)2 GraphResults (org.opennms.web.svclayer.model.GraphResults)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1