Skip to content
This repository has been archived by the owner on Jan 23, 2020. It is now read-only.

Rebase: Add apiKey, hostname, blacklist, tagNode setters #64

Merged
merged 3 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ Note: If you do not see the version of `Datadog Plugin` that you are expecting,
## Configuration
To configure your newly installed Datadog Plugin, simply navigate to the `Manage Jenkins -> Configure System` page on your Jenkins installation. Once there, scroll down to find the `Datadog Plugin` section. Find your API Key from the [API Keys](https://app.datadoghq.com/account/settings#api) page on your Datadog account, and copy/paste it into the `API Key` textbox on the Jenkins configuration screen. You can test that your API Key works by pressing the `Test Key` button, on the Jenkins configuration screen, directly below the API Key textbox. Once your configuration changes are finished, simply save them, and you're good to go!

Alternatively, you have the option of configuring your Datadog plugin using a Groovy script like this one:

```groovy
import jenkins.model.*
import org.datadog.jenkins.plugins.datadog.DatadogBuildListener

def j = Jenkins.getInstance()
def d = j.getDescriptor("org.datadog.jenkins.plugins.datadog.DatadogBuildListener")
d.setHostname('https://your-jenkins.com:8080')
d.setTagNode(true)
d.setApiKey('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
d.setBlacklist('job1,job2')
d.save()
```

Configuring the plugin this way might be useful if you're running your Jenkins Master in a Docker container using the [Official Jenkins Docker Image](https://github.com/jenkinsci/docker) or any derivative that supports plugins.txt and Groovy init scripts.

### Logging
Logging is done by utilizing the java.util.Logger, which follows the [best logging practices for Jenkins](https://wiki.jenkins-ci.org/display/JENKINS/Logging). In order to obtain logs, follow the directions listed [here](https://wiki.jenkins-ci.org/display/JENKINS/Logging). When adding a Logger, all Datadog plugin functions start with `org.datadog.jenkins.plugins.datadog.` and the function name you're after should autopopulate. As of this writing, the only function available was `org.datadog.jenkins.plugins.datadog.DatadogBuildListener`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,17 @@ public String getDisplayName() {
public boolean configure(final StaplerRequest req, final JSONObject formData)
throws FormException {
// Grab apiKey and hostname
apiKey = Secret.fromString(fixEmptyAndTrim(formData.getString("apiKey")));
hostname = formData.getString("hostname");
this.setApiKey(formData.getString("apiKey"));
this.setHostname(formData.getString("hostname"));

// Grab blacklist, strip whitespace, remove duplicate commas, and make lowercase
blacklist = formData.getString("blacklist")
.replaceAll("\\s", "")
.replaceAll(",,", "")
.toLowerCase();
// Grab blacklist
this.setBlacklist(formData.getString("blacklist"));

// Grab tagNode and coerse to a boolean
if ( formData.getString("tagNode").equals("true") ) {
tagNode = true;
this.setTagNode(true);
} else {
tagNode = false;
this.setTagNode(false);
}

daemonHost = formData.getString("daemonHost");
Expand Down Expand Up @@ -580,10 +577,11 @@ public String getApiKey() {
/**
* Setter function for the {@link apiKey} global configuration.
*
* @param apiKey - A string representing an apiKey
* @param key = A string containing the plaintext representation of a
* DataDog API Key
*/
public void setApiKey(String apiKey) {
this.apiKey = Secret.fromString(apiKey);
public void setApiKey(final String key) {
this.apiKey = Secret.fromString(fixEmptyAndTrim(key));
}

/**
Expand All @@ -598,9 +596,9 @@ public String getHostname() {
/**
* Setter function for the {@link hostname} global configuration.
*
* @param hostname - A string representing the hostname
* @param hostname - A String containing the hostname of the Jenkins host.
*/
public void setHostname(String hostname) {
public void setHostname(final String hostname) {
this.hostname = hostname;
}

Expand All @@ -614,27 +612,45 @@ public String getBlacklist() {
return blacklist;
}

/**
* Setter function for the {@link blacklist} global configuration,
* accepting a comma-separated string of jobs that will be sanitized.
*
* @param jobs - a comma-separated list of jobs to blacklist from monitoring.
*/
public void setBlacklist(final String jobs) {
// strip whitespace, remove duplicate commas, and make lowercase
this.blacklist = jobs
.replaceAll("\\s", "")
.replaceAll(",,", "")
.toLowerCase();
}

/**
* Getter function for the optional tag {@link tagNode} global configuration.
*
* @return a Boolean containing optional tag value for the {@link tagNode} global configuration.
* @return a Boolean containing optional tag value for the {@link tagNode}
* global configuration.
*/
public Boolean getTagNode() {
return tagNode;
}

/**
* @return The host definition for the dogstats daemon
* Setter function for the optional tag {@link tagNode} global configuration.
*
* @param willTag - A Boolean expressing whether the {@link tagNode} tag will
* be included.
*/
public String getDaemonHost() {
return daemonHost;
public void setTagNode(final Boolean willTag) {
this.tagNode = willTag;
}

/**
* @return The target API URL
* @return The host definition for the dogstats daemon
*/
public String getTargetMetricURL() {
return targetMetricURL;
public String getDaemonHost() {
return daemonHost;
}

/**
Expand All @@ -644,6 +660,13 @@ public void setDaemonHost(String daemonHost) {
this.daemonHost = daemonHost;
}

/**
* @return The target API URL
*/
public String getTargetMetricURL() {
return targetMetricURL;
}

/**
* @param targetMetricURL - The target API URL
*/
Expand Down