Class: LogStash::Outputs::Redmine

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/redmine.rb

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/logstash/outputs/redmine.rb', line 114

def receive(event)
  return if event == LogStash::SHUTDOWN

  # interpolate parameters
  description = event.sprintf(@description)
  subject = event.sprintf(@subject)

  # Create a hash that's used for make the post_http_request with required parameters
  @issue = Hash.new
  @issue = { "issue" => {
                   "project_id" => "#{@project_id}",
                   "tracker_id" => "#{@tracker_id}",
                   "priority_id" => "#{@priority_id}",
                   "status_id" => "#{@status_id}",
                   "subject" => "#{subject}",
                   "description" => "#{description}"
                   }
           }

  # Add "not required" issue parameters in the issue hash
  @issue["issue"]["assigned_to_id"] = "#{@assigned_to_id}" if not @assigned_to_id.nil?
  @issue["issue"]["parent_issue_id"] = "#{@parent_issue_id}" if not @parent_issue_id.nil?
  @issue["issue"]["category_id"] = "#{@category_id}" if not @category_id.nil?
  @issue["issue"]["fixed_version_id"] = "#{@fixed_version_id}" if not @fixed_version_id.nil?

  # change hash issue to json for the request
  @req.body = LogStash::Json.dump(@issue)

  # send the post_http_request "req"
  @logger.info("Sending request to redmine :", :host => @formated_url, :body => @req.body)
  begin
    @http.request(@req)
  rescue => e
    @logger.warn("Skipping redmine output; error during request post", "error" => $!, "missed_event" => event)
  end #begin

end

#registerObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/logstash/outputs/redmine.rb', line 85

def register

  require 'net/http'
  require 'uri'

  # url form
  # TODO : Add a mecanism that verify and format this value
  @post_format = 'json'
  @formated_url = "#{@url}/issues.#{@post_format}"
  @uri = URI(@formated_url)
  @logger.debug("formated_uri:",:uri => @formated_url)

  #http prepare
  @http = Net::HTTP.new(@uri.host, @uri.port)
  @header = { 'Content-Type' => 'application/json', 'X-Redmine-Api-Key' => "#{@token}" }
  @req = Net::HTTP::Post.new(@uri.path, @header)
  @logger.debug("request instancied with:", :uri_path => @uri.path, :header => @header )

  #ssl verify
  if @ssl == true
    @logger.info("ssl use detected", :ssl => @ssl)
    @http.use_ssl = true
    # disable ssl certificate verification
    @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

end