Class: God::Contacts::Sensu
- Inherits:
-
God::Contact
- Object
- God::Contact
- God::Contacts::Sensu
- Defined in:
- lib/god/contacts/sensu.rb
Class Attribute Summary collapse
-
.check_name ⇒ Object
Returns the value of attribute check_name.
-
.handler ⇒ Object
Returns the value of attribute handler.
-
.host ⇒ Object
Returns the value of attribute host.
-
.port ⇒ Object
Returns the value of attribute port.
-
.status_code ⇒ Object
Returns the value of attribute status_code.
Instance Attribute Summary collapse
-
#check_name ⇒ Object
Returns the value of attribute check_name.
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Attributes inherited from God::Contact
Instance Method Summary collapse
- #notify(message, time, priority, category, host) ⇒ Object
- #sensu_client_socket(msg) ⇒ Object
- #valid? ⇒ Boolean
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_name ⇒ Object
Returns the value of attribute check_name.
22 23 24 |
# File 'lib/god/contacts/sensu.rb', line 22 def check_name @check_name end |
.handler ⇒ Object
Returns the value of attribute handler.
22 23 24 |
# File 'lib/god/contacts/sensu.rb', line 22 def handler @handler end |
.host ⇒ Object
Returns the value of attribute host.
22 23 24 |
# File 'lib/god/contacts/sensu.rb', line 22 def host @host end |
.port ⇒ Object
Returns the value of attribute port.
22 23 24 |
# File 'lib/god/contacts/sensu.rb', line 22 def port @port end |
.status_code ⇒ Object
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_name ⇒ Object
Returns the value of attribute check_name.
36 37 38 |
# File 'lib/god/contacts/sensu.rb', line 36 def check_name @check_name end |
#handler ⇒ Object
Returns the value of attribute handler.
36 37 38 |
# File 'lib/god/contacts/sensu.rb', line 36 def handler @handler end |
#host ⇒ Object
Returns the value of attribute host.
36 37 38 |
# File 'lib/god/contacts/sensu.rb', line 36 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
36 37 38 |
# File 'lib/god/contacts/sensu.rb', line 36 def port @port end |
#status_code ⇒ Object
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(, time, priority, category, host) data = { :category => category, :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
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 |