logstash-output-hipchat 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f868fcfecff4b8e60158c837f7f0574f779bd5c7
4
- data.tar.gz: bb904b0d9c27320edffa2e52e5b10c1335e5ddc5
3
+ metadata.gz: ccdb664543fb032e93e7682e9defa67641ac7efe
4
+ data.tar.gz: b252c880912a19bdedd31e6474cccad146cda363
5
5
  SHA512:
6
- metadata.gz: 2544424102bc6593ab23606ebdb6b6b96f110f63d17e7733c39966e73dbe3b02c378ec522476f9e5886bd8b16add604657de6a1ae99dd3ebb78d7ff39e3a15ae
7
- data.tar.gz: d8c1a8a43ade709e0712f85612d16f5a881820f6e2cea1be75e62b512de47a0c28d250404f92a336671f94705e1b98161d859b6ee36b6de3d512682b57b13bf1
6
+ metadata.gz: 5d879dedf4aef41344e43877440c566aef2f11ee294d9cce284ba17b60393e37cbfb36e4c6b276280a8f6a756583f72e53213d1ae79a9456798f6207efc66b6e
7
+ data.tar.gz: ec09e5901bd30f6083a44c775e042132686674b08d29f4f9b974392878d292a1aef8379ef6e681e20aa1d59bbfc9bf9c9470089351b6a6ef47ae173bcf08dbe6
data/CHANGELOG.md CHANGED
@@ -0,0 +1,5 @@
1
+ # 2.0.0
2
+ - Use hipchat official gem
3
+ - support v2 version of the api and HipChat cloud server.
4
+ - Added a few tests
5
+ - more options of this plugin now support fieldref
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -1,20 +1,21 @@
1
1
  # encoding: utf-8
2
+ require "logstash/outputs/base"
2
3
  require "logstash/namespace"
3
- require "logstash/outputs/http"
4
4
 
5
5
  # This output allows you to write events to https://www.hipchat.com/[HipChat].
6
6
  #
7
+ # Make sure your API token have the appropriate permissions and support
8
+ # sending messages.
7
9
  class LogStash::Outputs::HipChat < LogStash::Outputs::Base
8
-
9
10
  config_name "hipchat"
10
11
 
11
12
  # The HipChat authentication token.
12
13
  config :token, :validate => :string, :required => true
13
14
 
14
- # The ID or name of the room.
15
+ # The ID or name of the room, support fieldref
15
16
  config :room_id, :validate => :string, :required => true
16
17
 
17
- # The name the message will appear be sent from.
18
+ # The name the message will appear be sent from, you can use fieldref
18
19
  config :from, :validate => :string, :default => "logstash"
19
20
 
20
21
  # Whether or not this message should trigger a notification for people in the room.
@@ -22,58 +23,49 @@ class LogStash::Outputs::HipChat < LogStash::Outputs::Base
22
23
 
23
24
  # Background color for message.
24
25
  # HipChat currently supports one of "yellow", "red", "green", "purple",
25
- # "gray", or "random". (default: yellow)
26
+ # "gray", or "random". (default: yellow), support fieldref
26
27
  config :color, :validate => :string, :default => "yellow"
27
28
 
28
29
  # Message format to send, event tokens are usable here.
29
30
  config :format, :validate => :string, :default => "%{message}"
30
31
 
32
+ # Specify `Message Format`
33
+ config :message_format, :validate => ["html", "text"], :default => "html"
34
+
35
+ # HipChat host to use
36
+ config :host, :validate => :string
37
+
31
38
  public
32
39
  def register
33
- require "ftw"
34
- require "uri"
40
+ require "hipchat"
41
+ end
35
42
 
36
- @agent = FTW::Agent.new
43
+ def client
44
+ @client ||= if @host.nil? || @host.empty?
45
+ HipChat::Client.new(@token, :api_version => "v2")
46
+ else
47
+ HipChat::Client.new(@token, :api_version => "v2", :server_url => server_url)
48
+ end
49
+ end
37
50
 
38
- @url = "https://api.hipchat.com/v1/rooms/message?auth_token=" + @token
39
- @content_type = "application/x-www-form-urlencoded"
40
- end # def register
51
+ def server_url
52
+ "https://#{@host}"
53
+ end
41
54
 
42
- public
43
55
  def receive(event)
44
56
  return unless output?(event)
45
57
 
46
- hipchat_data = Hash.new
47
- hipchat_data['room_id'] = event.sprintf(@room_id)
48
- hipchat_data['from'] = @from
49
- hipchat_data['color'] = @color
50
- hipchat_data['notify'] = @trigger_notify ? "1" : "0"
51
- hipchat_data['message'] = event.sprintf(@format)
58
+ message = event.sprintf(@format)
59
+ from = event.sprintf(@from)
60
+ color = event.sprintf(@color)
61
+ room = event.sprintf(@room_id)
52
62
 
53
- @logger.debug("HipChat data", :hipchat_data => hipchat_data)
63
+ @logger.debug("HipChat data", :from => from , :message => message, :notify => trigger_notify, :color => color, :message_format => @message_format) if @logger.debug?
54
64
 
55
65
  begin
56
- request = @agent.post(@url)
57
- request["Content-Type"] = @content_type
58
- request.body = encode(hipchat_data)
59
-
60
- response = @agent.execute(request)
61
-
62
- # Consume body to let this connection be reused
63
- rbody = ""
64
- response.read_body { |c| rbody << c }
65
- #puts rbody
66
+ client[room].send(from, message, :notify => trigger_notify, :color => color, :message_format => @message_format)
66
67
  rescue Exception => e
67
- @logger.warn("Unhandled exception", :request => request, :response => response, :exception => e, :stacktrace => e.backtrace)
68
+ logger.warn("Unhandled exception", :exception => e, :stacktrace => e.backtrace)
68
69
  end
69
- end # def receive
70
-
71
- # shamelessly lifted this from the LogStash::Outputs::Http, I'd rather put this
72
- # in a common place for both to use, but unsure where that place is or should be
73
- def encode(hash)
74
- return hash.collect do |key, value|
75
- CGI.escape(key) + "=" + CGI.escape(value)
76
- end.join("&")
77
- end # def encode
78
-
79
- end # class LogStash::Outputs::HipChat
70
+ end
71
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-hipchat'
4
- s.version = '1.0.0'
4
+ s.version = '2.0.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This output allows you to write events to Hipchat"
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
24
-
25
- s.add_runtime_dependency 'ftw', ['~> 0.0.40']
24
+ s.add_runtime_dependency "logstash-codec-plain"
25
+ s.add_runtime_dependency "hipchat"
26
26
 
27
27
  s.add_development_dependency 'logstash-devutils'
28
28
  end
@@ -1 +1,80 @@
1
- require "logstash/devutils/rspec/spec_helper"
1
+ # encoding: utf-8
2
+ require "logstash/outputs/hipchat"
3
+ require "logstash/event"
4
+ require_relative "../spec_helper"
5
+
6
+ describe LogStash::Outputs::HipChat do
7
+ let(:token) { "secret" }
8
+ let(:message) { "foobar" }
9
+ let(:event) { LogStash::Event.new({ "message" => message }) }
10
+ let(:room_id) { "secret-lair" }
11
+ let(:from) { "computer" }
12
+ let(:trigger_notify) { true }
13
+ let(:color) { "yellow" }
14
+ let(:message_format) { "html" }
15
+ let(:options) {
16
+ {
17
+ "token" => token,
18
+ "room_id" => room_id,
19
+ "from" => from,
20
+ "color" => color,
21
+ "trigger_notify" => trigger_notify
22
+ }
23
+ }
24
+ let(:hipchat) { double("hipchat") }
25
+ let(:output) { LogStash::Outputs::HipChat.new(options) }
26
+
27
+ before do
28
+ output.register
29
+ end
30
+
31
+ shared_examples "sending events" do
32
+ it "send the events" do
33
+ expect(hipchat).to receive(:send).with(from, message, :notify => trigger_notify, :color => color, :message_format => message_format)
34
+ output.receive(event)
35
+ end
36
+
37
+ context "String interpolation" do
38
+ let(:event) {
39
+ LogStash::Event.new({ "message" => message,
40
+ "my_room" => room_id,
41
+ "my_color" => color,
42
+ "from_who" => from})
43
+ }
44
+
45
+ let(:options) {
46
+ super.merge({
47
+ "token" => "secret",
48
+ "room_id" => "%{my_room}",
49
+ "from" => "%{from_who}",
50
+ "color" => "%{my_color}",
51
+ "trigger_notify" => trigger_notify
52
+ })
53
+ }
54
+
55
+ it "applies string interpolation" do
56
+ expect(hipchat).to receive(:send).with(from, message, :notify => trigger_notify, :color => color, :message_format => message_format)
57
+ output.receive(event)
58
+ end
59
+ end
60
+ end
61
+
62
+ context "default host" do
63
+ before do
64
+ expect(HipChat::Client).to receive(:new).with(token, :api_version => "v2").and_return({ room_id => hipchat })
65
+ end
66
+
67
+ include_examples "sending events"
68
+ end
69
+
70
+ context "specified host" do
71
+ let(:host) { "local.dev" }
72
+ let(:options) { super.merge({ "host" => host }) }
73
+
74
+ before do
75
+ expect(HipChat::Client).to receive(:new).with(token, :api_version => "v2", :server_url => "https://#{host}").and_return({ room_id => hipchat })
76
+ end
77
+
78
+ include_examples "sending events"
79
+ end
80
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-hipchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -31,17 +31,31 @@ dependencies:
31
31
  prerelease: false
32
32
  type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
- name: ftw
34
+ name: logstash-codec-plain
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - '>='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.0.40
39
+ version: '0'
40
40
  requirement: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ~>
42
+ - - '>='
43
43
  - !ruby/object:Gem::Version
44
- version: 0.0.40
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: hipchat
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
45
59
  prerelease: false
46
60
  type: :runtime
47
61
  - !ruby/object:Gem::Dependency
@@ -64,17 +78,16 @@ executables: []
64
78
  extensions: []
65
79
  extra_rdoc_files: []
66
80
  files:
67
- - .gitignore
81
+ - lib/logstash/outputs/hipchat.rb
82
+ - spec/spec_helper.rb
83
+ - spec/outputs/hipchat_spec.rb
84
+ - logstash-output-hipchat.gemspec
85
+ - README.md
68
86
  - CHANGELOG.md
69
87
  - CONTRIBUTORS
70
88
  - Gemfile
71
89
  - LICENSE
72
90
  - NOTICE.TXT
73
- - README.md
74
- - Rakefile
75
- - lib/logstash/outputs/hipchat.rb
76
- - logstash-output-hipchat.gemspec
77
- - spec/outputs/hipchat_spec.rb
78
91
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
79
92
  licenses:
80
93
  - Apache License (2.0)
@@ -97,9 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
110
  version: '0'
98
111
  requirements: []
99
112
  rubyforge_project:
100
- rubygems_version: 2.2.2
113
+ rubygems_version: 2.1.9
101
114
  signing_key:
102
115
  specification_version: 4
103
116
  summary: This output allows you to write events to Hipchat
104
117
  test_files:
118
+ - spec/spec_helper.rb
105
119
  - spec/outputs/hipchat_spec.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- Gemfile.lock
3
- .bundle
4
- vendor
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- @files=[]
2
-
3
- task :default do
4
- system("rake -T")
5
- end
6
-
7
- require "logstash/devutils/rake"