Search in sources :

Example 86 with OnmsNode

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

the class Test method doExecute.

@Override
protected Object doExecute() throws Exception {
    // Parse/validate the IP address
    final InetAddress addr = InetAddressUtils.addr(ipAddress);
    if (addr == null) {
        throw new IllegalStateException("Error getting InetAddress object for " + ipAddress);
    }
    final Map<String, Object> parameters = Poll.parse(serviceParameters);
    final MonitoredService monSvc = transactionTemplate.execute(new TransactionCallback<MonitoredService>() {

        @Override
        public MonitoredService doInTransaction(TransactionStatus status) {
            final List<OnmsIpInterface> ips = ipInterfaceDao.findByIpAddress(ipAddress);
            if (ips == null || ips.size() == 0) {
                System.err.printf("Error: Can't find the IP address %s on the database\n", ipAddress);
                return null;
            }
            if (ips.size() > 1) {
                System.out.printf("Warning: there are several IP interface objects associated with the IP address %s (picking the first one)\n", ipAddress);
            }
            OnmsNode n = ips.get(0).getNode();
            return new SimpleMonitoredService(addr, n.getId(), n.getLabel(), serviceName);
        }
    });
    if (monSvc == null) {
        // in which case we already printed an error message above
        return null;
    }
    // Read a fresh copy of poller-configuration.xml
    final PollerConfig pollerConfig = ReadOnlyPollerConfigManager.create();
    System.out.printf("Checking service %s on IP %s%n", serviceName, ipAddress);
    final org.opennms.netmgt.config.poller.Package pkg = packageName == null ? pollerConfig.getFirstLocalPackageMatch(ipAddress) : pollerConfig.getPackage(packageName);
    if (pkg == null) {
        System.err.printf("Error: Package %s doesn't exist%n", packageName);
        return null;
    }
    System.out.printf("Package: %s%n", pkg.getName());
    final Service svc = pollerConfig.getServiceInPackage(serviceName, pkg);
    if (svc == null) {
        System.err.printf("Error: Service %s not defined on package %s%n", serviceName, packageName);
        return null;
    }
    ServiceMonitor monitor = null;
    if (monitorClass == null) {
        monitor = pollerConfig.getServiceMonitor(serviceName);
        if (monitor == null) {
            System.err.printf("Error: Service %s doesn't have a monitor class defined%n", serviceName);
            return null;
        }
    } else {
        monitor = registry.getMonitorByClassName(monitorClass);
        System.err.printf("Error: No monitor found with class name %s\n", monitorClass);
        if (monitor == null) {
            return null;
        }
    }
    System.out.printf("Monitor: %s%n", monitor.getClass().getName());
    if (pollerConfig.isPolledLocally(ipAddress, serviceName)) {
        for (Parameter p : svc.getParameters()) {
            if (!parameters.containsKey(p.getKey())) {
                String value = p.getValue();
                if (value == null) {
                    try {
                        value = JaxbUtils.marshal(p.getAnyObject());
                    } catch (Exception e) {
                    }
                }
                parameters.put(p.getKey(), value);
            }
        }
        for (Entry<String, Object> e : parameters.entrySet()) {
            System.out.printf("Parameter %s : %s%n", e.getKey(), e.getValue());
        }
        try {
            PollStatus status = monitor.poll(monSvc, parameters);
            System.out.printf("Available ? %s (status %s[%s])%n", status.isAvailable(), status.getStatusName(), status.getStatusCode());
            if (status.isAvailable()) {
                System.out.printf("Response time: %s%n", status.getResponseTime());
            } else {
                if (status.getReason() != null) {
                    System.out.printf("Reason: %s%n", status.getReason());
                }
            }
        } catch (Exception e) {
            System.err.println("Error: Can't execute the monitor. " + e.getMessage());
            return null;
        }
    } else {
        System.err.printf("Error: Polling is not enabled for service %s using IP %s%n", serviceName, ipAddress);
    }
    return null;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) PollStatus(org.opennms.netmgt.poller.PollStatus) SimpleMonitoredService(org.opennms.netmgt.poller.support.SimpleMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) PollerConfig(org.opennms.netmgt.config.PollerConfig) TransactionStatus(org.springframework.transaction.TransactionStatus) SimpleMonitoredService(org.opennms.netmgt.poller.support.SimpleMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Service(org.opennms.netmgt.config.poller.Service) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) SimpleMonitoredService(org.opennms.netmgt.poller.support.SimpleMonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) List(java.util.List) InetAddress(java.net.InetAddress)

Example 87 with OnmsNode

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

the class PollerRpcTimeoutIT method setUp.

@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface(str(InetAddressUtils.UNPINGABLE_ADDRESS));
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    // Add a location that no systems are monitoring
    OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
    m_monitoringLocationDao.save(location);
    // Update all of the nodes to have the nonexistent location
    for (OnmsNode node : m_nodeDao.findAll()) {
        node.setLocation(location);
        m_nodeDao.save(node);
    }
    InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    // Sanity check the config
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
    Assert.assertNotNull(pkg);
    Service svc = pkg.getServices().iterator().next();
    Assert.assertEquals("HTTP", svc.getName());
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(factory);
    pollContext.setQueryManager(m_queryManager);
    pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    PollableNetwork network = new PollableNetwork(pollContext);
    m_poller = new Poller();
    m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
    m_poller.setOutageDao(m_outageDao);
    m_poller.setTransactionTemplate(m_transactionTemplate);
    m_poller.setEventIpcManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(m_queryManager);
    m_poller.setPollerConfig(factory);
    m_poller.setPollOutagesConfig(m_pollOutagesConfig);
    m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) MockNetwork(org.opennms.netmgt.mock.MockNetwork) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 88 with OnmsNode

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

the class DemandPollServiceTest method testPollMonitoredService.

public void testPollMonitoredService() throws EventProxyException {
    final int expectedResultId = m_pollStore.getExpectedId();
    // anticipate a call to the dao save with a pollResult
    m_demandPollDao.save(isA(DemandPoll.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
            m_pollStore.save(poll);
            return null;
        }
    });
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
    m_pollerService.poll(monSvc, expectedResultId);
    replay(m_demandPollDao);
    replay(m_monitoredServiceDao);
    replay(m_pollerService);
    DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
    verify(m_demandPollDao);
    verify(m_monitoredServiceDao);
    verify(m_pollerService);
    assertNotNull("Null is an invalid response from pollMonitoredService", result);
    assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 89 with OnmsNode

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

the class GenericInfoPanelItemProvider method createVertexContext.

public Map<String, Object> createVertexContext(final VertexRef vertex) {
    final Map<String, Object> context = Maps.newHashMap();
    if (vertex instanceof AbstractVertex) {
        final AbstractVertex abstractVertex = (AbstractVertex) vertex;
        if (abstractVertex.getNodeID() != null) {
            final OnmsNode node = this.nodeDao.get(abstractVertex.getNodeID());
            if (node != null) {
                context.put("node", node);
            }
        }
    }
    context.put("vertex", vertex);
    return context;
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) OnmsNode(org.opennms.netmgt.model.OnmsNode)

Example 90 with OnmsNode

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

the class RrdDashletConfigurationWindow method setRrdGraphEntryFromKscReportGraph.

private void setRrdGraphEntryFromKscReportGraph(RrdGraphEntry rrdGraphEntry, Graph graph) {
    String graphLabel, graphId, graphUrl, nodeId, nodeLabel, resourceLabel, resourceTypeId, resourceTypeLabel;
    String[] graphTypeArr = graph.getGraphtype().split("\\.");
    String[] resourceIdArr = graph.getResourceId().orElse("").split("\\.");
    nodeId = resourceIdArr[0].split("[\\[\\]]")[1];
    String resourceTypeName = resourceIdArr[1].split("[\\[\\]]")[0];
    OnmsNode onmsNode = m_nodeDao.get(nodeId);
    nodeLabel = onmsNode.getLabel();
    Map<OnmsResourceType, List<OnmsResource>> resourceTypeListMap = m_rrdGraphHelper.getResourceTypeMapForNodeId(nodeId);
    for (Map.Entry<OnmsResourceType, List<OnmsResource>> entry : resourceTypeListMap.entrySet()) {
        OnmsResourceType onmsResourceType = entry.getKey();
        if (resourceTypeName.equals(onmsResourceType.getName())) {
            resourceTypeId = "node[" + nodeId + "]." + resourceTypeName;
            resourceTypeLabel = onmsResourceType.getLabel();
            List<OnmsResource> onmsResourceList = entry.getValue();
            for (OnmsResource onmsResource : onmsResourceList) {
                String onmsResourceId = onmsResource.getId().toString();
                if (onmsResourceId.equals(graph.getResourceId())) {
                    resourceLabel = onmsResource.getLabel();
                    Map<String, String> resultsMap = m_rrdGraphHelper.getGraphResultsForResourceId(onmsResource.getId());
                    Map<String, String> nameTitleMapping = m_rrdGraphHelper.getGraphNameTitleMappingForResourceId(onmsResource.getId());
                    graphId = onmsResourceId + "." + nameTitleMapping.get(graph.getGraphtype());
                    graphLabel = nameTitleMapping.get(graph.getGraphtype());
                    graphUrl = resultsMap.get(graph.getGraphtype());
                    rrdGraphEntry.setNodeId(nodeId);
                    rrdGraphEntry.setNodeLabel(nodeLabel);
                    rrdGraphEntry.setResourceTypeId(resourceTypeId);
                    rrdGraphEntry.setResourceTypeLabel(resourceTypeLabel);
                    rrdGraphEntry.setResourceId(onmsResourceId);
                    rrdGraphEntry.setResourceLabel(resourceLabel);
                    rrdGraphEntry.setGraphId(graphId);
                    rrdGraphEntry.setGraphLabel(graphLabel);
                    rrdGraphEntry.setGraphUrl(graphUrl);
                    break;
                }
            }
            break;
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) List(java.util.List) Map(java.util.Map)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23