1+ package com.plugin.${javaPluginClass.toLowerCase()};
2+
3+ import com.dtolabs.rundeck.core.logging.LogEventControl;
4+ import com.dtolabs.rundeck.core.logging.LogLevel;
5+ import com.dtolabs.rundeck.core.logging.PluginLoggingContext;
6+ import com.dtolabs.rundeck.core.plugins.Plugin;
7+ import com.dtolabs.rundeck.plugins.descriptions.PluginDescription;
8+ import com.dtolabs.rundeck.plugins.descriptions.PluginProperty;
9+ import com.dtolabs.rundeck.plugins.descriptions.SelectLabels;
10+ import com.dtolabs.rundeck.plugins.descriptions.SelectValues;
11+ import com.dtolabs.rundeck.plugins.logging.LogFilterPlugin;
12+ import java.util.HashMap;
13+ import java.util.Map;
14+
15+ @Plugin(service="LogFilter",name="${sanitizedPluginName}")
16+ @PluginDescription(title="${pluginName}", description="My plugin description")
17+ public class ${javaPluginClass} implements LogFilterPlugin{
18+
19+ @PluginProperty(name = "example header",title = "Example String",description = "Example description")
20+ private String header;
21+
22+ @PluginProperty(
23+ title = "Data type",
24+ description = "Select datatype output",
25+ required = false
26+ )
27+ @SelectValues(
28+ values = {"text/plain", "text/html"},
29+ freeSelect = true
30+ )
31+ @SelectLabels(values = {"TEXT", "HTML"})
32+ String datatype = null;
33+
34+
35+ private boolean started = false;
36+ private StringBuilder buffer;
37+
38+ @Override
39+ public void init(final PluginLoggingContext context) {
40+ started = true;
41+ buffer = new StringBuilder();
42+
43+ if(datatype.equals("text/html")){
44+ buffer.append("<table class='table table-striped'>");
45+ buffer.append("<tr><th>Log Output</th></tr>");
46+ }
47+ }
48+
49+ @Override
50+ public void handleEvent(final PluginLoggingContext context, final LogEventControl event) {
51+ if(event.getEventType().equals("log") && event.getLoglevel().equals(LogLevel.NORMAL) ){
52+
53+ if(datatype.equals("text/html")){
54+ buffer.append("<tr><td>").append("<b>[").append(header).append("]</b> ").append(event.getMessage()).append("</td></tr>");
55+ }else{
56+ buffer.append("[").append(header).append("] ").append(event.getMessage()).append("\\n");
57+ }
58+
59+ event.setLoglevel(LogLevel.DEBUG);
60+ }
61+ }
62+
63+ @Override
64+ public void complete(final PluginLoggingContext context) {
65+ if (started && datatype!=null && buffer.length()>0) {
66+
67+ if(datatype.equals("text/html")){
68+ buffer.append("</table>");
69+ }
70+
71+ Map<String,String> type = new HashMap<>();
72+ type.put("content-data-type", datatype);
73+
74+
75+ context.log(
76+ 2,
77+ buffer.toString(),
78+ type
79+ );
80+
81+ }
82+ }
83+ }
0 commit comments