This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 63a1bf3 Added nagios native support #1726 63a1bf3 is described below commit 63a1bf390db6feefa748521bc7f4f5db7b4101b5 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Wed Oct 28 09:22:08 2020 +0100 Added nagios native support #1726 --- .../ROOT/pages/reference/extensions/nagios.adoc | 8 +- .../ROOT/partials/reference/components/nagios.adoc | 6 +- extensions-jvm/pom.xml | 1 - .../nagios/deployment/pom.xml | 0 .../nagios/deployment/NagiosProcessor.java | 14 --- {extensions-jvm => extensions}/nagios/pom.xml | 1 - .../nagios/runtime/pom.xml | 1 + .../main/resources/META-INF/quarkus-extension.yaml | 3 +- extensions/pom.xml | 1 + .../nagios}/pom.xml | 67 ++++++++++- .../component/nagios/it/NagiosResource.java | 34 +++--- .../quarkus/component/nagios/it/NagiosIT.java | 17 +-- .../quarkus/component/nagios/it/NagiosTest.java | 25 +++- .../component/nagios/it/NagiosTestResource.java | 130 +++++++++++++++++++++ integration-tests/pom.xml | 1 + tooling/scripts/test-categories.yaml | 1 + 16 files changed, 246 insertions(+), 64 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/nagios.adoc b/docs/modules/ROOT/pages/reference/extensions/nagios.adoc index 9cb6ec5..e286907 100644 --- a/docs/modules/ROOT/pages/reference/extensions/nagios.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/nagios.adoc @@ -2,15 +2,15 @@ // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page = Nagios :cq-artifact-id: camel-quarkus-nagios -:cq-native-supported: false -:cq-status: Preview +:cq-native-supported: true +:cq-status: Stable :cq-description: Send passive checks to Nagios using JSendNSCA. :cq-deprecated: false :cq-jvm-since: 1.1.0 -:cq-native-since: n/a +:cq-native-since: 1.4.0 [.badges] -[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported## +[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.4.0## Send passive checks to Nagios using JSendNSCA. diff --git a/docs/modules/ROOT/partials/reference/components/nagios.adoc b/docs/modules/ROOT/partials/reference/components/nagios.adoc index aac3fc8..74bdc8a 100644 --- a/docs/modules/ROOT/partials/reference/components/nagios.adoc +++ b/docs/modules/ROOT/partials/reference/components/nagios.adoc @@ -2,11 +2,11 @@ // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page :cq-artifact-id: camel-quarkus-nagios :cq-artifact-id-base: nagios -:cq-native-supported: false -:cq-status: Preview +:cq-native-supported: true +:cq-status: Stable :cq-deprecated: false :cq-jvm-since: 1.1.0 -:cq-native-since: n/a +:cq-native-since: 1.4.0 :cq-camel-part-name: nagios :cq-camel-part-title: Nagios :cq-camel-part-description: Send passive checks to Nagios using JSendNSCA. diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml index de80a2f..e1bd37a 100644 --- a/extensions-jvm/pom.xml +++ b/extensions-jvm/pom.xml @@ -108,7 +108,6 @@ <module>msv</module> <module>mvel</module> <module>mybatis</module> - <module>nagios</module> <module>nitrite</module> <module>ognl</module> <module>openstack</module> diff --git a/extensions-jvm/nagios/deployment/pom.xml b/extensions/nagios/deployment/pom.xml similarity index 100% rename from extensions-jvm/nagios/deployment/pom.xml rename to extensions/nagios/deployment/pom.xml diff --git a/extensions-jvm/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java b/extensions/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java similarity index 68% rename from extensions-jvm/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java rename to extensions/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java index 9e0402d..53f99ef 100644 --- a/extensions-jvm/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java +++ b/extensions/nagios/deployment/src/main/java/org/apache/camel/quarkus/component/nagios/deployment/NagiosProcessor.java @@ -17,11 +17,7 @@ package org.apache.camel.quarkus.component.nagios.deployment; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.ExecutionTime; -import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.FeatureBuildItem; -import io.quarkus.deployment.pkg.steps.NativeBuild; -import org.apache.camel.quarkus.core.JvmOnlyRecorder; import org.jboss.logging.Logger; class NagiosProcessor { @@ -33,14 +29,4 @@ class NagiosProcessor { FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); } - - /** - * Remove this once this extension starts supporting the native mode. - */ - @BuildStep(onlyIf = NativeBuild.class) - @Record(value = ExecutionTime.RUNTIME_INIT) - void warnJvmInNative(JvmOnlyRecorder recorder) { - JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time - recorder.warnJvmInNative(FEATURE); // warn at runtime - } } diff --git a/extensions-jvm/nagios/pom.xml b/extensions/nagios/pom.xml similarity index 97% rename from extensions-jvm/nagios/pom.xml rename to extensions/nagios/pom.xml index cd283e9..4422b3f 100644 --- a/extensions-jvm/nagios/pom.xml +++ b/extensions/nagios/pom.xml @@ -33,6 +33,5 @@ <modules> <module>deployment</module> <module>runtime</module> - <module>integration-test</module> </modules> </project> diff --git a/extensions-jvm/nagios/runtime/pom.xml b/extensions/nagios/runtime/pom.xml similarity index 98% rename from extensions-jvm/nagios/runtime/pom.xml rename to extensions/nagios/runtime/pom.xml index 3be19d9..33b0a6e 100644 --- a/extensions-jvm/nagios/runtime/pom.xml +++ b/extensions/nagios/runtime/pom.xml @@ -32,6 +32,7 @@ <properties> <camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>1.4.0</camel.quarkus.nativeSince> </properties> <dependencyManagement> diff --git a/extensions-jvm/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml similarity index 97% rename from extensions-jvm/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml rename to extensions/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml index bb8b9dd..757691f 100644 --- a/extensions-jvm/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/nagios/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -24,9 +24,8 @@ name: "Camel Nagios" description: "Send passive checks to Nagios using JSendNSCA" metadata: - unlisted: true guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/nagios.html" categories: - "integration" status: - - "preview" + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index 51fb2b1..3d1afa0 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -152,6 +152,7 @@ <module>mongodb</module> <module>mongodb-gridfs</module> <module>mustache</module> + <module>nagios</module> <module>nats</module> <module>netty</module> <module>netty-http</module> diff --git a/extensions-jvm/nagios/integration-test/pom.xml b/integration-tests/nagios/pom.xml similarity index 58% rename from extensions-jvm/nagios/integration-test/pom.xml rename to integration-tests/nagios/pom.xml index 454c7ff..c1c1fe1 100644 --- a/extensions-jvm/nagios/integration-test/pom.xml +++ b/integration-tests/nagios/pom.xml @@ -21,13 +21,12 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-build-parent-it</artifactId> + <artifactId>camel-quarkus-integration-tests</artifactId> <version>1.4.0-SNAPSHOT</version> - <relativePath>../../../poms/build-parent-it/pom.xml</relativePath> </parent> - <artifactId>camel-quarkus-nagios-integration-test</artifactId> - <name>Camel Quarkus :: Nagios :: Integration Test</name> + <artifactId>camel-quarkus-integration-test-nagios</artifactId> + <name>Camel Quarkus :: Integration Tests :: Nagios</name> <description>Integration tests for Camel Quarkus Nagios extension</description> <dependencyManagement> @@ -63,6 +62,21 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-netty</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> <dependency> @@ -80,4 +94,49 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> diff --git a/extensions-jvm/nagios/integration-test/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java b/integration-tests/nagios/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java similarity index 58% rename from extensions-jvm/nagios/integration-test/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java rename to integration-tests/nagios/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java index eb51edf..ce96f07 100644 --- a/extensions-jvm/nagios/integration-test/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java +++ b/integration-tests/nagios/src/main/java/org/apache/camel/quarkus/component/nagios/it/NagiosResource.java @@ -16,36 +16,40 @@ */ package org.apache.camel.quarkus.component.nagios.it; +import java.util.HashMap; +import java.util.Map; + import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.nagios.NagiosConstants; import org.jboss.logging.Logger; @Path("/nagios") @ApplicationScoped public class NagiosResource { + public static final String NSCA_PORT_CFG_KEY = "quarkus.camel.nagios.test.nsca-port"; + public static final String NSCA_HOST_CFG_KEY = "quarkus.camel.nagios.test.nsca-host"; + private static final Logger LOG = Logger.getLogger(NagiosResource.class); - private static final String COMPONENT_NAGIOS = "nagios"; @Inject - CamelContext context; + ProducerTemplate template; - @Path("/load/component/nagios") + @Path("/send") @GET - @Produces(MediaType.TEXT_PLAIN) - public Response loadComponentNagios() throws Exception { - /* This is an autogenerated test */ - if (context.getComponent(COMPONENT_NAGIOS) != null) { - return Response.ok().build(); - } - LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_NAGIOS); - return Response.status(500, COMPONENT_NAGIOS + " could not be loaded from the Camel context").build(); + public void send() { + LOG.infof("Calling send()"); + + Map<String, Object> headers = new HashMap<>(); + headers.put(NagiosConstants.LEVEL, "CRITICAL"); + headers.put(NagiosConstants.HOST_NAME, "myHost"); + headers.put(NagiosConstants.SERVICE_NAME, "myService"); + String uri = String.format("nagios:{{%s}}:{{%s}}?password=secret", NSCA_HOST_CFG_KEY, NSCA_PORT_CFG_KEY); + template.sendBodyAndHeaders(uri, "Hello Nagios", headers); } } diff --git a/extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosIT.java similarity index 70% copy from extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java copy to integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosIT.java index 04cb033..1b0357d 100644 --- a/extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java +++ b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosIT.java @@ -16,19 +16,8 @@ */ package org.apache.camel.quarkus.component.nagios.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; - -@QuarkusTest -class NagiosTest { - - @Test - public void loadComponentNagios() { - /* A simple autogenerated test */ - RestAssured.get("/nagios/load/component/nagios") - .then() - .statusCode(200); - } +import io.quarkus.test.junit.NativeImageTest; +@NativeImageTest +class NagiosIT extends NagiosTest { } diff --git a/extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java similarity index 54% rename from extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java rename to integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java index 04cb033..2125820 100644 --- a/extensions-jvm/nagios/integration-test/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java +++ b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTest.java @@ -16,19 +16,32 @@ */ package org.apache.camel.quarkus.component.nagios.it; +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; +import org.apache.camel.quarkus.component.nagios.it.NagiosTestResource.MockNscaServerInitializerFactory; import org.junit.jupiter.api.Test; +@QuarkusTestResource(NagiosTestResource.class) @QuarkusTest -class NagiosTest { +public class NagiosTest { + + private static final String EXPECTED_NSCA_FRAME_DIGEST = "315d4b1aed2bb2db79d516f7c651b0d1"; + + private MockNscaServerInitializerFactory mockNscaServer; + + public MockNscaServerInitializerFactory getMockNscaServer() { + return mockNscaServer; + } + + public void setMockNscaServer(MockNscaServerInitializerFactory mockNscaServer) { + this.mockNscaServer = mockNscaServer; + } @Test - public void loadComponentNagios() { - /* A simple autogenerated test */ - RestAssured.get("/nagios/load/component/nagios") - .then() - .statusCode(200); + public void sendFixedNscaFrameReturnsExpectedDigest() { + RestAssured.get("/nagios/send").then().statusCode(204); + mockNscaServer.verifyFrameReceived(EXPECTED_NSCA_FRAME_DIGEST); } } diff --git a/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTestResource.java b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTestResource.java new file mode 100644 index 0000000..bf1d3c1 --- /dev/null +++ b/integration-tests/nagios/src/test/java/org/apache/camel/quarkus/component/nagios/it/NagiosTestResource.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.camel.quarkus.component.nagios.it; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.netty.NettyConsumer; +import org.apache.camel.component.netty.ServerInitializerFactory; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.quarkus.test.AvailablePortFinder; +import org.apache.commons.codec.digest.DigestUtils; +import org.awaitility.Awaitility; +import org.jboss.logging.Logger; + +import static org.apache.camel.quarkus.component.nagios.it.NagiosResource.NSCA_HOST_CFG_KEY; +import static org.apache.camel.quarkus.component.nagios.it.NagiosResource.NSCA_PORT_CFG_KEY; + +public class NagiosTestResource implements QuarkusTestResourceLifecycleManager { + + private static final Logger LOG = Logger.getLogger(NagiosTestResource.class); + private static final int INIT_VECTOR_PLUS_TIMESTAMP_SIZE_IN_BYTES = 128 + Integer.BYTES; + + private int nscaPort; + private CamelContext context; + + private MockNscaServerInitializerFactory mockNscaServer = new MockNscaServerInitializerFactory(); + + @Override + public Map<String, String> start() { + nscaPort = AvailablePortFinder.getNextAvailable(); + + try { + context = new DefaultCamelContext(); + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + context.getRegistry().bind("mockNscaServer", mockNscaServer); + fromF("netty:tcp://0.0.0.0:%s?serverInitializerFactory=#mockNscaServer", nscaPort) + .log("This log statement is here just because a route definition needs an output"); + } + }); + context.start(); + } catch (Exception e) { + LOG.error("An issue occured while starting the NagiosTestResource route", e); + } + Map<String, String> properties = new HashMap<String, String>(); + properties.put(NSCA_PORT_CFG_KEY, "" + nscaPort); + properties.put(NSCA_HOST_CFG_KEY, "localhost"); + return properties; + } + + @Override + public void stop() { + if (context != null) { + context.shutdown(); + } + } + + @Override + public void inject(Object testInstance) { + Class<?> c = testInstance.getClass(); + if (c == NagiosTest.class || c == NagiosIT.class) { + ((NagiosTest) testInstance).setMockNscaServer(mockNscaServer); + } + } + + public static class MockNscaServerInitializerFactory extends ServerInitializerFactory { + + private volatile String actualFrameDigest; + + protected void initChannel(Channel ch) { + + ch.pipeline().addFirst("mock-nsca-handler", new ByteToMessageDecoder() { + @Override + public void channelActive(ChannelHandlerContext ctx) { + // Send the init sequence required by the nsca protocol (this one is empty for test reproducibility) + final ByteBuf initVectorAndTimeStamp = ctx.alloc().buffer(INIT_VECTOR_PLUS_TIMESTAMP_SIZE_IN_BYTES); + initVectorAndTimeStamp.writeBytes(new byte[INIT_VECTOR_PLUS_TIMESTAMP_SIZE_IN_BYTES]); + ctx.writeAndFlush(initVectorAndTimeStamp); + } + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { + byte[] bytes = new byte[in.readableBytes()]; + in.readBytes(bytes); + actualFrameDigest = DigestUtils.md5Hex(bytes); + } + }); + } + + void verifyFrameReceived(String expectedFrameDigest) { + if (expectedFrameDigest == null) { + throw new IllegalArgumentException("argument expectedFrameDigest can't be null"); + } + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { + LOG.infof("ExpectedFrameDigest=%s and actualFrameDigest=%s", expectedFrameDigest, actualFrameDigest); + return expectedFrameDigest.equals(actualFrameDigest); + }); + } + + @Override + public ServerInitializerFactory createPipelineFactory(NettyConsumer consumer) { + return this; + } + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index cb9f6f0..4ead2df 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -127,6 +127,7 @@ <module>microprofile</module> <module>mongodb</module> <module>mustache</module> + <module>nagios</module> <module>nats</module> <module>netty</module> <module>nsq</module> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 0b8356d..5ad16aa 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -108,6 +108,7 @@ misc: - fop - jolt - mustache + - nagios - pdf - qute - shiro