You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/01/18 07:10:51 UTC
svn commit: r900283 - in /camel/trunk/components/camel-nagios: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/component/
src/main/java/org/apache/camel/compon...
Author: davsclaus
Date: Mon Jan 18 06:10:50 2010
New Revision: 900283
URL: http://svn.apache.org/viewvc?rev=900283&view=rev
Log:
CAMEL-2347: Added initial camel-nagios with an event notifier. Work in progress.
Added:
camel/trunk/components/camel-nagios/
camel/trunk/components/camel-nagios/pom.xml (with props)
camel/trunk/components/camel-nagios/src/
camel/trunk/components/camel-nagios/src/main/
camel/trunk/components/camel-nagios/src/main/java/
camel/trunk/components/camel-nagios/src/main/java/org/
camel/trunk/components/camel-nagios/src/main/java/org/apache/
camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/
camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/
camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java (with props)
camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java (with props)
camel/trunk/components/camel-nagios/src/test/
camel/trunk/components/camel-nagios/src/test/java/
camel/trunk/components/camel-nagios/src/test/java/org/
camel/trunk/components/camel-nagios/src/test/java/org/apache/
camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/
camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/
camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/
camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java (with props)
camel/trunk/components/camel-nagios/src/test/resources/
camel/trunk/components/camel-nagios/src/test/resources/log4j.properties (with props)
Added: camel/trunk/components/camel-nagios/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-nagios/pom.xml?rev=900283&view=auto
==============================================================================
--- camel/trunk/components/camel-nagios/pom.xml (added)
+++ camel/trunk/components/camel-nagios/pom.xml Mon Jan 18 06:10:50 2010
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-nagios</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Nagios</name>
+ <description>Camel Nagios support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.nagios.*
+ </camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.googlecode</groupId>
+ <artifactId>jsendnsca-core</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.googlecode</groupId>
+ <artifactId>jsendnsca-test</artifactId>
+ <scope>test</scope>
+ <version>1.3.1</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: camel/trunk/components/camel-nagios/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-nagios/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-nagios/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java?rev=900283&view=auto
==============================================================================
--- camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java (added)
+++ camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java Mon Jan 18 06:10:50 2010
@@ -0,0 +1,104 @@
+/**
+ * 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.component.nagios;
+
+import com.googlecode.jsendnsca.core.NagiosSettings;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * @version $Revision$
+ */
+public class NagiosConfiguration {
+
+ private NagiosSettings nagiosSettings;
+ private String host;
+ private int port;
+ private int connectionTimeout = 5000;
+ private int timeout = 5000;
+ private String password;
+
+ public synchronized NagiosSettings getNagiosSettings() {
+ if (nagiosSettings == null) {
+
+ // validate parameters
+ ObjectHelper.notEmpty(host, "host", this);
+ if (port <= 0) {
+ throw new IllegalArgumentException("Port must be a positive number on " + this);
+ }
+
+ // create settings
+ nagiosSettings = new NagiosSettings();
+ nagiosSettings.setConnectTimeout(getConnectionTimeout());
+ nagiosSettings.setTimeout(getTimeout());
+ nagiosSettings.setNagiosHost(getHost());
+ nagiosSettings.setPort(getPort());
+ nagiosSettings.setPassword(getPassword());
+ }
+
+ return nagiosSettings;
+ }
+
+ public void setNagiosSettings(NagiosSettings nagiosSettings) {
+ this.nagiosSettings = nagiosSettings;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public int getConnectionTimeout() {
+ return connectionTimeout;
+ }
+
+ public void setConnectionTimeout(int connectionTimeout) {
+ this.connectionTimeout = connectionTimeout;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public String toString() {
+ return "NagiosConfiguration[host=" + host + ":" + port + ", connectionTimeout=" + connectionTimeout + ", timeout=" + timeout;
+ }
+
+}
Propchange: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java?rev=900283&view=auto
==============================================================================
--- camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java (added)
+++ camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java Mon Jan 18 06:10:50 2010
@@ -0,0 +1,94 @@
+/**
+ * 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.component.nagios;
+
+import java.util.EventObject;
+
+import com.googlecode.jsendnsca.core.Level;
+import com.googlecode.jsendnsca.core.MessagePayload;
+import com.googlecode.jsendnsca.core.NagiosPassiveCheckSender;
+import com.googlecode.jsendnsca.core.NagiosSettings;
+import org.apache.camel.management.EventNotifierSupport;
+
+/**
+ * An {@link org.apache.camel.spi.EventNotifier} which sends alters to Nagios.
+ *
+ * @version $Revision$
+ */
+public class NagiosEventNotifier extends EventNotifierSupport {
+
+ private NagiosSettings nagiosSettings;
+ private NagiosConfiguration configuration;
+ private NagiosPassiveCheckSender sender;
+
+ public void notify(EventObject eventObject) throws Exception {
+ // create message payload to send
+ String message = eventObject.toString();
+ MessagePayload payload = new MessagePayload("localhost", Level.CRITICAL.ordinal(), "Camel", message);
+
+ if (log.isInfoEnabled()) {
+ log.info("Sending notification to Nagios: " + payload.getMessage());
+ }
+ sender.send(payload);
+ if (log.isTraceEnabled()) {
+ log.trace("Sending notification done");
+ }
+ }
+
+ // TODO: level should be computed based on event message
+ // TODO: host and service name should be configurable
+
+
+ public boolean isEnabled(EventObject eventObject) {
+ return true;
+ }
+
+ public NagiosConfiguration getConfiguration() {
+ if (configuration == null) {
+ configuration = new NagiosConfiguration();
+ }
+ return configuration;
+ }
+
+ public void setConfiguration(NagiosConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public NagiosSettings getNagiosSettings() {
+ return nagiosSettings;
+ }
+
+ public void setNagiosSettings(NagiosSettings nagiosSettings) {
+ this.nagiosSettings = nagiosSettings;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (nagiosSettings == null) {
+ nagiosSettings = configuration.getNagiosSettings();
+ }
+ sender = new NagiosPassiveCheckSender(nagiosSettings);
+
+ log.info("Using " + configuration);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ sender = null;
+ }
+
+}
Propchange: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-nagios/src/main/java/org/apache/camel/component/nagios/NagiosEventNotifier.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java?rev=900283&view=auto
==============================================================================
--- camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java (added)
+++ camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java Mon Jan 18 06:10:50 2010
@@ -0,0 +1,104 @@
+/**
+ * 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.component.nagios;
+
+import java.util.List;
+
+import com.googlecode.jsendnsca.core.MessagePayload;
+import com.googlecode.jsendnsca.core.mocks.NagiosNscaStub;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class NagiosEventNotifierTest extends CamelTestSupport {
+
+ private NagiosNscaStub nagios;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ nagios = new NagiosNscaStub(5667, "password");
+ nagios.start();
+
+ super.setUp();
+ }
+
+ @After
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ nagios.stop();
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ NagiosEventNotifier notifier = new NagiosEventNotifier();
+ notifier.getConfiguration().setHost("localhost");
+ notifier.getConfiguration().setPort(5667);
+ notifier.getConfiguration().setPassword("password");
+
+ CamelContext context = super.createCamelContext();
+ context.getManagementStrategy().addEventNotifier(notifier);
+ return context;
+ }
+
+ @Test
+ public void testNagiosEventNotifierOk() throws Exception {
+ getMockEndpoint("mock:ok").expectedMessageCount(1);
+
+ template.sendBody("direct:ok", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ context.stop();
+
+ List<MessagePayload> events = nagios.getMessagePayloadList();
+ assertEquals(10, events.size());
+ }
+
+ @Test
+ public void testNagiosEventNotifierError() throws Exception {
+ try {
+ template.sendBody("direct:fail", "Bye World");
+ } catch (Exception e) {
+ // ignore
+ }
+
+ context.stop();
+
+ List<MessagePayload> events = nagios.getMessagePayloadList();
+ assertEquals(10, events.size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:ok").to("mock:ok");
+
+ from("direct:fail").throwException(new IllegalArgumentException("Damn"));
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-nagios/src/test/java/org/apache/camel/component/nagios/NagiosEventNotifierTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-nagios/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-nagios/src/test/resources/log4j.properties?rev=900283&view=auto
==============================================================================
--- camel/trunk/components/camel-nagios/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-nagios/src/test/resources/log4j.properties Mon Jan 18 06:10:50 2010
@@ -0,0 +1,37 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+log4j.logger.org.apache.camel.component.snmp=DEBUG
+log4j.logger.org.snmp4j=DEBUG
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-nagios-test.log
+log4j.appender.file.append=true
Propchange: camel/trunk/components/camel-nagios/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-nagios/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-nagios/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain