introspective-monitoring

Introspective Monitoring library

License

License

GroupId

GroupId

com.ning
ArtifactId

ArtifactId

nagios
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

introspective-monitoring
Introspective Monitoring library
Project URL

Project URL

http://github.com/pierre/introspective-monitoring
Source Code Management

Source Code Management

http://github.com/pierre/introspective-monitoring/tree/master

Download nagios

How to add to project

<!-- https://jarcasting.com/artifacts/com.ning/nagios/ -->
<dependency>
    <groupId>com.ning</groupId>
    <artifactId>nagios</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.ning/nagios/
implementation 'com.ning:nagios:0.0.2'
// https://jarcasting.com/artifacts/com.ning/nagios/
implementation ("com.ning:nagios:0.0.2")
'com.ning:nagios:jar:0.0.2'
<dependency org="com.ning" name="nagios" rev="0.0.2">
  <artifact name="nagios" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.ning', module='nagios', version='0.0.2')
)
libraryDependencies += "com.ning" % "nagios" % "0.0.2"
[com.ning/nagios "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.googlecode.jsendnsca » jsendnsca jar 2.0.1
log4j : log4j jar 1.2.16
org.skife.config : config-magic jar 0.8

Project Modules

There are no modules declared in this project.

Introspective Monitoring

Enough with active checks! Make your service advertise its state to Nagios.

HOWTO

  1. Define your service check by implementing com.ning.nagios.ServiceCheck

  2. Configure how your service talks to Nagios by implementing com.ning.nagios.ServiceMonitor

  3. Register the check with your ServiceMonitor

For example, assuming you have a Config object:

public class NagiosMonitor implements ServiceMonitor
{
    private static final Logger log = Logger.getLogger(NagiosMonitor.class);

    private final ConcurrentMap<String, MonitoredService> services = new ConcurrentHashMap<String, MonitoredService>();
    private final PassiveCheckSender sender;
    private final MessagePayloadBuilder payloadBuilder;
    private final TimeSpan checkRate;

    @Inject
    public NagiosMonitor(final Config config)
    {
        this.sender = new NagiosPassiveCheckSender(new NagiosSettingsBuilder()
            .withNagiosHost(config.getNagiosHost())
            .withPort(config.getNagiosPort())
            .withEncryption(config.getNagiosEncryption())
            .withPassword(config.getNagiosPassword())
            .withConnectionTimeout((int) config.getNagiosTimeout().getMillis())
            .withResponseTimeout((int) config.getNagiosTimeout().getMillis())
            .create());
        this.payloadBuilder = new MessagePayloadBuilder().withHostname(config.getNagiosReportedHostname());
        this.checkRate = config.getNagiosCheckRate();
    }

    @Override
    public MonitoredService registerServiceCheck(final String serviceName, final ServiceCheck check)
    {
        final MonitoredService service = new JsendnscaService(serviceName, checkRate, check, sender, payloadBuilder);
        final MonitoredService existingService = services.putIfAbsent(serviceName, service);

        if (existingService != null) {
            throw new IllegalStateException(String.format("Service check [%s] has already been registered", serviceName));
        }

        log.info(String.format("Added service [%s] with check rate of [%s]", service, checkRate));

        return service;
    }
}

You can now do

// Talk to Nagios
final ServiceCheck check = injector.getInstance(ServiceCheck.class);
final ServiceMonitor serviceMonitor = injector.getInstance(ServiceMonitor.class);
serviceMonitor.registerServiceCheck(config.getNagiosServiceName(), check);

Note: the library comes with com.ning.nagios.FakeNagiosMonitor for testing.

License (see LICENSE-2.0.txt file for full license)

Copyright 2011 Ning

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Versions

Version
0.0.2
0.0.1