chef-handler-datadog 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ChefHandlerDatadog
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -30,6 +30,7 @@ class Chef
30
30
  @dog.emit_point("chef.resources.total", run_status.all_resources.length, :host => hostname)
31
31
  @dog.emit_point("chef.resources.updated", run_status.updated_resources.length, :host => hostname)
32
32
  @dog.emit_point("chef.resources.elapsed_time", run_status.elapsed_time, :host => hostname)
33
+ Chef::Log.debug("Submitted chef metrics back to Datadog")
33
34
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
34
35
  Chef::Log.error("Could not send metrics to Datadog. Connection error:\n" + e)
35
36
  end
@@ -63,17 +64,34 @@ class Chef
63
64
  # Submit the details back to Datadog
64
65
  begin
65
66
  # Send the Event data
66
- @dog.emit_event(Dogapi::Event.new(event_data,
67
- :msg_title => event_title,
68
- :event_type => 'config_management.run',
69
- :event_object => hostname,
70
- :alert_type => alert_type,
71
- :priority => event_priority,
72
- :source_type_name => 'chef'
73
- ), :host => hostname)
67
+ evt = @dog.emit_event(Dogapi::Event.new(event_data,
68
+ :msg_title => event_title,
69
+ :event_type => 'config_management.run',
70
+ :event_object => hostname,
71
+ :alert_type => alert_type,
72
+ :priority => event_priority,
73
+ :source_type_name => 'chef'
74
+ ), :host => hostname)
75
+ begin
76
+ # FIXME nice-to-have: abstract format of return value away a bit
77
+ # in dogapi directly. See https://github.com/DataDog/dogapi-rb/issues/18
78
+ if evt.length < 2
79
+ Chef::Log.warn("Unexpected response from Datadog Event API: #{evt}")
80
+ else
81
+ # [http_response_code, {"event" => {"url" => "...", ...}}]
82
+ # 2xx means ok
83
+ if evt[0].to_i / 100 != 2
84
+ Chef::Log.warn("Could not submit event to Datadog (HTTP call failed): #{evt[0]}")
85
+ else
86
+ Chef::Log.debug("Successfully submitted Chef event to Datadog for #{hostname} at #{evt[1]['event']['url']}")
87
+ end
88
+ end
89
+ rescue
90
+ Chef::Log.warn("Could not determine whether chef run was successfully submitted to Datadog: #{evt}")
91
+ end
74
92
 
75
93
  # Get the current list of tags, remove any "role:" entries
76
- host_tags = @dog.host_tags(node.name)[1]["tags"] || []
94
+ host_tags = @dog.host_tags(hostname)[1]["tags"] || []
77
95
  host_tags.delete_if {|tag| tag.start_with?('role:') }
78
96
 
79
97
  # Get list of chef roles, rename them to tag format
@@ -90,7 +108,21 @@ class Chef
90
108
  new_host_tags = host_tags | chef_roles
91
109
 
92
110
  # Replace all tags with the new tags
93
- @dog.update_tags(node.name, new_host_tags)
111
+ rc = @dog.update_tags(hostname, new_host_tags)
112
+ begin
113
+ # See FIXME above about why I feel dirty repeating this code here
114
+ if evt.length < 2
115
+ Chef::Log.warn("Unexpected response from Datadog Event API: #{evt}")
116
+ else
117
+ if rc[0].to_i / 100 != 2
118
+ Chef::Log.warn("Could not submit #{chef_roles} tags for #{hostname} to Datadog")
119
+ else
120
+ Chef::Log.debug("Successfully updated #{hostname}'s tags to #{new_host_tags.join(', ')}")
121
+ end
122
+ end
123
+ rescue
124
+ Chef::Log.warn("Could not determine whether #{hostname}'s tags were successfully submitted to Datadog: #{rc}")
125
+ end
94
126
 
95
127
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
96
128
  Chef::Log.error("Could not connect to Datadog. Connection error:\n" + e)
metadata CHANGED
@@ -1,135 +1,140 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-datadog
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mike Fiedler
14
9
  - Adam Jacob
15
10
  - Alexis Le-Quoc
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2012-09-14 00:00:00 Z
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
14
+ date: 2012-09-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: chef
18
+ requirement: !ruby/object:Gem::Requirement
24
19
  none: false
25
- requirements:
20
+ requirements:
26
21
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 59
29
- segments:
30
- - 10
31
- - 12
32
- version: "10.12"
33
- prerelease: false
22
+ - !ruby/object:Gem::Version
23
+ version: '10.12'
34
24
  type: :runtime
35
- name: chef
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 11
44
- segments:
45
- - 1
46
- - 2
47
- version: "1.2"
48
25
  prerelease: false
49
- type: :runtime
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '10.12'
32
+ - !ruby/object:Gem::Dependency
50
33
  name: dogapi
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
54
35
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ type: :runtime
62
41
  prerelease: false
63
- type: :development
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ - !ruby/object:Gem::Dependency
64
49
  name: rake
65
- requirement: *id003
66
- - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
68
51
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- prerelease: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
77
56
  type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
78
65
  name: shoulda
79
- requirement: *id004
80
- - !ruby/object:Gem::Dependency
81
- version_requirements: &id005 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
82
67
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
90
- prerelease: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
91
72
  type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
92
81
  name: bundler
93
- requirement: *id005
94
- - !ruby/object:Gem::Dependency
95
- version_requirements: &id006 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
96
83
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- prerelease: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
105
88
  type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
106
97
  name: rdoc
107
- requirement: *id006
108
- - !ruby/object:Gem::Dependency
109
- version_requirements: &id007 !ruby/object:Gem::Requirement
98
+ requirement: !ruby/object:Gem::Requirement
110
99
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
- prerelease: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
119
104
  type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
120
113
  name: travis-lint
121
- requirement: *id007
122
- description: This Handler will report the events and metrics for a chef-client run to DataDog.
123
- email:
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ description: This Handler will report the events and metrics for a chef-client run
129
+ to DataDog.
130
+ email:
124
131
  - packages@datadoghq.com
125
132
  executables: []
126
-
127
133
  extensions: []
128
-
129
- extra_rdoc_files:
134
+ extra_rdoc_files:
130
135
  - README.md
131
136
  - LICENSE.txt
132
- files:
137
+ files:
133
138
  - .gitignore
134
139
  - .travis.yml
135
140
  - Gemfile
@@ -142,38 +147,30 @@ files:
142
147
  - test/helper.rb
143
148
  - test/test_chef-handler-datadog.rb
144
149
  homepage: http://www.datadoghq.com/
145
- licenses:
150
+ licenses:
146
151
  - BSD
147
152
  post_install_message:
148
153
  rdoc_options: []
149
-
150
- require_paths:
154
+ require_paths:
151
155
  - lib
152
- required_ruby_version: !ruby/object:Gem::Requirement
156
+ required_ruby_version: !ruby/object:Gem::Requirement
153
157
  none: false
154
- requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- hash: 3
158
- segments:
159
- - 0
160
- version: "0"
161
- required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  none: false
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- hash: 3
167
- segments:
168
- - 0
169
- version: "0"
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
170
168
  requirements: []
171
-
172
169
  rubyforge_project:
173
- rubygems_version: 1.8.24
170
+ rubygems_version: 1.8.23
174
171
  signing_key:
175
172
  specification_version: 3
176
173
  summary: Chef Handler for DataDog events and metrics
177
- test_files:
174
+ test_files:
178
175
  - test/helper.rb
179
176
  - test/test_chef-handler-datadog.rb