Class: Bosh::Monitor::Plugins::ConsulEventForwarder

Inherits:
Base
  • Object
show all
Includes:
HttpRequestHelper
Defined in:
lib/bosh/monitor/plugins/consul_event_forwarder.rb

Constant Summary collapse

CONSUL_REQUEST_HEADER =
{ 'Content-Type' => 'application/javascript' }
TTL_STATUS_MAP =
{ 'running' => :pass, 'failing' => :fail, 'unknown' => :fail, 'default' => :warn }
REQUIRED_OPTIONS =
["host", "port", "protocol" ]
CONSUL_MAX_EVENT_BYTESIZE =
512
CONSUL_ENDPOINTS =
{
  event:      "/v1/event/fire/",             #fire an event
  register:   "/v1/agent/check/register",    #register a check
  deregister: "/v1/agent/check/deregister/", #deregister a check
  pass:       "/v1/agent/check/pass/",       #mark a check as passing
  warn:       "/v1/agent/check/warn/",       #mark a check as warning
  fail:       "/v1/agent/check/fail/"        #mark a check as failing
}

Instance Attribute Summary

Attributes inherited from Base

#event_kinds, #logger, #options

Instance Method Summary collapse

Methods included from HttpRequestHelper

#send_http_get_request, #send_http_post_request, #send_http_put_request, #send_http_request

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bosh::Monitor::Plugins::Base

Instance Method Details

#process(event) ⇒ Object



47
48
49
# File 'lib/bosh/monitor/plugins/consul_event_forwarder.rb', line 47

def process(event)
  validate_options && forward_event(event)
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bosh/monitor/plugins/consul_event_forwarder.rb', line 22

def run
  @checklist       = []
  @host            = options['host']
  @namespace       = options['namespace']
  @port            = options['port']
  @protocol        = options['protocol']
  @params          = options['params']
  @ttl             = options['ttl']
  @use_events      = options['events']
  @ttl_note        = options['ttl_note']

  @heartbeats_as_alerts = options['heartbeats_as_alerts']
  @use_ttl              = !@ttl.nil?

  @status_map = Hash.new(:warn)
  @status_map.merge!(TTL_STATUS_MAP)

  logger.info("Consul Event Forwarder plugin is running...")
end

#validate_optionsObject



42
43
44
45
# File 'lib/bosh/monitor/plugins/consul_event_forwarder.rb', line 42

def validate_options
  valid_array = REQUIRED_OPTIONS.map{ |o| options[o].to_s.empty? }
  !valid_array.include?(true)
end