Class: Unsub::Service::Sensu

Inherits:
Base
  • Object
show all
Defined in:
lib/unsub/service/sensu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#log

Constructor Details

#initialize(url, log) ⇒ Sensu

Returns a new instance of Sensu.



6
7
8
9
10
# File 'lib/unsub/service/sensu.rb', line 6

def initialize url, log
  uri   = URI.parse url
  @http = Net::HTTP.new uri.host, uri.port
  @log  = log
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



4
5
6
# File 'lib/unsub/service/sensu.rb', line 4

def http
  @http
end

Instance Method Details

#delete_client(host) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/unsub/service/sensu.rb', line 25

def delete_client host
  success = if name = host[:sensu_name]
    delete_client = Net::HTTP::Delete.new '/clients/%s' % name
    response = http.request delete_client
    response.kind_of? Net::HTTPSuccess
  end

  log.info service: 'sensu', event: 'delete_client', host: host, success: success
  success
end

#extend_host(host) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/unsub/service/sensu.rb', line 13

def extend_host host
  name = if ip = host[:ip]
    client = sensu_clients.select { |c| c[:address] == ip }.shift
    client.nil? ? nil : client[:name]
  end

  old_host = host.dup ; host.merge! sensu_name: name if name
  log.info service: 'sensu', event: 'extend_host', old_host: old_host, host: host
  host
end