├── LogstashPlugin.groovy └── readme.md /LogstashPlugin.groovy: -------------------------------------------------------------------------------- 1 | import com.dtolabs.rundeck.plugins.logging.StreamingLogWriterPlugin; 2 | import com.fasterxml.jackson.databind.ObjectMapper; 3 | import com.dtolabs.rundeck.core.logging.LogEvent; 4 | import com.dtolabs.rundeck.core.logging.LogLevel; 5 | 6 | /** 7 | * Opens a TCP connection, and writes JSON event messages to the socket 8 | */ 9 | rundeckPlugin(StreamingLogWriterPlugin){ 10 | configuration{ 11 | host defaultValue:"localhost", required:true, description: "Hostname to connect to" 12 | port required:true, description: "Port to connect to", type: 'Integer' 13 | } 14 | /** 15 | * open the socket, prepare some metadata 16 | */ 17 | open { Map execution, Map config -> 18 | def socket = new Socket(config.host, config.port.toInteger()); 19 | def socketStream = socket.getOutputStream(); 20 | def e2 = [:] 21 | execution.each{ e2["execution.${it.key}"]=it.value } 22 | def json=new ObjectMapper() 23 | 24 | [socket:socket, count:0, executionid:execution.execid, write:{ 25 | socketStream<< json.writeValueAsString(e2 + it) + "\n" 26 | }] 27 | } 28 | 29 | /** 30 | * write the log event and metadata as json to the socket 31 | */ 32 | addEvent { Map context, LogEvent event-> 33 | 34 | context.count++ 35 | 36 | def emeta=[:] 37 | 38 | event.metadata?.each{ emeta["event.${it.key}"]=it.value } 39 | 40 | def data= emeta + [ 41 | line:context.count, 42 | datetime:event.datetime.time, 43 | loglevel:event.loglevel.toString(), 44 | message:event.message, 45 | eventType:event.eventType, 46 | ] 47 | 48 | context.write data 49 | } 50 | /** 51 | * close the socket 52 | */ 53 | close { 54 | context.write ending:true, totallines:context.count, message: 'Execution '+context.executionid+' finished.' 55 | context.socket.close(); 56 | } 57 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | This repository is no longer maintained and is only avaiable for historical example purposes. It will be deleted at some point in the future. 4 | 5 | # Rundeck Logstash Plugin 6 | 7 | This is a simple Rundeck streaming Log Writer plugin that will pipe all log output to a Logstash server by writing Json to a TCP port. *For Rundeck version 1.6.0 or later.* 8 | 9 | # Installation 10 | 11 | Copy the `LogstashPlugin.groovy` to your `$RDECK_BASE/libext/` directory for Rundeck. 12 | 13 | Enable the plugin in your `rundeck-config.properties` file: 14 | 15 | rundeck.execution.logs.streamingWriterPlugins=LogstashPlugin 16 | 17 | # Configure Rundeck 18 | 19 | The plugin supports these configuration properties: 20 | 21 | * `host` - hostname of the logstash server 22 | * `port` - TCP port to send JSON data to 23 | 24 | You can update the your framework/project.properties file to set these configuration values: 25 | 26 | in `framework.properties`: 27 | 28 | framework.plugin.StreamingLogWriter.LogstashPlugin.port=9700 29 | framework.plugin.StreamingLogWriter.LogstashPlugin.host=localhost 30 | 31 | or in `project.properties`: 32 | 33 | project.plugin.StreamingLogWriter.LogstashPlugin.port=9700 34 | project.plugin.StreamingLogWriter.LogstashPlugin.host=localhost 35 | 36 | # Configure Logstash 37 | 38 | Add a TCP input that uses Json format data. Here is an example `rundeck-logstash.conf`: 39 | 40 | input { 41 | 42 | tcp { 43 | debug => true 44 | format => "json" 45 | host => "localhost" 46 | message_format => "%{message}" 47 | mode => server 48 | port => 9700 49 | #ssl_cacert => ... # a valid filesystem path (optional) 50 | #ssl_cert => ... # a valid filesystem path (optional) 51 | #ssl_enable => ... # boolean (optional), default: false 52 | #ssl_key => ... # a valid filesystem path (optional) 53 | #ssl_key_passphrase => ... # password (optional), default: nil 54 | #ssl_verify => ... # boolean (optional), default: false 55 | tags => ["rundeck"] 56 | type => "rundeck" 57 | } 58 | 59 | } 60 | 61 | output { 62 | stdout { } 63 | 64 | elasticsearch { embedded => true } 65 | } 66 | 67 | 68 | # Start Logstash 69 | 70 | Use the config file when starting logstash. 71 | 72 | java -jar ../logstash-1.1.13-flatjar.jar agent -f rundeck-logstash.conf -- web --backend elasticsearch://localhost/ 73 | --------------------------------------------------------------------------------