-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rundeck/add-logfilter-template
logfilter example
- Loading branch information
Showing
13 changed files
with
292 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/resources/templates/java-plugin/logfilter/Plugin.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()}; | ||
|
||
import com.dtolabs.rundeck.core.logging.LogEventControl; | ||
import com.dtolabs.rundeck.core.logging.LogLevel; | ||
import com.dtolabs.rundeck.core.logging.PluginLoggingContext; | ||
import com.dtolabs.rundeck.core.plugins.Plugin; | ||
import com.dtolabs.rundeck.plugins.descriptions.PluginDescription; | ||
import com.dtolabs.rundeck.plugins.descriptions.PluginProperty; | ||
import com.dtolabs.rundeck.plugins.descriptions.SelectLabels; | ||
import com.dtolabs.rundeck.plugins.descriptions.SelectValues; | ||
import com.dtolabs.rundeck.plugins.logging.LogFilterPlugin; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Plugin(service="LogFilter",name="${sanitizedPluginName}") | ||
@PluginDescription(title="${pluginName}", description="My plugin description") | ||
public class ${javaPluginClass} implements LogFilterPlugin{ | ||
|
||
@PluginProperty(name = "example header",title = "Example String",description = "Example description") | ||
private String header; | ||
|
||
@PluginProperty( | ||
title = "Data type", | ||
description = "Select datatype output", | ||
required = false | ||
) | ||
@SelectValues( | ||
values = {"text/plain", "text/html"}, | ||
freeSelect = true | ||
) | ||
@SelectLabels(values = {"TEXT", "HTML"}) | ||
String datatype = null; | ||
|
||
|
||
private boolean started = false; | ||
private StringBuilder buffer; | ||
|
||
@Override | ||
public void init(final PluginLoggingContext context) { | ||
started = true; | ||
buffer = new StringBuilder(); | ||
|
||
if(datatype.equals("text/html")){ | ||
buffer.append("<table class='table table-striped'>"); | ||
buffer.append("<tr><th>Log Output</th></tr>"); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleEvent(final PluginLoggingContext context, final LogEventControl event) { | ||
if(event.getEventType().equals("log") && event.getLoglevel().equals(LogLevel.NORMAL) ){ | ||
|
||
if(datatype.equals("text/html")){ | ||
buffer.append("<tr><td>").append("<b>[").append(header).append("]</b> ").append(event.getMessage()).append("</td></tr>"); | ||
}else{ | ||
buffer.append("[").append(header).append("] ").append(event.getMessage()).append("\\n"); | ||
} | ||
|
||
event.setLoglevel(LogLevel.DEBUG); | ||
} | ||
} | ||
|
||
@Override | ||
public void complete(final PluginLoggingContext context) { | ||
if (started && datatype!=null && buffer.length()>0) { | ||
|
||
if(datatype.equals("text/html")){ | ||
buffer.append("</table>"); | ||
} | ||
|
||
Map<String,String> type = new HashMap<>(); | ||
type.put("content-data-type", datatype); | ||
|
||
|
||
context.log( | ||
2, | ||
buffer.toString(), | ||
type | ||
); | ||
|
||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/resources/templates/java-plugin/logfilter/PluginSpec.groovy.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()} | ||
|
||
import com.dtolabs.rundeck.core.dispatcher.ContextView | ||
import com.dtolabs.rundeck.core.execution.workflow.DataOutput | ||
import com.dtolabs.rundeck.core.logging.LogEventControl | ||
import com.dtolabs.rundeck.core.logging.LogLevel | ||
import com.dtolabs.rundeck.core.logging.PluginLoggingContext | ||
import spock.lang.Specification | ||
|
||
class ${javaPluginClass}Spec extends Specification { | ||
|
||
def "test preset type "() { | ||
given: | ||
def plugin = new ${javaPluginClass}() | ||
plugin.datatype = datatype | ||
plugin.header = "test" | ||
def sharedoutput = new DataOutput(ContextView.global()) | ||
def context = Mock(PluginLoggingContext) { | ||
getOutputContext() >> sharedoutput | ||
} | ||
def events = [] | ||
lines.each { line -> | ||
events << Mock(LogEventControl) { | ||
getMessage() >> line | ||
getEventType() >> 'log' | ||
getLoglevel() >> LogLevel.NORMAL | ||
} | ||
} | ||
when: | ||
plugin.init(context) | ||
events.each { | ||
plugin.handleEvent(context, it) | ||
} | ||
plugin.complete(context) | ||
|
||
then: | ||
1 * context.log(2, output, meta) | ||
|
||
where: | ||
datatype | lines | output | meta | ||
'text/plain' | ['1,2,3', '---', 'a,b,c'] | '[test] 1,2,3\\n[test] ---\\n[test] a,b,c\\n' | ['content-data-type': 'text/plain'] | ||
'text/html' | ['1,2,3', '---', 'a,b,c'] | "<table class='table table-striped'><tr><th>Log Output</th></tr><tr><td><b>[test]</b> 1,2,3</td></tr><tr><td><b>[test]</b> ---</td></tr><tr><td><b>[test]</b> a,b,c</td></tr></table>" | ['content-data-type': 'text/html'] | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/templates/java-plugin/logfilter/README.md.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# ${pluginName} Rundeck Plugin | ||
|
||
This is a log filter plugin. | ||
|
42 changes: 42 additions & 0 deletions
42
src/main/resources/templates/java-plugin/logfilter/build.gradle.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version = '0.1.0' | ||
defaultTasks 'clean','build' | ||
apply plugin: 'java' | ||
apply plugin: 'groovy' | ||
apply plugin: 'idea' | ||
sourceCompatibility = 1.8 | ||
ext.rundeckPluginVersion= '2.0' | ||
ext.rundeckVersion= '${rundeckVersion}' | ||
|
||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'org.rundeck:rundeck-core:3.0.1+' | ||
|
||
testCompile 'junit:junit:4.12' | ||
testCompile "org.codehaus.groovy:groovy-all:2.4.15" | ||
testCompile "org.spockframework:spock-core:1.0-groovy-2.4" | ||
} | ||
|
||
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}' | ||
jar { | ||
manifest { | ||
attributes 'Rundeck-Plugin-Classnames': pluginClassNames | ||
attributes 'Rundeck-Plugin-File-Version': version | ||
attributes 'Rundeck-Plugin-Name': '${pluginName}' | ||
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.' | ||
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x' | ||
attributes 'Rundeck-Plugin-Tags': 'java,notification' | ||
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true' | ||
} | ||
from("rundeck-verb-artifact.yaml") { | ||
into("") | ||
} | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '4.4.1' | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
src/main/resources/templates/java-plugin/logfilter/java-plugin.structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build.gradle.template->build.gradle | ||
README.md.template->README.md | ||
icon.png->src/main/resources/resources/icon.png | ||
Plugin.java.template->src/main/java/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}.java | ||
PluginSpec.groovy.template->src/test/groovy/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}Spec.groovy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters