Class: LogStash::Inputs::Trello

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/trello.rb

Overview

A Logstash input plugin used for querying Trello at set intervals. It return events of varying types assosciated with Trello entities (ie cards, lists, etc).

Constant Summary collapse

@@plural_entities =
[
	"actions",
	"boards",
	"cards",
	"checklists",
	"invitations",
	"labels",
	"lists",
	"members",
	"memberships",
	"organizations",
	"powerups",
	"checkItemStates",
	"entities",
	"checkItems"
]
@@singular_entities =
[
	"action",
	"board",
	"card",
	"checklist",
	"invitation",
	"label",
	"list",
	"member",
	"membership",
	"organization",
	"powerup",
	"checkItem"
]
@@all_entities =
@@singular_entities + @@plural_entities
@@plural_ids =
[
	"idChecklists",
	"idLabels",
	"idMembers",
	"idMembersVoted"
]
@@singular_ids =
[
	"idBoard",
	"idList",
	"idCard",
	"idMemberCreator",
	"idMember",
	"idOrganization",
	"idCheckItem",
	"idShort"
]
@@all_ids =
@@singular_ids + @@plural_ids

Instance Method Summary collapse

Instance Method Details

#_group(data) ⇒ Object



614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/logstash/inputs/trello.rb', line 614

def _group(data)
	prototype = {}
	data.each do |entry|
		entry.each do |key, val|
			prototype[key] = []
		end
	end
	data.each do |entry|
		entry.each do |key, val|
			if val != "" and !val.nil?
				prototype[key].push(val)
			end
		end
	end
	return prototype
end

#_nested_hash_to_matrix(data, name) ⇒ Object



655
656
657
658
659
660
661
662
663
664
665
# File 'lib/logstash/inputs/trello.rb', line 655

def _nested_hash_to_matrix(data, name)
	data.each do |key, val|
		new_key = name + @sep + key.to_s
		if val.is_a?(Hash) and val != {}
			_nested_hash_to_matrix(val, new_key)
		else
			@output.push([new_key, val])
		end
	end
	return @output
end

#registerObject



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/logstash/inputs/trello.rb', line 309

def register()
	if @fields == ["all"]
		@fields = TrelloUtils::PARAM_ALL_FIELDS
	elsif @fields == ["default"]
		@fields = TrelloUtils::PARAM_DEFAULT_FIELDS
	end

	if @filters == ["all"]
		@filters = TrelloUtils::PARAM_ALL_FILTERS
	elsif @filters == ["default"]
		@filters = TrelloUtils::PARAM_DEFAULT_FILTERS
	end

	if @output_type == ["all"]
		@output_types = [
					"board",
					"memberships",
					"labels",
					"cards",
					"lists",
					"members",
					"checklists",
					"actions"
		]
	end
	@host = Socket.gethostname
	@client = TrelloUtils::TrelloClient.new({
			organizations: @organizations,
			key:           @key,
			token:         @token,
			board_ids:     @board_ids,
			fields:        @fields,
			filters:       @filters,
			port:          @port
	})
end

#run(queue) ⇒ Object



746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
# File 'lib/logstash/inputs/trello.rb', line 746

def run(queue)
	init_time = Time.now - @interval
	init_time = init_time.strftime('%Y-%m-%dT%H:%M:%S%z')
	query_times = {}
	board_ids.each { |board_id| query_times[board_id] = init_time}
	Stud.interval(@interval) do
		@client.board_ids.each do |board_id|
			uri = @client.get_uri(board_id, query_times[board_id])
			response = nil
			begin
				response = @client.issue_request(uri)
			rescue RuntimeError
				next
			end
			process_response(response, queue)
			query_times[board_id] = Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
		end
	end
end