Class: MCollective::Util::Playbook::Tasks::Graphite_eventTask

Inherits:
Base
  • Object
show all
Defined in:
lib/mcollective/util/playbook/tasks/graphite_event_task.rb

Instance Attribute Summary

Attributes inherited from Base

#description, #fail_ok

Instance Method Summary collapse

Methods inherited from Base

#initialize, #run_task, #startup_hook, #to_s

Methods included from MCollective::Util::Playbook::TemplateUtil

#__template_process_string, #__template_resolve, #t

Constructor Details

This class inherits a constructor from MCollective::Util::Playbook::Tasks::Base

Instance Method Details

#from_hash(properties) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 52

def from_hash(properties)
  @what = properties["what"]
  @data = properties["data"]
  @graphite = properties.fetch("graphite", "")
  @headers = properties.fetch("headers", {})
  @tags = properties.fetch("tags", ["choria"])
  @uri = URI.parse(@graphite)
end

#requestObject



12
13
14
15
16
17
18
19
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 12

def request
  {
    "what" => @what,
    "tags" => @tags.join(","),
    "when" => Time.now.to_i,
    "data" => @data
  }
end

#runObject



8
9
10
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 8

def run
  webhook_task.run
end

#to_execution_result(results) ⇒ Object



46
47
48
49
50
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 46

def to_execution_result(results)
  r = webhook_task.to_execution_result(results)
  r["type"] = "graphite"
  r
end

#validate_configuration!Object



37
38
39
40
41
42
43
44
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 37

def validate_configuration!
  raise("The 'what' property is required") unless @what
  raise("The 'data' property is required") unless @data
  raise("The 'graphite' property is required") if @graphite == ""
  raise("'tags' should be an array") unless @tags.is_a?(Array)
  raise("'headers' should be a hash") unless @headers.is_a?(Hash)
  raise("The graphite url should be either http or https") unless ["http", "https"].include?(@uri.scheme)
end

#webhook_taskObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mcollective/util/playbook/tasks/graphite_event_task.rb', line 21

def webhook_task
  return @_webhook if @_webhook

  @_webhook = Tasks::WebhookTask.new(@playbook)

  @_webhook.from_hash(
    "description" => @description,
    "headers" => @headers,
    "uri" => @graphite,
    "method" => "POST",
    "data" => request
  )

  @_webhook
end