diff --git a/basic/splunk/README.md b/basic/splunk/README.md new file mode 100644 index 00000000..6d6b6bcf --- /dev/null +++ b/basic/splunk/README.md @@ -0,0 +1,51 @@ +Splunk Sample +============== + +This example demonstrates the use of Splunk **Outbound** and **Inbound** Adapter. +As configuration example is used a xml file + +## Running the sample + +Start Splunk server and change references in application.yml file. + +type from the root project + + $ gradlew :splunk:run + +#### Using an IDE such as eclipse + +Type from /basic/splunk + + mvn eclipse:eclipse + +import the project and run it **org.springframework.integration.samples.splunk.Application** like any other main + +### Output + +The application sends 10 "custom" SplunkEvent to a main index and the read all event with yesterday as earliest-time +the received message are printed on sysout with stream adapter + +Program output: + +Producer: + + [2015-11-22 21:16:04:546+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:23" _serial="0" _raw="2015-11-22 18:38:08:923+0100 ean="164" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" source="tinyMain" _indextime="1448213888" _subsecond=".923" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T18:38:08.923+01:00"] + [2015-11-22 21:16:04:546+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:18" _serial="1" _raw="2015-11-22 18:38:08:822+0100 ean="62" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" source="tinyMain" _indextime="1448213888" _subsecond=".822" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T18:38:08.822+01:00"] + [2015-11-22 21:16:04:546+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:13" _serial="2" _raw="2015-11-22 16:26:50:770+0100 ean="194" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" source="tinyMain" _indextime="1448206010" _subsecond=".770" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T16:26:50.770+01:00"] + [2015-11-22 21:16:04:546+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:8" _serial="3" _raw="2015-11-22 16:26:50:670+0100 ean="42" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" source="tinyMain" _indextime="1448206010" _subsecond=".670" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T16:26:50.670+01:00"] +] + +In this snippet we see toString() of message that send from program to Splunk, you can see the custom fields included email, ean code ecc.ecc + +Consumer: + + [2015-11-22 21:32:33:467+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:158" _serial="0" _raw="2015-11-22 21:25:50:956+0100 ean="216" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" _kv="1" source="tinyMain" _indextime="1448223950" _subsecond=".956" ean="216" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T21:25:50.956+01:00"] + [2015-11-22 21:32:33:467+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:153" _serial="1" _raw="2015-11-22 21:25:50:936+0100 ean="504" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" _kv="1" source="tinyMain" _indextime="1448223950" _subsecond=".936" ean="504" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T21:25:50.936+01:00"] + [2015-11-22 21:32:33:467+0100 _bkt="main~2~783FBE3F-8AA4-4DE3-BC2C-CA406157661C" _cd="2:148" _serial="2" _raw="2015-11-22 21:25:50:916+0100 ean="357" severity="ALERT" email="mail@gmail.com" order_number="21501001010101"" splunk_server="fbalicchia-desktop" index="main" _kv="1" source="tinyMain" _indextime="1448223950" _subsecond=".916" ean="357" linecount="1" _si="fbalicchia-desktop,main" host="127.0.0.1" _sourcetype="customMessage" sourcetype="customMessage" _time="2015-11-22T21:25:50.916+01:00"] + +The layout of the message is the same but we found entry with ean code greater than '135'. Splunk support out of the box a good query languages where more info can be found at splunk project documentation + + +> Please note that Before use this example, please, verify that **jdk.tls.disabledAlgorithms=SSLv3** entry in **lib/security/java.security** is commenting out + + diff --git a/basic/splunk/pom.xml b/basic/splunk/pom.xml new file mode 100644 index 00000000..f75dd36f --- /dev/null +++ b/basic/splunk/pom.xml @@ -0,0 +1,135 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 1.3.0.RELEASE + + org.springframework.integration.samples + splunk + 4.1.0.BUILD-SNAPSHOT + Apache splunk Sample + Apache splunk Sample + http://projects.spring.io/spring-integration + + SpringIO + https://spring.io + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + garyrussell + Gary Russell + grussell@pivotal.io + + project lead + + + + markfisher + Mark Fisher + mfisher@pivotal.io + + project founder and lead emeritus + + + + ghillert + Gunnar Hillert + ghillert@pivotal.io + + + abilan + Artem Bilan + abilan@pivotal.io + + + + scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git + scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git + https://github.com/spring-projects/spring-integration-samples + + + + org.springframework.integration + spring-integration-core + 4.2.1.RELEASE + compile + + + junit + junit + 4.11 + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-integration + compile + + + com.splunk + splunk + 1.5.0.0 + + + org.springframework.integration + spring-integration-splunk + 1.1.0.RELEASE + + + org.slf4j + slf4j-log4j12 + + + compile + + + org.springframework + spring-test + 4.2.0.RELEASE + test + + + + + repo.spring.io.milestone + Spring Framework Maven Milestone Repository + https://repo.spring.io/libs-milestone + + + repo.spring.io.snapshot + Spring Framework Maven Snapshot Repository + https://repo.spring.io/libs-snapshot + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/Application.java b/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/Application.java new file mode 100644 index 00000000..1a9808f0 --- /dev/null +++ b/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/Application.java @@ -0,0 +1,87 @@ +/* + * Copyright 2015 the original author or authors. + * + * 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. + */ +package org.springframework.integration.samples.splunk; + +import java.util.concurrent.ThreadLocalRandom; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportResource; +import org.springframework.integration.samples.splunk.event.OrderEvent; +import org.springframework.integration.splunk.event.SplunkEvent; +import org.springframework.integration.splunk.support.SplunkServer; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.MessageChannel; + +/** + * @author Filippo Balicchia + * @since 4.2 + */ +@SpringBootApplication +@ImportResource("si-splunk-example-context.xml") +public class Application { + + @Value("${splunk.host}") + private String host; + @Value("${splunk.port}") + private String port; + @Value("${splunk.username}") + private String username; + @Value("${splunk.password}") + private String password; + @Value("${splunk.owner}") + private String owner; + public static void main(String[] args) throws Exception { + + ConfigurableApplicationContext context = SpringApplication.run(Application.class, args); + MessageChannel channelRestOutput = context.getBean("toSplunk", MessageChannel.class); + sendWithRest(channelRestOutput); + System.out.println("Consumer"); + + } + + private static void sendWithRest(MessageChannel channel) { + + for (int i = 0; i < 10; i++) { + channel.send(MessageBuilder.withPayload(createEvent()).build()); + } + + } + + private static SplunkEvent createEvent(){ + int nextInt = ThreadLocalRandom.current().nextInt(1, 1000); + OrderEvent sd = new OrderEvent(); + sd.setEan(String.valueOf (nextInt)); + sd.setEmailuser("mail@gmail.com"); + sd.setOrderNumber("21501001010101"); + return sd; + } + + @Bean + public SplunkServer splunkServerRef() { + SplunkServer splunkServer = new SplunkServer(); + splunkServer.setPort(Integer.valueOf(port)); + splunkServer.setHost(host); + splunkServer.setUsername(username); + splunkServer.setOwner(owner); + splunkServer.setPassword(password); + return splunkServer; + } + +} diff --git a/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/event/OrderEvent.java b/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/event/OrderEvent.java new file mode 100644 index 00000000..e12a2ee8 --- /dev/null +++ b/basic/splunk/src/main/java/org/springframework/integration/samples/splunk/event/OrderEvent.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 the original author or authors. + * + * 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. + */ +package org.springframework.integration.samples.splunk.event; + +import org.springframework.integration.splunk.event.SplunkEvent; + +/** + * @author Filippo Balicchia + * @since 4.2 + */ +public class OrderEvent extends SplunkEvent { + + private static final long serialVersionUID = 4203808769092252241L; + + public static String ORDER_NUMBER = "order_number"; + + public static String EAN_ITEM = "ean"; + + public static String EMAIL_USER = "email"; + + public OrderEvent() { + super(); + } + + public void setOrderNumber(String orderNumber) { + addPair(ORDER_NUMBER, orderNumber); + } + + public void setEan(String eanNumber) { + addPair(EAN_ITEM, eanNumber); + } + + public void setEmailuser(String email) { + addPair(EMAIL_USER, email); + } + +} diff --git a/basic/splunk/src/main/resources/application.yml b/basic/splunk/src/main/resources/application.yml new file mode 100644 index 00000000..60185069 --- /dev/null +++ b/basic/splunk/src/main/resources/application.yml @@ -0,0 +1,6 @@ +splunk: + host: localhost + port: 8089 + username: admin + password: admin + owner: admin diff --git a/basic/splunk/src/main/resources/banner.txt b/basic/splunk/src/main/resources/banner.txt new file mode 100644 index 00000000..957427d9 --- /dev/null +++ b/basic/splunk/src/main/resources/banner.txt @@ -0,0 +1,15 @@ +${AnsiColor.GREEN} _____ _ _____ _ _ _ +${AnsiColor.GREEN} / ____| (_) |_ _| | | | | (_) +${AnsiColor.GREEN} | (___ _ __ _ __ _ _ __ __ _ | | _ __ | |_ ___ __ _ _ __ __ _| |_ _ ___ _ __ +${AnsiColor.GREEN} \___ \| '_ \| '__| | '_ \ / _` | | | | '_ \| __/ _ \/ _` | '__/ _` | __| |/ _ \| '_ \ +${AnsiColor.GREEN} ____) | |_) | | | | | | | (_| | _| |_| | | | || __/ (_| | | | (_| | |_| | (_) | | | | +${AnsiColor.GREEN} |_____/| .__/|_| |_|_| |_|\__, | |_____|_| |_|\__\___|\__, |_| \__,_|\__|_|\___/|_| |_| +${AnsiColor.GREEN} | | __/ | __/ | ${AnsiColor.BRIGHT_BLUE} ____________ +${AnsiColor.GREEN} _____|_| _ |___/ _____ |___/ _ ${AnsiColor.BRIGHT_BLUE} \ \ \ \ \ \ \ +${AnsiColor.GREEN} / ____| | | | | / ____| | | ${AnsiColor.BRIGHT_BLUE} \ \ \ \ \ \ \ +${AnsiColor.GREEN} | (___ _ __ | |_ _ _ __ | | __ | (___ __ _ _ __ ___ _ __ | | ___ ${AnsiColor.BRIGHT_BLUE} \ \ \ \ \ \ \ +${AnsiColor.GREEN} \___ \| '_ \| | | | | '_ \| |/ / \___ \ / _` | '_ ` _ \| '_ \| |/ _ \${AnsiColor.BRIGHT_BLUE} / / / / / / / +${AnsiColor.GREEN} ____) | |_) | | |_| | | | | < ____) | (_| | | | | | | |_) | | __/${AnsiColor.BRIGHT_BLUE} / / / / / / / +${AnsiColor.GREEN} |_____/| .__/|_|\__,_|_| |_|_|\_\ |_____/ \__,_|_| |_| |_| .__/|_|\___|${AnsiColor.BRIGHT_BLUE} / / / / / / / +${AnsiColor.GREEN} ======| |===============================================| |=========== +${AnsiColor.GREEN} |_| |_|${AnsiColor.DEFAULT} diff --git a/basic/splunk/src/main/resources/logback.xml b/basic/splunk/src/main/resources/logback.xml new file mode 100644 index 00000000..025b7d4c --- /dev/null +++ b/basic/splunk/src/main/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + diff --git a/basic/splunk/src/main/resources/si-splunk-example-context.xml b/basic/splunk/src/main/resources/si-splunk-example-context.xml new file mode 100644 index 00000000..084d8288 --- /dev/null +++ b/basic/splunk/src/main/resources/si-splunk-example-context.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + diff --git a/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/ApplicationTests.java b/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/ApplicationTests.java new file mode 100644 index 00000000..d273666b --- /dev/null +++ b/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/ApplicationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 the original author or authors. + * + * 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. + */ + +package org.springframework.integration.samples.splunk; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Filippo Balicchia + * @since 4.2 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +public class ApplicationTests { + + @ClassRule + public static SplunkWatcher splunkWatcher = new SplunkWatcher(); + + @Test + public void contextLoads() { + } + +} diff --git a/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/SplunkWatcher.java b/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/SplunkWatcher.java new file mode 100644 index 00000000..73edecdb --- /dev/null +++ b/basic/splunk/src/test/java/org/springframework/integration/samples/splunk/SplunkWatcher.java @@ -0,0 +1,68 @@ +/* + * Copyright 2015 the original author or authors. + * + * 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. + */ + +package org.springframework.integration.samples.splunk; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assume; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.springframework.integration.splunk.support.SplunkServer; +import org.springframework.integration.splunk.support.SplunkServiceFactory; + +import com.splunk.Service; + +/** + * @author Filippo Balicchia + * @since 4.2 + */ +public class SplunkWatcher extends TestWatcher { + + private static final Log logger = LogFactory.getLog(SplunkWatcher.class); + + private final int port; + + public SplunkWatcher() { + this(Service.DEFAULT_PORT); + } + + public SplunkWatcher(int port) { + this.port = port; + } + + @Override + public Statement apply(Statement base, Description description) { + try { + + SplunkServer splunkServer = new SplunkServer(); + splunkServer.setPassword("admin"); + splunkServer.setUsername("admin"); + SplunkServiceFactory splunkServiceFactory = new SplunkServiceFactory(splunkServer); + splunkServiceFactory.getService().open(this.port); + System.setProperty("splunk.port", "" + this.port); + } + catch (Exception e) { + logger.warn( + "Not executing tests because basic connectivity test failed"); + Assume.assumeNoException(e); + } + + return super.apply(base, description); + } + +} diff --git a/build.gradle b/build.gradle index aae13955..9a07d9e7 100644 --- a/build.gradle +++ b/build.gradle @@ -195,6 +195,7 @@ subprojects { subproject -> springIntegrationVersion = '4.2.2.RELEASE' springIntegrationDslVersion = '1.1.1.RELEASE' springIntegrationKafkaVersion = '1.3.0.RELEASE' + springIntegrationSplunkVersion = '1.1.0.RELEASE' springVersion = '4.2.3.RELEASE' springSecurityVersion = '4.0.2.RELEASE' springWebFlowVersion = '2.3.3.RELEASE' @@ -564,6 +565,28 @@ project('http') { } +project('splunk') { + description = 'Splunk Sample' + + apply plugin: 'spring-boot' + + dependencies { + compile 'org.springframework.boot:spring-boot-starter-integration' + compile "org.springframework.integration:spring-integration-core:$springIntegrationVersion" + compile "org.springframework.integration:spring-integration-splunk:$springIntegrationSplunkVersion" + testCompile 'org.springframework.boot:spring-boot-starter-test' + } + + springBoot { + mainClass = 'org.springframework.integration.samples.splunk.Application' + } + + task run(type: JavaExec) { + main 'org.springframework.integration.samples.splunk.Application' + classpath = sourceSets.main.runtimeClasspath + } +} + project('kafka') { description = 'Apache Kafka Sample'