This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers in repository https://gitbox.apache.org/repos/asf/camel.git
commit a53ff14f633ed2fb8c5a1d9aef2ca275401e369e Author: Nicolas Filotto <[email protected]> AuthorDate: Fri Apr 1 12:15:14 2022 +0200 CAMEL-17792: Add doc about the message headers of camel-nagios --- .../org/apache/camel/component/nagios/nagios.json | 5 +++ .../src/main/docs/nagios-component.adoc | 43 +++++++++++----------- .../camel/component/nagios/NagiosConstants.java | 5 +++ .../camel/component/nagios/NagiosEndpoint.java | 2 +- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/components/camel-nagios/src/generated/resources/org/apache/camel/component/nagios/nagios.json b/components/camel-nagios/src/generated/resources/org/apache/camel/component/nagios/nagios.json index 9e727d1..7c82aa8 100644 --- a/components/camel-nagios/src/generated/resources/org/apache/camel/component/nagios/nagios.json +++ b/components/camel-nagios/src/generated/resources/org/apache/camel/component/nagios/nagios.json @@ -30,6 +30,11 @@ "encryption": { "kind": "property", "displayName": "Encryption", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "com.googlecode.jsendnsca.encryption.Encryption", "enum": [ "NONE", "TRIPLE_DES", "XOR", "RIJNDAEL128", "RIJNDAEL192", "RIJNDAEL256", "BLOWFISH" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.nagios.NagiosConfiguration", "configurationField": "configuration", "descrip [...] "password": { "kind": "property", "displayName": "Password", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.nagios.NagiosConfiguration", "configurationField": "configuration", "description": "Password to be authenticated when sending checks to Nagios." } }, + "headers": { + "CamelNagiosHostName": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "localhost", "description": "The hostname to be sent in this passive check." }, + "CamelNagiosLevel": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "com.googlecode.jsendnsca.Level", "enum": [ "OK", "WARNING", "CRITICAL", "UNKNOWN" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The level of the passive check." }, + "CamelNagiosServiceName": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "The context name", "description": "The service name." } + }, "properties": { "host": { "kind": "path", "displayName": "Host", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.nagios.NagiosConfiguration", "configurationField": "configuration", "description": "This is the address of the Nagios host where checks should be send." }, "port": { "kind": "path", "displayName": "Port", "group": "producer", "label": "", "required": true, "type": "integer", "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.nagios.NagiosConfiguration", "configurationField": "configuration", "description": "The port number of the host." }, diff --git a/components/camel-nagios/src/main/docs/nagios-component.adoc b/components/camel-nagios/src/main/docs/nagios-component.adoc index 176ef6b..d93d9a3 100644 --- a/components/camel-nagios/src/main/docs/nagios-component.adoc +++ b/components/camel-nagios/src/main/docs/nagios-component.adoc @@ -38,7 +38,7 @@ nagios://host[:port][?Options] Camel provides two abilities with the xref:nagios-component.adoc[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. +Camel also provides a EventNotifier which allows you to send notifications to Nagios. // component-configure options: START @@ -53,50 +53,51 @@ include::partial$component-endpoint-options.adoc[] // endpoint options: START // endpoint options: END - +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END == 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. +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: +For example, we send the `Hello Nagios` message to Nagios as follows: [source,java] --------------------------------------------------------------------------------------- - template.sendBody("direct:start", "Hello Nagios"); - - from("direct:start").to("nagios:127.0.0.1:5667?password=secret").to("mock:result"); +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: [source,java] ----------------------------------------------------------------------------- - 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); +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 xref:nagios-component.adoc[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: +For example, we can enable this from Java as follows: [source,java] ------------------------------------------------------------------- - NagiosEventNotifier notifier = new NagiosEventNotifier(); - notifier.getConfiguration().setHost("localhost"); - notifier.getConfiguration().setPort(5667); - notifier.getConfiguration().setPassword("password"); - - CamelContext context = ... - context.getManagementStrategy().addEventNotifier(notifier); - return context; +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. diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConstants.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConstants.java index eab3be0..b8d576b 100644 --- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConstants.java +++ b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConstants.java @@ -16,10 +16,15 @@ */ package org.apache.camel.component.nagios; +import org.apache.camel.spi.Metadata; + public final class NagiosConstants { + @Metadata(description = "The hostname to be sent in this passive check.", javaType = "String", defaultValue = "localhost") public static final String HOST_NAME = "CamelNagiosHostName"; + @Metadata(description = "The level of the passive check.", javaType = "com.googlecode.jsendnsca.Level") public static final String LEVEL = "CamelNagiosLevel"; + @Metadata(description = "The service name.", javaType = "String", defaultValue = "The context name") public static final String SERVICE_NAME = "CamelNagiosServiceName"; private NagiosConstants() { diff --git a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java index fafadab..31a2bbe 100644 --- a/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java +++ b/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEndpoint.java @@ -33,7 +33,7 @@ import org.apache.camel.util.ObjectHelper; * Send passive checks to Nagios using JSendNSCA. */ @UriEndpoint(firstVersion = "2.3.0", scheme = "nagios", title = "Nagios", syntax = "nagios:host:port", producerOnly = true, - category = { Category.MONITORING }) + category = { Category.MONITORING }, headersClass = NagiosConstants.class) public class NagiosEndpoint extends DefaultEndpoint { private PassiveCheckSender sender;
