event-reporting-handler 0.1.3 → 0.1.4

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: bf8c42c9e2441cfce17d209c05bf66ee8d488ce8
4
- data.tar.gz: d35afb4b87b5555ecebbd992df27133bb44cd7d8
3
+ metadata.gz: e6805de8c9d2645fbcb7bde2874469f93450970e
4
+ data.tar.gz: 20c9dbf6cb2e611f99b3f4000b1500a4c8dadf7d
5
5
  SHA512:
6
- metadata.gz: 9b81b49cfab68c670eb5a4c50cec805288715f5e02fa42d636c7ecd35035e40234f901f9fd15740766924789b8dd235f147ecdd1d42fa69f79b0fe714898690c
7
- data.tar.gz: a8683e7f88db650ab2f817cd27d67e3d7996a9931d81f516cc3d7c61a7cdca3071073551eb71bda5989e82c11c1f711a14edc5f2ee62a819cfb4c766c61c1776
6
+ metadata.gz: 84dcd8a5bdb03b385bb2bfa9e08c32e46f2949c5b8a5395cb8a868f1af9cce7b007c65fbd41eabf33393a0dbe400ac48147f3a8076f1253b157eafc9ca7f5105
7
+ data.tar.gz: 09227886b4374bf5c8c4e87a9b708a1f52b26a6f22ad7d37ee7a7d4726e32ed37d2f57335e75de29b57543afbc25581ce7278bd0380849c0d87b82db5aa16f0a
@@ -5,7 +5,7 @@ require 'event_reporting_handler/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "event-reporting-handler"
8
- spec.version = EventReportingHandler::VERSION
8
+ spec.version = BloombergLP::EventReportingHandler::VERSION
9
9
  spec.authors = ["Shahul Khajamohideen"]
10
10
  spec.email = ["skhajamohid1@bloomberg.net"]
11
11
 
@@ -3,49 +3,83 @@
3
3
  # Copyright 2015, Bloomberg Finance L.P.
4
4
  #
5
5
  require 'chef/event_dispatch/base'
6
- module EventReportingHandler
7
- class HttpEventReporter < Chef::EventDispatch::Base
6
+ require 'raven'
8
7
 
9
- def initialize(http_url)
10
- @http_url = http_url
11
- end
8
+ module BloombergLP
9
+ module EventReportingHandler
10
+ class HttpEventReporter < Chef::EventDispatch::Base
12
11
 
13
- def run_started(run_status)
14
- @chef_run_id = run_status.run_id
15
- @node_fqdn = run_status.node.name
16
- publish_event(:run_started)
17
- end
12
+ def initialize(http_url,sentry_config,run_status)
13
+ @http_url = http_url
14
+ @node = run_status.node
15
+ Raven.configure(true) do |config|
16
+ config.ssl_verification = sentry_config['verify_ssl'] || true
17
+ config.dsn = sentry_config['dsn']
18
+ config.logger = ::Chef::Log
19
+ config.current_environment = node.chef_environment
20
+ config.environments = [node.chef_environment]
21
+ config.send_modules = Gem::Specification.respond_to?(:map)
22
+ end
23
+ Raven.logger.debug "Raven ready to report errors"
24
+ end
18
25
 
26
+ def run_started(run_status)
27
+ @chef_run_id = run_status.run_id
28
+ @node_fqdn = .name
29
+ publish_event(:run_started)
30
+ end
19
31
 
20
- # Called at the end a successful Chef run.
21
- def run_completed(node)
22
- publish_event(:run_completed)
23
- end
24
32
 
25
- # Called at the end of a failed Chef run.
26
- def run_failed(exception)
27
- publish_event(:run_failed)
28
- end
33
+ # Called at the end a successful Chef run.
34
+ def run_completed(node)
35
+ publish_event(:run_completed)
36
+ end
37
+
38
+ # Called at the end of a failed Chef run.
39
+ def run_failed(exception)
40
+ sentry_event_id = report_to_sentry(exception)
41
+ publish_event(:run_failed, {sentry_event_id: sentry_event_id})
29
42
 
30
- private
31
- def publish_event(event)
32
- json_to_publish = get_json_from_event(event)
33
- uri = URI(@http_url)
34
- res = Net::HTTP.start(uri.host, uri.port) do |http|
35
- http.post(uri.path, json_to_publish, 'Content-Type' => 'application/json')
36
43
  end
37
- case res
38
- when Net::HTTPSuccess, Net::HTTPRedirection
39
- Chef::Log.debug("Successfully sent http request with #{json_to_publish}")
40
- else
41
- Chef::Log.warn("Error in sending http request to #{url} Code is #{res.code} Msg is #{res.message}")
44
+
45
+ private
46
+ def report_to_sentry(exception)
47
+ Raven.logger.info "Logging run failure to Sentry server"
48
+ if exception
49
+ evt = Raven::Event.capture_exception(exception)
50
+ else
51
+ evt = Raven::Event.new do |evt|
52
+ evt.message = "Unknown error during Chef run"
53
+ evt.level = :error
54
+ end
55
+ end
56
+ # Use the node name, not the FQDN
57
+ evt.server_name = node.name
58
+ Raven.send(evt)
59
+ evt.id
42
60
  end
43
- end
44
61
 
45
- def get_json_from_event(event)
46
- { deploy_event: { node_fqdn: @node_fqdn, sub_type: event, occurred_at: Time.now.to_s } }.to_json
47
- end
62
+
63
+ def publish_event(event,custom_attributes)
64
+ json_to_publish = get_json_from_event(event,custom_attributes)
65
+ uri = URI(@http_url)
66
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
67
+ http.post(uri.path, json_to_publish, 'Content-Type' => 'application/json')
68
+ end
69
+ case res
70
+ when Net::HTTPSuccess, Net::HTTPRedirection
71
+ Chef::Log.debug("Successfully sent http request with #{json_to_publish} to #{@http_url}")
72
+ else
73
+ Chef::Log.warn("Error in sending http request to #{@http_url} Code is #{res.code} Msg is #{res.message}")
74
+ end
75
+ end
76
+
77
+ def get_json_from_event(event,custom_attributes)
78
+ event = { deploy_event: { node_fqdn: @node_fqdn, sub_type: event, occurred_at: Time.now.to_s } }
79
+ event.merge(custom_attributes).to_json
80
+ end
48
81
 
49
82
 
83
+ end
50
84
  end
51
85
  end
@@ -4,20 +4,24 @@
4
4
  #
5
5
 
6
6
  require 'chef/handler'
7
- module EventReportingHandler
8
- class StartHandler < Chef::Handler
9
- attr_reader :http_url
10
7
 
11
- def initialize(http_url)
12
- @http_url = http_url
13
- end
8
+ module BloombergLP
9
+ module EventReportingHandler
10
+ class StartHandler < Chef::Handler
11
+ attr_reader :http_url
14
12
 
15
- def report
16
- Chef::Log.debug("Running start handler with http_url: #{http_url}")
17
- http_event_reporter = HttpEventReporter.new(http_url)
18
- @run_status.events.register(http_event_reporter)
19
- http_event_reporter.run_started(@run_status)
20
- end
13
+ def initialize(http_url='',sentry_config={})
14
+ @http_url = http_url
15
+ @sentry_config = sentry_config
16
+ end
21
17
 
18
+ def report
19
+ Chef::Log.debug("Running start handler with http_url: #{http_url} and sentry_config: #{sentry_config} ")
20
+ http_event_reporter = HttpEventReporter.new(http_url,sentry_config,@run_status)
21
+ @run_status.events.register(http_event_reporter)
22
+ http_event_reporter.run_started(@run_status)
23
+ end
24
+
25
+ end
22
26
  end
23
27
  end
@@ -2,6 +2,8 @@
2
2
  #
3
3
  # Copyright 2015, Bloomberg Finance L.P.
4
4
  #
5
- module EventReportingHandler
6
- VERSION = "0.1.3"
5
+ module BloombergLP
6
+ module EventReportingHandler
7
+ VERSION = "0.1.4"
8
+ end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event-reporting-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shahul Khajamohideen