chef-handler-datadog 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/chef-handler-datadog.rb +25 -7
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -4,8 +4,8 @@ require 'chef/handler'
4
4
  require 'dogapi'
5
5
 
6
6
  class Datadog < Chef::Handler
7
-
8
- # For the tags to work, the client must have created an Application Key on the
7
+
8
+ # For the tags to work, the client must have created an Application Key on the
9
9
  # "Account Settings" page here: https://app.datadoghq.com/account/settings
10
10
  # It should be passed along from the node/role/environemnt attributes, as the default is nil.
11
11
  def initialize(opts = {})
@@ -23,7 +23,7 @@ class Datadog < Chef::Handler
23
23
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT => e
24
24
  Chef::Log.error("Could not send metrics to Datadog. Connection error:\n" + e)
25
25
  end
26
-
26
+
27
27
  event_title = ""
28
28
  run_time = pluralize(run_status.elapsed_time, "second")
29
29
  if run_status.success?
@@ -38,7 +38,7 @@ class Datadog < Chef::Handler
38
38
  if run_status.updated_resources.length.to_i > 0
39
39
  event_data << "\n@@@\n"
40
40
  run_status.updated_resources.each do |r|
41
- event_data << "- #{r.to_s} (#{r.defined_at})\n"
41
+ event_data << "- #{r.to_s} (#{defined_at(r)})\n"
42
42
  end
43
43
  event_data << "\n@@@\n"
44
44
  end
@@ -53,8 +53,8 @@ class Datadog < Chef::Handler
53
53
  # Submit the details back to Datadog
54
54
  begin
55
55
  # Send the Event data
56
- @dog.emit_event(Dogapi::Event.new(event_data,
57
- :msg_title => event_title,
56
+ @dog.emit_event(Dogapi::Event.new(event_data,
57
+ :msg_title => event_title,
58
58
  :event_type => 'config_management.run',
59
59
  :event_object => run_status.node.name,
60
60
  :alert_type => alert_type,
@@ -100,4 +100,22 @@ class Datadog < Chef::Handler
100
100
  "#{number} #{noun}s"
101
101
  end
102
102
  end
103
- end
103
+
104
+ ## This function is to mimic behavior built into a later version of chef than 0.9.x
105
+ ## Source is here: https://github.com/opscode/chef/blob/master/chef/lib/chef/resource.rb#L415-424
106
+ ## Including this based on help from schisamo
107
+ def defined_at(resource)
108
+ cookbook_name = resource.cookbook_name
109
+ recipe_name = resource.recipe_name
110
+ source_line = resource.source_line
111
+ if cookbook_name && recipe_name && source_line
112
+ "#{cookbook_name}::#{recipe_name} line #{source_line.split(':')[1]}"
113
+ elsif source_line
114
+ file, line_no = source_line.split(':')
115
+ "#{file} line #{line_no}"
116
+ else
117
+ "dynamically defined"
118
+ end
119
+ end
120
+
121
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-datadog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Fiedler