Search in sources :

Example 1 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class MockNetworkTest method testPollerConfig.

public void testPollerConfig() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setPollInterval("HTTP", 750L);
    m_pollerConfig.setPollerThreads(5);
    m_pollerConfig.setCriticalService("YAHOO");
    PollerConfig pollerConfig = m_pollerConfig;
    // test the nodeOutageProcessing setting works
    assertTrue(pollerConfig.isNodeOutageProcessingEnabled());
    // test to ensure that the poller has packages
    Enumeration<Package> pkgs = pollerConfig.enumeratePackage();
    assertNotNull(pkgs);
    int pkgCount = 0;
    Package pkg = null;
    while (pkgs.hasMoreElements()) {
        pkg = (Package) pkgs.nextElement();
        pkgCount++;
    }
    assertTrue(pkgCount > 0);
    // ensure a sample interface is in the package
    assertTrue(pollerConfig.isInterfaceInPackage("192.168.1.1", pkg));
    for (final Service svc : pkg.getServices()) {
        if ("ICMP".equals(svc.getName()))
            assertEquals(Long.valueOf(500L), svc.getInterval());
        else if ("HTTP".equals(svc.getName()))
            assertEquals(Long.valueOf(750L), svc.getInterval());
        else
            assertEquals(Long.valueOf(1000L), svc.getInterval());
    }
    // ensure that setting the thread worked
    assertEquals(5, pollerConfig.getThreads());
    // ensure that setting the critical service worked
    assertEquals("YAHOO", pollerConfig.getCriticalService());
    // ensure that we have service monitors to the sevices
    assertNotNull(pollerConfig.getServiceMonitor("SMTP"));
}
Also used : PollerConfig(org.opennms.netmgt.config.PollerConfig) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 2 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class MockPollerConfig method setPollInterval.

public void setPollInterval(final Package pkg, final String svcName, final long interval) {
    final Service svc = findService(pkg, svcName);
    if (svc == null)
        throw new IllegalArgumentException("No service named: " + svcName + " in package " + pkg);
    svc.setInterval(interval);
}
Also used : OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service)

Example 3 with Service

use of org.opennms.netmgt.config.poller.Service in project opennms by OpenNMS.

the class MockPollerConfigTest method testPollerConfig.

public void testPollerConfig() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setPollInterval("HTTP", 750L);
    m_pollerConfig.setPollerThreads(5);
    m_pollerConfig.setCriticalService("YAHOO");
    // test the nodeOutageProcessing setting works
    assertTrue(m_pollerConfig.isNodeOutageProcessingEnabled());
    // test to ensure that the poller has packages
    Enumeration<Package> pkgs = m_pollerConfig.enumeratePackage();
    assertNotNull(pkgs);
    int pkgCount = 0;
    Package pkg = null;
    while (pkgs.hasMoreElements()) {
        pkg = pkgs.nextElement();
        pkgCount++;
    }
    assertTrue(pkgCount > 0);
    // ensure a sample interface is in the package
    assertTrue(m_pollerConfig.isInterfaceInPackage("192.168.1.1", pkg));
    assertFalse(m_pollerConfig.isInterfaceInPackage("192.168.1.7", pkg));
    int svcCount = 0;
    boolean icmpFound = false;
    boolean httpFound = false;
    for (final Service svc : pkg.getServices()) {
        svcCount++;
        if ("ICMP".equals(svc.getName())) {
            icmpFound = true;
            assertEquals(Long.valueOf(500L), svc.getInterval());
        } else if ("HTTP".equals(svc.getName())) {
            httpFound = true;
            assertEquals(Long.valueOf(750L), svc.getInterval());
        } else {
            assertEquals(Long.valueOf(1000L), svc.getInterval());
        }
    }
    assertTrue(icmpFound);
    assertTrue(httpFound);
    assertEquals(3, svcCount);
    // ensure that setting the thread worked
    assertEquals(5, m_pollerConfig.getThreads());
    // ensure that setting the critical service worked
    assertEquals("YAHOO", m_pollerConfig.getCriticalService());
    // ensure that we have service monitors to the sevices
    assertNotNull(m_pollerConfig.getServiceMonitor("SMTP"));
}
Also used : Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package)

Example 4 with Service

use of org.opennms.netmgt.config.poller.Service 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 5 with Service

use of org.opennms.netmgt.config.poller.Service 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)

Aggregations

Service (org.opennms.netmgt.config.poller.Service)22 Package (org.opennms.netmgt.config.poller.Package)11 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)6 Test (org.junit.Test)5 PollerConfig (org.opennms.netmgt.config.PollerConfig)5 Parameter (org.opennms.netmgt.config.poller.Parameter)5 PollStatus (org.opennms.netmgt.poller.PollStatus)5 File (java.io.File)4 Rrd (org.opennms.netmgt.config.poller.Rrd)4 Downtime (org.opennms.netmgt.config.poller.Downtime)3 Filter (org.opennms.netmgt.config.poller.Filter)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 MonitoredService (org.opennms.netmgt.poller.MonitoredService)3 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2