From 6415227cbcea64acf42981a86c34aba59d38b376 Mon Sep 17 00:00:00 2001 From: Vitor Nascimento Jr Date: Thu, 23 Feb 2017 11:20:03 -0300 Subject: [PATCH] Plugin Initial --- Logstash.groovy | 49 ++++++++++++++++++++++++++++++++++++ readme.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 Logstash.groovy create mode 100644 readme.md diff --git a/Logstash.groovy b/Logstash.groovy new file mode 100644 index 0000000..3120c7f --- /dev/null +++ b/Logstash.groovy @@ -0,0 +1,49 @@ +import com.dtolabs.rundeck.plugins.notification.NotificationPlugin +import com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants +import com.dtolabs.rundeck.core.plugins.configuration.ValidationException +import com.fasterxml.jackson.databind.ObjectMapper; +import groovy.json.JsonOutput + +/** + * Send Log. + * @param execution the execution data map + * @param config the plugin configuration data map + */ +def sendNotification(Map execution, Map config) { + + // Socket + def socket = new Socket(config.host, config.port.toInteger()); + def socketStream = socket.getOutputStream(); + + // Execution Information + def e2 = [:] + execution.each{ e2["${it.key}"] = it.value } + + // Stream + def json = new ObjectMapper() + socketStream << json.writeValueAsString(e2 + data) + "\n" +} + +rundeckPlugin(NotificationPlugin) { + title = 'Logstash Notification' + description = 'Send Execution Results to LogStash' + configuration { + host required: true, description: "Hostname to connect to Logstash", scope: 'Framework' + port required: true, description: "Port to connect to Logstash", type: 'Integer', scope: 'Framework' + } + + onstart { Map executionData, Map configuration -> + sendNotification(executionData, configuration) + true + } + + onfailure { Map executionData, Map configuration -> + sendNotification(executionData, configuration) + true + } + + onsuccess { Map executionData, Map configuration -> + sendNotification(executionData, configuration) + true + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0ac6273 --- /dev/null +++ b/readme.md @@ -0,0 +1,67 @@ +Info: Script inspired from https://github.com/rundeck-plugins/rundeck-logstash-plugin. + +# Rundeck Logstash Notification Plugin + +This is a simple Rundeck Notifiction plugin that will pipe all executions logs to a Logstash server by writing Json to a TCP port. *For Rundeck version 2.6.x or later.* + +# Installation + +Copy the `Logstash.groovy` to your `$RDECK_BASE/libext/` directory for Rundeck. + +# Configure Rundeck + +The plugin supports these configuration properties: + +* `host` - hostname of the logstash server +* `port` - TCP port to send JSON data to + +You can update the your framework.properties file to set these configuration values: + +in `framework.properties`: + + framework.plugin.Notification.Logstash.port=5000 + framework.plugin.Notification.Logstash.host=localhost + +# Configure Logstash + +Add a TCP input that uses Json format data. Here is an example `rundeck-logstash.conf`: + + output { + stdout { } + elasticsearch { + embedded => true + } + } + + input { + tcp { + port => 5000 + } + } + + filter{ + mutate { + replace => { + "type" => "rundeck" + } + } + json { + source => "message" + target => "rundeck" + } + } + + ## Or add your filters / logstash plugins configuration here + + output { + elasticsearch { + hosts => "elasticsearch:9200" + } + } + + +# Start Logstash + +Use the config file when starting logstash. + + https://hub.docker.com/_/logstash/