Search in sources :

Example 1 with ServiceMonitorAdaptor

use of org.opennms.netmgt.poller.ServiceMonitorAdaptor in project opennms by OpenNMS.

the class PollerRequestBuilderImpl method execute.

@Override
public CompletableFuture<PollerResponse> execute() {
    if (serviceMonitor == null) {
        throw new IllegalArgumentException("Monitor or monitor class name is required.");
    } else if (service == null) {
        throw new IllegalArgumentException("Monitored service is required.");
    }
    final RpcTarget target = client.getRpcTargetHelper().target().withNodeId(service.getNodeId()).withLocation(service.getNodeLocation()).withSystemId(systemId).withServiceAttributes(attributes).withLocationOverride((s) -> serviceMonitor.getEffectiveLocation(s)).build();
    final PollerRequestDTO request = new PollerRequestDTO();
    request.setLocation(target.getLocation());
    request.setSystemId(target.getSystemId());
    request.setClassName(serviceMonitor.getClass().getCanonicalName());
    request.setServiceName(service.getSvcName());
    request.setAddress(service.getAddress());
    request.setNodeId(service.getNodeId());
    request.setNodeLabel(service.getNodeLabel());
    request.setNodeLocation(service.getNodeLocation());
    request.setTimeToLiveMs(ttlInMs);
    request.addAttributes(attributes);
    // Retrieve the runtime attributes, which may include attributes
    // such as the agent details and other state related attributes
    // which should be included in the request
    final Map<String, Object> parameters = request.getMonitorParameters();
    request.addAttributes(serviceMonitor.getRuntimeAttributes(request, parameters));
    // Execute the request
    return client.getDelegate().execute(request).thenApply(results -> {
        PollStatus pollStatus = results.getPollStatus();
        // Invoke the adapters in the same order as which they were added
        for (ServiceMonitorAdaptor adaptor : adaptors) {
            // The adapters may update the status
            pollStatus = adaptor.handlePollResult(service, attributes, pollStatus);
        }
        results.setPollStatus(pollStatus);
        return results;
    });
}
Also used : ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) ServiceMonitorAdaptor(org.opennms.netmgt.poller.ServiceMonitorAdaptor) List(java.util.List) PollerResponse(org.opennms.netmgt.poller.PollerResponse) Map(java.util.Map) MonitoredService(org.opennms.netmgt.poller.MonitoredService) RpcTarget(org.opennms.core.rpc.api.RpcTarget) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) LinkedList(java.util.LinkedList) PollerRequestBuilder(org.opennms.netmgt.poller.PollerRequestBuilder) PollStatus(org.opennms.netmgt.poller.PollStatus) PollStatus(org.opennms.netmgt.poller.PollStatus) ServiceMonitorAdaptor(org.opennms.netmgt.poller.ServiceMonitorAdaptor) RpcTarget(org.opennms.core.rpc.api.RpcTarget)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 RpcTarget (org.opennms.core.rpc.api.RpcTarget)1 MonitoredService (org.opennms.netmgt.poller.MonitoredService)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 PollerRequestBuilder (org.opennms.netmgt.poller.PollerRequestBuilder)1 PollerResponse (org.opennms.netmgt.poller.PollerResponse)1 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)1 ServiceMonitorAdaptor (org.opennms.netmgt.poller.ServiceMonitorAdaptor)1