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();
}
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);
}
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;
}
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);
}
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();
}
};
}
Aggregations