Skip to content

Commit

Permalink
almost ready to try
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjcleaver committed Jun 30, 2013
1 parent 3ee6581 commit de4e90c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ vendor
data
.buildpath
.project
etc/jira-output.conf
37 changes: 0 additions & 37 deletions etc/jira-output.conf

This file was deleted.

23 changes: 23 additions & 0 deletions etc/jira-output.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
input { stdin { type => "stdin-type"}}

output {
jira {
host => "pm.xyz.com"
apikey => "user:password"
project => "LOGSTASH"
# searchfields => hash { 'field' => 'value', 'field2' => 'value2' } # only when used with the append method
# method => append/new # Create a new ticket with every event or append it based on the search method
# fields => hash { 'JiraField1' => 'value1', 'JiraField2' => 'value2' } # Add data to field for the ticket when its created initially
# comment => 'string' # Add comment to the ticket ( a new comment is placed all the time when in append method )
}

stdout {
debug => true
debug_format => "ruby"
}

elasticsearch {
index => "logstash"
type => "%{@type}"
}
}
21 changes: 12 additions & 9 deletions lib/logstash/outputs/jira.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class LogStash::Outputs::Jira < LogStash::Outputs::Base

# The hostname to send logs to. This should target your JIRA server
# and has to have the REST interface enabled
config :host, :validate => :string, :default => ""
config :host, :validate => :string

# JIRA Project name
config :project, :validate => :string, :required => true

# The RestAPI key
config :key, :validate => :string, :required => true
config :apikey, :validate => :string, :required => true

# Should the log action be sent over https instead of plain http
config :proto, :validate => :string, :default => "http"
Expand Down Expand Up @@ -86,33 +89,33 @@ def receive(event)
# Send the event over http.
# curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
# https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue#JIRARESTAPIExample-CreateIssue-Request.3
url = URI.parse("#{@proto}://#{@host}/rest/api/2/issue")
url = URI.parse("#{@proto}://#{@apikey}@#{@host}/rest/api/2/issue")
@logger.info("JIRA Rest Url", :url => url)
http = Net::HTTP::Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_password.value).new(url.host, url.port)
if url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Post.new(url.path)
request.template = {
"fields": {
request.template = '{
"fields" {
"project":
{
"key": "TEST"
"key": "#{@project}"
},
"summary": "Always do right. This will gratify some people and astonish the REST.",
"description": "Creating an issue while setting custom field values",
"issuetype": {
"name": "Bug"
},
}
}
}
}'
# "customfield_11050" : {"Value that we're putting into a Free Text Field."}
# request.body = event.to_json
request.body = request.template
response = http.request(request)
if response.is_a?(Net::HTTPSuccess)
@logger.info("Event send to Jira OK!")
@logger.info("Event send to JIRA OK!")
else
@logger.warn("HTTP error", :error => response.error!)
end
Expand Down

0 comments on commit de4e90c

Please sign in to comment.