Search in sources :

Example 11 with Parameter

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

the class DefaultPollerBackEnd method getParameterMap.

protected static Map<String, Object> getParameterMap(final Service serviceConfig) {
    final Map<String, Object> paramMap = new HashMap<String, Object>();
    for (final Parameter serviceParm : serviceConfig.getParameters()) {
        String value = serviceParm.getValue();
        if (value == null) {
            final Object o = serviceParm.getAnyObject();
            if (o == null) {
                value = "";
            } else if (o instanceof PageSequence) {
                // The PageSequenceMonitor uses PageSequence type parameters in the service definition
                // These need to be marshalled to XML before being sent to the PollerFrontEnd
                value = JaxbUtils.marshal(o);
            } else {
                value = o.toString();
            }
        }
        paramMap.put(serviceParm.getKey(), value);
    }
    return paramMap;
}
Also used : PageSequence(org.opennms.netmgt.config.pagesequence.PageSequence) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Parameter(org.opennms.netmgt.config.poller.Parameter)

Example 12 with Parameter

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

the class PollableServiceConfig method createParameterMap.

private Map<String, Object> createParameterMap(final Service svc) {
    final Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    for (final Parameter p : svc.getParameters()) {
        Object val = p.getValue();
        if (val == null) {
            val = (p.getAnyObject() == null ? "" : p.getAnyObject());
        }
        m.put(p.getKey(), val);
    }
    return m;
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Parameter(org.opennms.netmgt.config.poller.Parameter)

Example 13 with Parameter

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

the class PollerConfigWithPSMIT method testPSM.

@Test
public void testPSM() throws Exception {
    InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("MQ_API_DirectRte_v2");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("MapQuest");
    Assert.assertNotNull(pkg);
    Service svc = PollerConfigFactory.getInstance().getServiceInPackage("MQ_API_DirectRte_v2", pkg);
    Assert.assertNotNull(svc);
    Map<String, Object> parameters = new HashMap<String, Object>();
    for (Parameter p : svc.getParameters()) {
        parameters.put(p.getKey(), p.getValue() == null ? p.getAnyObject() : p.getValue());
    }
    PollStatus status = monitor.poll(new MockMonitoredService(1, "www.mapquest.com", InetAddress.getByName("www.mapquest.com"), "MQ_API_DirectRte_v2"), parameters);
    Assert.assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) Test(org.junit.Test)

Aggregations

Parameter (org.opennms.netmgt.config.poller.Parameter)13 Test (org.junit.Test)7 PollStatus (org.opennms.netmgt.poller.PollStatus)6 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)6 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)5 MonitoredService (org.opennms.netmgt.poller.MonitoredService)5 Service (org.opennms.netmgt.config.poller.Service)4 InetAddress (java.net.InetAddress)2 HashMap (java.util.HashMap)2 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)2 PageSequence (org.opennms.netmgt.config.pagesequence.PageSequence)2 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PollerConfig (org.opennms.netmgt.config.PollerConfig)1 Page (org.opennms.netmgt.config.pagesequence.Page)1 Package (org.opennms.netmgt.config.poller.Package)1