Sha256: 812711de744d3c2a97898718f23a372dbad5a5e9c5f0f92041bd6b6731693b89

Contents?: true

Size: 1.81 KB

Versions: 20

Compression:

Stored size: 1.81 KB

Contents

require "uri"

module MCollective
  module Util
    class Playbook
      class Tasks
        class Graphite_eventTask < Base
          def run
            webhook_task.run
          end

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

          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

          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

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

          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
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
choria-mcorpc-support-2.26.5 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.26.4 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.26.3 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.26.2 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.26.1 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.26.0 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.25.3 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.25.2 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.25.1 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.25.0 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.24.4 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.24.3 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.24.2 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.24.1 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.24.0 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.23.3 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.23.2 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.23.1 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.23.0 lib/mcollective/util/playbook/tasks/graphite_event_task.rb
choria-mcorpc-support-2.23.0.pre lib/mcollective/util/playbook/tasks/graphite_event_task.rb