Skip to content

Instantly share code, notes, and snippets.

Last active Mar 19, 2020
What would you like to do?
Logstash => jira
Plugin Settings
jira_url => string # Url to jira
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 )
require "logstash/outputs/base"
require "logstash/namespace"
require "uri"
# TODO(sissel): Move to something that performs better than net/http
require "net/http"
require "net/https"
# Ugly monkey patch to get around <>
Net::BufferedIO.class_eval do
BUFSIZE = 1024 * 16
def rbuf_fill
timeout(@read_timeout) {
@rbuf << @io.sysread(BUFSIZE)
# Got a loggly account? Use logstash to ship logs to Loggly!
# This is most useful so you can use logstash to parse and structure
# your logs and ship structured, json events to your account at Loggly.
# To use this, you'll need to use a Loggly input with type 'http'
# and 'json logging' enabled.
class LogStash::Outputs::Jira < LogStash::Outputs::Base
config_name "jira"
milestone 2
# The hostname to send logs to. This should target the loggly http input
# server which is usually ""
config :host, :validate => :string, :default => ""
# The RestAPI key
config :key, :validate => :string, :required => true
# Should the log action be sent over https instead of plain http
config :proto, :validate => :string, :default => "http"
# Proxy Host
config :proxy_host, :validate => :string
# Proxy Port
config :proxy_port, :validate => :number
# Proxy Username
config :proxy_user, :validate => :string
# Proxy Password
config :proxy_password, :validate => :password, :default => ""
# Ticket creation method
config :method, :validate => :string, :default => 'new'
# Search fields; When in 'append' method. search for a ticket that has these fields and data.
config :searchfields, :validate => :hash
# createfields; Add data to these fields at initial creation
config :createfields, :validate => :hash
# appendfields; Update data in these fields when appending data to an existing ticket
config :appendfields, :validate => :hash
# Comment; Add this in the comment field ( is for new and append method the same )
config :comment, :validate => :string
def register
# nothing to do
def receive(event)
return unless output?(event)
if event == LogStash::SHUTDOWN
if @method == 'append'
else if @method == 'new'
if response.is_a?(Net::HTTPSuccess)"Event send to Jira OK!")
@logger.warn("HTTP error", :error => response.error!)
end # def receive
def create
# Send the event over http or https.
url = URI.parse("#{@proto}://#{@host}/rest/api/2/issue/")"Jira Rest Url", :url => url)
@http = Net::HTTP::Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_password.value).new(, url.port)
if url.scheme == 'https'
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
# Create a new ticket
if @method == 'new'
request =
request.body = event.to_json
response = http.request(request)
else if @method == 'append' # Append it to a found ticket
end # def connect
def search
end # class LogStash::Outputs::Jira
Copy link

ofer-velich commented Sep 16, 2014

is this plugin can check if the current log has been already reported as a bug in JIRA ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment