tail-cf-plugin 0.0.11.pre → 0.0.12.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ module TailCfPlugin
2
+ class LoggregatorClient
3
+ def initialize(output)
4
+ @output = output
5
+ end
6
+
7
+ def listen(loggregator_host, space_id, app_id, user_token)
8
+ address = "#{loggregator_host}/tail/spaces/#{space_id}"
9
+ address += "/apps/#{app_id}" if app_id
10
+
11
+ address += "?authorization=#{URI.encode(user_token)}"
12
+
13
+ uri = URI.parse(address)
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ if uri.scheme == 'https'
16
+ http.use_ssl = true
17
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ end
19
+
20
+ request = Net::HTTP::Get.new uri.request_uri
21
+ output.puts "Connected to #{loggregator_host}"
22
+ http.request request do |response|
23
+ response.read_body do |chunk|
24
+ received_message = LogMessage.decode(chunk)
25
+ output.puts([received_message.app_id, received_message.source_id, received_message.message_type_name, received_message.message].join(" "))
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :output
33
+ end
34
+ end
@@ -1,17 +1,15 @@
1
1
  require 'cf'
2
- require 'faye/websocket'
3
- require 'eventmachine'
4
2
 
5
3
  module TailCfPlugin
6
- require 'tail-cf-plugin/loggregrator_client'
4
+ require 'tail-cf-plugin/loggregator_client'
7
5
  require 'log_message/log_message.pb'
6
+ require 'uri'
8
7
 
9
8
  class Plugin < CF::CLI
10
9
  include LoginRequirements
11
10
 
12
11
  desc "Tail logs for CF applications or spaces"
13
12
  group :apps
14
- input :loggregator_host, :argument => :required, :desc => "The ip:port of the loggregator"
15
13
  input :app, :desc => "App to tail logs from", :argument => :optional, :from_given => by_name(:app)
16
14
  input :space, :type => :boolean, :desc => "Logs of all apps in the current space", :default => false
17
15
 
@@ -26,11 +24,19 @@ module TailCfPlugin
26
24
  app_guid = input[:app].guid
27
25
  end
28
26
 
29
- loggregrator_client = LoggregatorClient.new(STDOUT)
30
- loggregrator_client.listen(input[:loggregator_host], client.current_space.guid, app_guid, client.token.auth_header)
27
+ loggregator_client = LoggregatorClient.new(STDOUT)
28
+ loggregator_client.listen(loggregator_host, client.current_space.guid, app_guid, client.token.auth_header)
31
29
  end
32
30
 
33
31
  ::ManifestsPlugin.default_to_app_from_manifest(:tail, false)
34
32
 
33
+ private
34
+
35
+ def loggregator_host
36
+ url = URI.parse(client.target)
37
+ domain = url.host.split(".")[1..-1].join(".")
38
+ "#{url.scheme}://loggregator.#{domain}"
39
+ end
40
+
35
41
  end
36
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tail-cf-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11.pre
4
+ version: 0.0.12.pre
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cf
@@ -33,22 +33,6 @@ dependencies:
33
33
  - - <
34
34
  - !ruby/object:Gem::Version
35
35
  version: '5.0'
36
- - !ruby/object:Gem::Dependency
37
- name: faye-websocket
38
- requirement: !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 0.6.1
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
- requirements:
49
- - - ~>
50
- - !ruby/object:Gem::Version
51
- version: 0.6.1
52
36
  - !ruby/object:Gem::Dependency
53
37
  name: beefcake
54
38
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +56,7 @@ executables: []
72
56
  extensions: []
73
57
  extra_rdoc_files: []
74
58
  files:
75
- - lib/tail-cf-plugin/loggregrator_client.rb
59
+ - lib/tail-cf-plugin/loggregator_client.rb
76
60
  - lib/tail-cf-plugin/plugin.rb
77
61
  - vendor/log_message/log_message.pb.rb
78
62
  - vendor/log_message/log_message.proto
@@ -1,36 +0,0 @@
1
- module TailCfPlugin
2
- class LoggregatorClient
3
- def initialize(output)
4
- @output = output
5
- end
6
-
7
- def listen(loggregator_host, space_id, app_id, user_token)
8
- websocket_address = "ws://#{loggregator_host}/tail/spaces/#{space_id}"
9
- websocket_address += "/apps/#{app_id}" if app_id
10
-
11
- websocket_address += "?authorization=#{URI.encode(user_token)}"
12
-
13
- EM.run {
14
- ws = Faye::WebSocket::Client.new(websocket_address, nil, :headers => {"Origin" => "http://localhost"})
15
-
16
- ws.on :message do |event|
17
- received_message = LogMessage.decode(event.data.pack("C*"))
18
- output.puts([received_message.app_id, received_message.source_id, received_message.message_type_name, received_message.message].join(" "))
19
- end
20
-
21
- ws.on :error do |event|
22
- output.puts("Server error")
23
- end
24
-
25
- ws.on :close do |event|
26
- output.puts("Server dropped connection...goodbye.")
27
- EM.stop
28
- end
29
- }
30
- end
31
-
32
- private
33
-
34
- attr_reader :output
35
- end
36
- end