lib/logstash/outputs/jira.rb in logstash-output-jira-0.1.4 vs lib/logstash/outputs/jira.rb in logstash-output-jira-2.0.1
- old
+ new
@@ -1,23 +1,65 @@
# encoding: utf-8
-# Origin https://groups.google.com/forum/#!msg/logstash-users/exgrB4iQ-mw/R34apku5nXsJ
-# and https://botbot.me/freenode/logstash/msg/4169496/
-# via https://gist.github.com/electrical/4660061e8fff11cdcf37#file-jira-rb
-# Uses jiralicious as the bridge to JIRA
-# By Martin Cleaver, Blended Perspectives
-# with a lot of help from 'electrical' in #logstash
-
require "logstash/outputs/base"
require "logstash/namespace"
-
+# This output allows you to use Logstash to parse and structure
+# your logs and ship structured event data to JIRA.
#
-# This is so is most useful so you can use logstash to parse and structure
-# your logs and ship structured, json events to JIRA
+# Structured event data will be added to the JIRA issue as 'Description' field value.
#
-# To use this, you'll need to ensure your JIRA instance allows REST calls
+# Example JSON-encoded event:
+#
+# {
+# "message": "Hello JIRA!",
+# "@version": "1",
+# "@timestamp": "2015-06-04T10:23:30.279Z",
+# "type": "syslog",
+# "host": "192.168.1.42",
+# "syslog_pri": "11",
+# "syslog_timestamp": "Jun 4 14:23:30",
+# "syslog_host": "myhost",
+# "program": "root",
+# "syslog_severity_code": 3,
+# "syslog_facility_code": 1,
+# "syslog_facility": "user-level",
+# "syslog_severity": "error"
+# }
+#
+# Example JIRA issue created the event above:
+#
+# Type: Task
+# Priority: 2 - Major
+# Status: TO DO
+# Resolution: Unresolved
+# Summary: [logstash] Hello JIRA!
+# Description:
+# ---
+# message: Hello JIRA!
+# '@version': '1'
+# '@timestamp': 2015-06-04 10:23:30.279000000 Z
+# type: syslog
+# host: 192.168.1.42
+# syslog_pri: '11'
+# syslog_timestamp: Jun 4 14:23:30
+# syslog_host: myhost
+# program: root
+# syslog_severity_code: 3
+# syslog_facility_code: 1
+# syslog_facility: user-level
+# syslog_severity: error
+#
+# To use this output you'll need to ensure that your JIRA instance allows REST calls.
+#
+# This output uses `jiralicious` as the bridge to JIRA
+# By Martin Cleaver, Blended Perspectives
+# with a lot of help from 'electrical' in #logstash.
+#
+# Origin <https://groups.google.com/forum/#!msg/logstash-users/exgrB4iQ-mw/R34apku5nXsJ>
+# and <https://botbot.me/freenode/logstash/msg/4169496/>
+# via <https://gist.github.com/electrical/4660061e8fff11cdcf37#file-jira-rb>.
class LogStash::Outputs::Jira < LogStash::Outputs::Base
config_name "jira"
# The hostname to send logs to. This should target your JIRA server
@@ -34,10 +76,12 @@
# JIRA Issuetype number
config :issuetypeid, :validate => :string, :required => true
# JIRA Summary
+ #
+ # Truncated and appended with '...' if longer than 255 characters.
config :summary, :validate => :string, :required => true
# JIRA Priority
config :priority, :validate => :string, :required => true
@@ -70,40 +114,32 @@
# nothing to do
end
public
def receive(event)
- return unless output?(event)
+
- if event == LogStash::SHUTDOWN
- finished
- return
- end
+ return if event == LogStash::SHUTDOWN
Jiralicious.configure do |config|
config.username = @username
config.password = @password
config.uri = @host
- config.auth_type = :cookie
+ config.auth_type = :basic
config.api_version = "latest"
end
+ # Limit issue summary to 255 characters
+ summary = event.sprintf(@summary)
+ summary = "#{summary[0,252]}..." if summary.length > 255
-issue = Jiralicious::Issue.new
+ issue = Jiralicious::Issue.new
issue.fields.set_id("project", @projectid) # would have prefered a project key, https://github.com/jstewart/jiralicious/issues/16
- issue.fields.set("summary", @summary)
+ issue.fields.set("summary", summary)
+ issue.fields.set("description", event.sprintf(event.to_hash.to_yaml))
issue.fields.set_id("issuetype", @issuetypeid)
- issue.fields.set_name("reporter", @reporter)
- issue.fields.set_name("assignee", @assignee)
+ issue.fields.set_name("reporter", @reporter) if @reporter
+ issue.fields.set_name("assignee", @assignee) if @assignee
issue.fields.set_id("priority", @priority)
-#puts issue.fields.to_yaml
issue.save
-
-
-
-# if response.is_a?(Net::HTTPSuccess)
-# @logger.info("Event send to JIRA OK!")
-# else
-# @logger.warn("HTTP error", :error => response.error!)
-# end
end # def receive
end # class LogStash::Outputs::Jira