-
-
Notifications
You must be signed in to change notification settings - Fork 107
Ability to send custom data to logstash #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| import static java.util.logging.Level.WARNING; | ||
| import java.io.IOException; | ||
| import java.lang.invoke.MethodHandles; | ||
| import net.sf.json.JSONException; | ||
| import net.sf.json.JSONObject; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
|
|
@@ -120,6 +121,7 @@ public TestData(Action action) { | |
| protected String displayName; | ||
| protected String fullDisplayName; | ||
| protected String description; | ||
| protected JSONObject custom; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| protected String url; | ||
| protected String buildHost; | ||
| protected String buildLabel; | ||
|
|
@@ -135,7 +137,7 @@ public TestData(Action action) { | |
| protected TestData testResults = null; | ||
|
|
||
| // Freestyle project build | ||
| public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener listener) { | ||
| public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener listener, String customData) { | ||
| initData(build, currentTime); | ||
|
|
||
| Node node = build.getBuiltOn(); | ||
|
|
@@ -171,6 +173,14 @@ public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener liste | |
| } | ||
| } | ||
| } | ||
|
|
||
| // Parse JSON string. If fails add error message and continue | ||
| try{ | ||
| custom = JSONObject.fromObject(customData); | ||
| }catch (JSONException e){ | ||
| custom = JSONObject.fromObject("{\"error\":\"custom data json parse failed\"}"); | ||
| } | ||
|
|
||
| try { | ||
| buildVariables.putAll(build.getEnvironment(listener)); | ||
| } catch (Exception e) { | ||
|
|
@@ -183,7 +193,7 @@ public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener liste | |
| } | ||
|
|
||
| // Pipeline project build | ||
| public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener) { | ||
| public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener, String customData) { | ||
| initData(build, currentTime); | ||
|
|
||
| Executor executor = build.getExecutor(); | ||
|
|
@@ -198,6 +208,13 @@ public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener) { | |
| rootProjectDisplayName = displayName; | ||
| rootBuildNum = buildNum; | ||
|
|
||
| // Parse JSON string. If fails add error message and continue | ||
| try{ | ||
| custom = JSONObject.fromObject(customData); | ||
| }catch (JSONException e){ | ||
| custom = JSONObject.fromObject("{\"error\":\"custom data json parse failed\"}"); | ||
| } | ||
|
|
||
| try { | ||
| // TODO: sensitive variables are not filtered, c.f. https://stackoverflow.com/questions/30916085 | ||
| buildVariables = build.getEnvironment(listener); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <div> | ||
| <p>Custom json string to send to Logstash.<br/> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please change the code to parse and validate the json on input |
||
| Expected json string. If parse fail, error message is added in custom field</p> | ||
| </div> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will make
customDataa mandatory argumentthis is a no-no as it will break existing usage
please use
@DataBoundSetterinstead