This repository has been archived by the owner on Dec 19, 2020. It is now read-only.
-
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.
Initial release of this JIRA plugin for Graylog
- Loading branch information
0 parents
commit 3c3b6c2
Showing
14 changed files
with
890 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
target/ | ||
.idea/ | ||
*.iml | ||
dependency-reduced-pom.xml | ||
*.iws | ||
*.ipr |
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,5 @@ | ||
sudo: false | ||
language: java | ||
jdk: | ||
- oraclejdk7 | ||
- oraclejdk8 |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Thiago Jackiw | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,33 @@ | ||
JIRA Plugin for Graylog | ||
========================== | ||
|
||
[![Build Status](https://travis-ci.org/tjackiw/graylog-plugin-jira.svg)](https://travis-ci.org/tjackiw/graylog-plugin-jira) | ||
|
||
An alarm callback plugin that integrates [JIRA](https://www.atlassian.com/software/jira/) into [Graylog](https://www.graylog.org/). | ||
|
||
**Required Graylog version:** 1.0 and later | ||
|
||
## Installation | ||
|
||
[Download the plugin](https://github.com/tjackiw/graylog-plugin-jira/releases) | ||
and place the `.jar` file in your Graylog plugin directory. The plugin directory | ||
is the `plugins/` folder relative from your `graylog-server` directory by default | ||
and can be configured in your `graylog.conf` file. | ||
|
||
Restart `graylog-server` and you are done. | ||
|
||
## Usage | ||
|
||
Create a "JIRA Alarm Callback" on the "Manage alerts" page of your stream. | ||
Enter the requested configuration and save. | ||
Make sure you also configured alert conditions for the stream so that the alerts are actually triggered. | ||
|
||
## Build | ||
|
||
This project is using Maven and requires Java 7 or higher. | ||
|
||
You can build a plugin (JAR) with `mvn package`. | ||
|
||
## Copyright | ||
|
||
Copyright (c) 2016 Thiago Jackiw. See LICENSE for further details. |
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,86 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.graylog.plugins</groupId> | ||
<artifactId>graylog-plugin-jira</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>graylog-plugin-jira</name> | ||
<description>JIRA Alarm Callback Plugin for Graylog</description> | ||
<url>https://github.com/tjackiw/graylog-plugin-jira</url> | ||
|
||
<scm> | ||
<connection>scm:git:git@github.com:tjackiw/graylog-plugin-jira.git</connection> | ||
<developerConnection>scm:git:git@github.com:tjackiw/graylog-plugin-jira.git</developerConnection> | ||
<url>https://github.com/tjackiw/graylog-plugin-jira</url> | ||
<tag>v1.0.0</tag> | ||
</scm> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
<graylog2.plugin-dir>/usr/share/graylog-server/plugin</graylog2.plugin-dir> | ||
<graylog2.version>1.0.0</graylog2.version> | ||
</properties> | ||
|
||
<licenses> | ||
<license> | ||
<name>The MIT License (MIT)</name> | ||
<url>http://opensource.org/licenses/MIT</url> | ||
</license> | ||
</licenses> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.graylog2</groupId> | ||
<artifactId>graylog2-plugin</artifactId> | ||
<version>${graylog2.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.json-simple</groupId> | ||
<artifactId>json-simple</artifactId> | ||
<version>1.1.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<minimizeJar>false</minimizeJar> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
105 changes: 105 additions & 0 deletions
105
src/main/java/com/tjackiw/graylog2/plugin/jira/JiraClient.java
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,105 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Thiago Jackiw | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.tjackiw.graylog2.plugin.jira; | ||
|
||
import org.graylog2.plugin.Tools; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class JiraClient { | ||
private static final Logger LOG = LoggerFactory.getLogger(JiraClient.class); | ||
|
||
private final String username; | ||
private final String password; | ||
private final String instanceURL; | ||
|
||
public JiraClient(String instanceURL, String username, String password) { | ||
this.username = username; | ||
this.password = password; | ||
this.instanceURL = instanceURL; | ||
} | ||
|
||
public class JiraClientException extends Exception { | ||
public JiraClientException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public JiraClientException(String msg, Throwable cause) { | ||
super(msg, cause); | ||
} | ||
} | ||
|
||
public void send(JiraIssue jiraIssue) throws JiraClientException { | ||
String jiraURL = instanceURL; | ||
if (!jiraURL.endsWith("/")) { | ||
jiraURL += "/"; | ||
} | ||
|
||
final URL url; | ||
try { | ||
url = new URL(jiraURL + "rest/api/latest/issue"); | ||
} catch (MalformedURLException e) { | ||
throw new JiraClientException("[JIRA] Error while constructing instance URL.", e); | ||
} | ||
|
||
final HttpURLConnection conn; | ||
try { | ||
String credentials = Tools.encodeBase64(username + ":" + password); | ||
conn = (HttpURLConnection) url.openConnection(); | ||
conn.setDoOutput(true); | ||
conn.setRequestMethod("POST"); | ||
conn.addRequestProperty("Authorization", "Basic " + credentials); | ||
conn.addRequestProperty("Content-Type", "application/json"); | ||
} catch (IOException e) { | ||
throw new JiraClientException("[JIRA] Could not open connection to " + jiraURL + ": ", e); | ||
} | ||
|
||
try (final OutputStream outputStream = conn.getOutputStream()) { | ||
outputStream.write(jiraIssue.toJSONString().getBytes()); | ||
outputStream.flush(); | ||
|
||
switch (conn.getResponseCode()) { | ||
case 401: | ||
throw new JiraClientException("[JIRA] Invalid credentials. Make sure your username/password are set properly."); | ||
case 201: | ||
LOG.info("[JIRA] Issue has been successfully created."); | ||
break; | ||
default: | ||
throw new JiraClientException("[JIRA] Unexpected HTTP response status " + conn.getResponseCode()); | ||
} | ||
|
||
} catch (IOException e) { | ||
throw new JiraClientException("[JIRA] Could not POST event to " + jiraURL + ": ", e); | ||
} | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/com/tjackiw/graylog2/plugin/jira/JiraIssue.java
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,89 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Thiago Jackiw | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.tjackiw.graylog2.plugin.jira; | ||
|
||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
|
||
public class JiraIssue { | ||
private final String title; | ||
private final String labels; | ||
private final String priority; | ||
private final String issueType; | ||
private final String projectKey; | ||
private final String components; | ||
private final String description; | ||
|
||
public JiraIssue(final String projectKey, final String labels, final String issueType, final String components, final String priority, final String title, final String description) { | ||
this.title = title; | ||
this.labels = labels; | ||
this.priority = priority; | ||
this.issueType = issueType; | ||
this.projectKey = projectKey; | ||
this.components = components; | ||
this.description = description; | ||
} | ||
|
||
public String toJSONString() { | ||
JSONObject project = new JSONObject(); | ||
project.put("key", projectKey); | ||
|
||
JSONObject issuetype = new JSONObject(); | ||
issuetype.put("name", issueType); | ||
|
||
JSONObject level = new JSONObject(); | ||
level.put("name", priority); | ||
|
||
JSONArray labelList = new JSONArray(); | ||
String[] labelArr = labels.split("\\,"); | ||
for (String s : labelArr) { | ||
labelList.add(s); | ||
} | ||
|
||
JSONArray componentList = new JSONArray(); | ||
String[] compArr = components.split("\\,"); | ||
for (String s : compArr) { | ||
JSONObject hash = new JSONObject(); | ||
hash.put("name", s); | ||
componentList.add(hash); | ||
} | ||
|
||
JSONObject obj = new JSONObject(); | ||
obj.put("summary", title); | ||
obj.put("description", description); | ||
obj.put("project", project); | ||
obj.put("issuetype", issuetype); | ||
obj.put("labels", labelList); | ||
obj.put("components", componentList); | ||
obj.put("priority", level); | ||
|
||
JSONObject fields = new JSONObject(); | ||
fields.put("fields", obj); | ||
|
||
return fields.toJSONString(); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/tjackiw/graylog2/plugin/jira/JiraPlugin.java
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 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Thiago Jackiw | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.tjackiw.graylog2.plugin.jira; | ||
|
||
import org.graylog2.plugin.Plugin; | ||
import org.graylog2.plugin.PluginMetaData; | ||
import org.graylog2.plugin.PluginModule; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class JiraPlugin implements Plugin { | ||
@Override | ||
public Collection<PluginModule> modules() { | ||
return Collections.<PluginModule>singleton(new JiraPluginModule()); | ||
} | ||
|
||
@Override | ||
public PluginMetaData metadata() { | ||
return new JiraPluginMetadata(); | ||
} | ||
} |
Oops, something went wrong.