Updates
- 2009-05-03 - Version 1.2 - Core API now has support for triple-DES encryption and non blocking sender
- 2009-02-03 - Version 1.1.1 - minor update released, main improvement is no longer any dependencies on commons-io and commons-lang for the Core API
- 2008-11-30 - Version 1.1 - Codebase split into two projects, core API and CLI tool. Ant used as build tool instead of Maven.
- 2008-11-18 - Version 1.0 - first release
Overview
JSend NSCA is a Java API and command line tool for sending Nagios Passive Checks to the Nagios NSCA add on.
By using the JSend NSCA core API, you can easily integrate your Java applications into a Nagios monitored environment thereby notifying Nagios of problems and issues during the running of your application.
The Jsend NSCA CLI command line tool wraps the API and allows you to send passive checks from the command line.
Background
JSend NSCA was developed as the company I’m working for uses Nagios to monitor applications and servers. For existing applications written in Perl and c, there are options available to send passive checks but for Java applications, the option available was to shell out and execute the send_nsca command line tool.
Although send_nsca worked in this manner, it’s ugly and we preferred having the code within our applications for better performance.
A search on the internet revealed a few options such as the NagiosAppender for log4j but in the end we settled on writing our own client. This client is currently in use thus proving the feasibility of the approach.
On the back of this, I decided to write JSend NSCA from the ground up as an exercise in TDD and thought I would make it available as an open source project so other developers can benefit from the functionality.
Acknowledgements
Thanks goes to the NagiosAppender project for details of the NSCA protocol and inspiration for this project
Quick Start Example Code
import java.io.IOException;
import com.googlecode.jsendnsca.core.*;
import com.googlecode.jsendnsca.core.builders.*;
public class QuickStart {
public static void main(String[] args) {
NagiosSettings nagiosSettings = NagiosSettingsBuilder
.withNagiosHost("localhost")
.withPort(5667)
.withConnectionTimeout(5000)
.withResponseTimeout(15000)
.withPassword("hasturrocks")
.create();
NagiosPassiveCheckSender passiveAlerter = new NagiosPassiveCheckSender(
nagiosSettings);
MessagePayload payload = MessagePayloadBuilder
.withHostname("localhost")
.withLevel(Level.CRITICAL)
.withServiceName("Test Service Name")
.withMessage("Test Message")
.create();
try {
passiveAlerter.send(payload);
} catch (NagiosException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}