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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6805de8c9d2645fbcb7bde2874469f93450970e
|
4
|
+
data.tar.gz: 20c9dbf6cb2e611f99b3f4000b1500a4c8dadf7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
class HttpEventReporter < Chef::EventDispatch::Base
|
6
|
+
require 'raven'
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module BloombergLP
|
9
|
+
module EventReportingHandler
|
10
|
+
class HttpEventReporter < Chef::EventDispatch::Base
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
8
|
+
module BloombergLP
|
9
|
+
module EventReportingHandler
|
10
|
+
class StartHandler < Chef::Handler
|
11
|
+
attr_reader :http_url
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|