Skip to content

A java library providing a client to send nagios check results to a remote NRDP server

License

Notifications You must be signed in to change notification settings

mryan43/jsend-nrdp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsend-nrdp

jsend-nrdp is a java library for submitting Nagios passive check results to a remote NRDP server.

Maven

<dependency>
  <groupId>ch.shamu</groupId>
  <artifactId>jsend-nrdp</artifactId>
  <version>${jsend-nrdp.version}</version>
</dependency>

Configuration

this example uses Spring, but you can use any mean of bean creation.

@Configuration
public class NagiosNRDPContext {

	@Value("${nrdp.url}")
	private String url;

	@Value("${nrdp.token}")
	private String token;

	@Value("${nrdp.timeout:2000}")
	private int timeout;

	@Value("${nrdp.threads:2}")
	private int threads;

	@Value("${nrdp.max.queue.size:10000}")
	private int maxQueueSize;
	
	@Value("${nrdp.max.requests.per.second:20}")
	private double maxRequestsPerSecond;
	
	@Bean(destroyMethod = "shutdown")
	public NonBlockingNagiosCheckSender nagiosCheckSender(){

		NRDPServerConnectionSettings settings = new NRDPServerConnectionSettings(url, token, timeout);
		return new NonBlockingNagiosCheckSender(settings, threads, maxQueueSize, maxRequestsPerSecond);
	}

}

Async sending of check results

The NonBlockingNagiosCheckSender implementation uses a pool of background threads to process the http request to nagios. The "send" method will run in the background and log any exception.

NagiosCheckSender resultSender = new NonBlockingNagiosCheckSender(nrdpConnectionSettings, CONCURRENCY_LEVEL, MAX_BACKLOG_SIZE);
NagiosCheckResult resultToSend = new NagiosCheckResult(host, serviceName, serviceState, notif.getMessage());
try {
	resultSender.send(Collections.singletonList(resultToSend));
}
catch (IOException e) { // might happen if send queue is full
	log.error("Could not send check result to Nagios", e);
}

The "sendAsync" method returns a CompletableFuture that allows you to handle the completion of the http request to Nagios (either normal or exceptionnal)

NagiosCheckSender resultSender = new NonBlockingNagiosCheckSender(nrdpConnectionSettings, CONCURRENCY_LEVEL, MAX_BACKLOG_SIZE);
NagiosCheckResult resultToSend = new NagiosCheckResult(host, serviceName, serviceState, notif.getMessage());
try {
    resultSender.sendAsync(Collections.singletonList(resultToSend)).exceptionally(e -> {
      log.error("Error while sending check result to Nagios", e);
    });
}
catch (IOException e) { // might happen if send queue is full
	log.error("Could not send check result to Nagios", e);
}

About

A java library providing a client to send nagios check results to a remote NRDP server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages