Skip to content

Commit

Permalink
Plugin Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Nascimento Jr committed Feb 23, 2017
0 parents commit 6415227
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Logstash.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}
67 changes: 67 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 6415227

Please sign in to comment.