Class: God::Contacts::Sensu

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/sensu.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from God::Contact

#group, #info, #name

Instance Method Summary collapse

Methods inherited from God::Contact

#arg, defaults, #friendly_name, generate, normalize, valid?

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Class Attribute Details

.check_nameObject

Returns the value of attribute check_name


22
23
24
# File 'lib/god/contacts/sensu.rb', line 22

def check_name
  @check_name
end

.handlerObject

Returns the value of attribute handler


22
23
24
# File 'lib/god/contacts/sensu.rb', line 22

def handler
  @handler
end

.hostObject

Returns the value of attribute host


22
23
24
# File 'lib/god/contacts/sensu.rb', line 22

def host
  @host
end

.portObject

Returns the value of attribute port


22
23
24
# File 'lib/god/contacts/sensu.rb', line 22

def port
  @port
end

.status_codeObject

Returns the value of attribute status_code


22
23
24
# File 'lib/god/contacts/sensu.rb', line 22

def status_code
  @status_code
end

Instance Attribute Details

#check_nameObject

Returns the value of attribute check_name


36
37
38
# File 'lib/god/contacts/sensu.rb', line 36

def check_name
  @check_name
end

#handlerObject

Returns the value of attribute handler


36
37
38
# File 'lib/god/contacts/sensu.rb', line 36

def handler
  @handler
end

#hostObject

Returns the value of attribute host


36
37
38
# File 'lib/god/contacts/sensu.rb', line 36

def host
  @host
end

#portObject

Returns the value of attribute port


36
37
38
# File 'lib/god/contacts/sensu.rb', line 36

def port
  @port
end

#status_codeObject

Returns the value of attribute status_code


36
37
38
# File 'lib/god/contacts/sensu.rb', line 36

def status_code
  @status_code
end

Instance Method Details

#notify(message, time, priority, category, host) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/god/contacts/sensu.rb', line 44

def notify(message, time, priority, category, host)
  data = {
    :category => category,
    :message => message,
    :priority => priority,
    :host => host,
    :time => time,
  }
  parcel = { 'name' => arg(:check_name), 'status' => arg(:status_code).nil? ? self.status_code : arg(:status_code), 'output' => data.to_json, 'handler' => arg(:handler).empty? ? self.handler : arg(:handler), 'executed' => Time.now.to_i }
  sensu_client_socket parcel.to_json
  self.info = "notified sensu: #{arg(:check_name)}"
end

#sensu_client_socket(msg) ⇒ Object


38
39
40
41
42
# File 'lib/god/contacts/sensu.rb', line 38

def sensu_client_socket(msg)
  u = UDPSocket.new
  u.send(msg + "\n", 0, arg(:host).nil? ? self.host : arg(:host), arg(:port).nil? ? self.port : arg(:port))
  u.close
end

#valid?Boolean

Returns:

  • (Boolean)

30
31
32
33
34
# File 'lib/god/contacts/sensu.rb', line 30

def valid?
  valid = true
  valid &= complain("Attribute 'check_name' must be specified", self) unless arg(:check_name)
  valid
end