Nagios

Since Camel 2.3

Only producer is supported

The Nagios component allows you to send passive checks to Nagios.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-nagios</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

nagios://host[:port][?Options]

Camel provides two abilities with the Nagios component. You can send passive check messages by sending a message to its endpoint.
Camel also provides a EventNotifer which allows you to send notifications to Nagios.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

Configuring Endpoint Options

Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.

A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

Component Options

The Nagios component supports 7 options, which are listed below.

Name Description Default Type

connectionTimeout (producer)

Connection timeout in millis.

5000

int

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

boolean

timeout (producer)

Sending timeout in millis.

5000

int

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

configuration (advanced)

To use a shared NagiosConfiguration.

NagiosConfiguration

encryption (security)

To specify an encryption method.

Enum values:

  • NONE

  • TRIPLE_DES

  • XOR

  • RIJNDAEL128

  • RIJNDAEL192

  • RIJNDAEL256

  • BLOWFISH

Encryption

password (security)

Password to be authenticated when sending checks to Nagios.

String

Endpoint Options

The Nagios endpoint is configured using URI syntax:

nagios:host:port

with the following path and query parameters:

Path Parameters (2 parameters)

Name Description Default Type

host (producer)

Required This is the address of the Nagios host where checks should be send.

String

port (producer)

Required The port number of the host.

int

Query Parameters (6 parameters)

Name Description Default Type

connectionTimeout (producer)

Connection timeout in millis.

5000

int

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

boolean

sendSync (producer)

Whether or not to use synchronous when sending a passive check. Setting it to false will allow Camel to continue routing the message and the passive check message will be send asynchronously.

true

boolean

timeout (producer)

Sending timeout in millis.

5000

int

encryption (security)

To specify an encryption method.

Enum values:

  • NONE

  • TRIPLE_DES

  • XOR

  • RIJNDAEL128

  • RIJNDAEL192

  • RIJNDAEL256

  • BLOWFISH

Encryption

password (security)

Password to be authenticated when sending checks to Nagios.

String

Sending message examples

You can send a message to Nagios where the message payload contains the message. By default it will be OK level and use the CamelContext name as the service name. You can overrule these values using headers as shown above.

For example we send the Hello Nagios message to Nagios as follows:

    template.sendBody("direct:start", "Hello Nagios");

    from("direct:start").to("nagios:127.0.0.1:5667?password=secret").to("mock:result");

To send a CRITICAL message you can send the headers such as:

        Map headers = new HashMap();
        headers.put(NagiosConstants.LEVEL, "CRITICAL");
        headers.put(NagiosConstants.HOST_NAME, "myHost");
        headers.put(NagiosConstants.SERVICE_NAME, "myService");
        template.sendBodyAndHeaders("direct:start", "Hello Nagios", headers);

Using NagiosEventNotifer

The Nagios component also provides an EventNotifer which you can use to send events to Nagios. For example we can enable this from Java as follows:

        NagiosEventNotifier notifier = new NagiosEventNotifier();
        notifier.getConfiguration().setHost("localhost");
        notifier.getConfiguration().setPort(5667);
        notifier.getConfiguration().setPassword("password");

        CamelContext context = ...
        context.getManagementStrategy().addEventNotifier(notifier);
        return context;

In Camel on Spring XML you can declare a <bean> which Camel will automatic pickup and use.

<beans>
  <!-- setup to use nagios event notifier -->
  <bean id="nagiosEventNotifier" class="org.apache.camel.component.nagios.NagiosEventNotifier"/>

  <camelContext>
     ...
  </camelContext>
</beans>

Spring Boot Auto-Configuration

When using nagios with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-nagios-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>

The component supports 8 options, which are listed below.

Name Description Default Type

camel.component.nagios.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.nagios.configuration

To use a shared NagiosConfiguration. The option is a org.apache.camel.component.nagios.NagiosConfiguration type.

NagiosConfiguration

camel.component.nagios.connection-timeout

Connection timeout in millis.

5000

Integer

camel.component.nagios.enabled

Whether to enable auto configuration of the nagios component. This is enabled by default.

Boolean

camel.component.nagios.encryption

To specify an encryption method.

Encryption

camel.component.nagios.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.nagios.password

Password to be authenticated when sending checks to Nagios.

String

camel.component.nagios.timeout

Sending timeout in millis.

5000

Integer