Helper methods to send service status.
This commit is contained in:
parent
86f8428c41
commit
e0ea205149
2 changed files with 77 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
require 'nsca/client/host'
|
||||
require 'nsca/client/message'
|
||||
require 'nsca/client/notifier'
|
||||
require 'nsca/client/remote_server'
|
||||
require 'nsca/client/service'
|
||||
require 'nsca/client/version'
|
||||
|
||||
module NSCA
|
||||
module Client
|
||||
class << self
|
||||
def servers
|
||||
@servers ||= []
|
||||
end
|
||||
|
||||
def ok(service, message = 'OK')
|
||||
status = false
|
||||
servers.each do |server|
|
||||
message = Message.new(:ok, message, service, server)
|
||||
notifier = Notifier.new(message)
|
||||
status = true if notifier.send_nsca
|
||||
end
|
||||
status
|
||||
end
|
||||
|
||||
def warning(service, message = 'WARNING')
|
||||
status = false
|
||||
servers.each do |server|
|
||||
message = Message.new(:warn, message, service, server)
|
||||
notifier = Notifier.new(message)
|
||||
status = true if notifier.send_nsca
|
||||
end
|
||||
status
|
||||
end
|
||||
|
||||
def critical(service, message = 'CRITICAL')
|
||||
status = false
|
||||
servers.each do |server|
|
||||
message = Message.new(:critical, message, service, server)
|
||||
notifier = Notifier.new(message)
|
||||
status = true if notifier.send_nsca
|
||||
end
|
||||
status
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
spec/nsca/client_spec.rb
Normal file
31
spec/nsca/client_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NSCA::Client do
|
||||
let(:service) { NSCA::Client::Service.new(:name => 'TestMessage') }
|
||||
|
||||
before(:all) do
|
||||
NSCA::Client.servers << NSCA::Client::RemoteServer.new(:host => '172.0.0.1')
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
SendNsca::NscaConnection.any_instance.should_receive(:send_nsca)
|
||||
end
|
||||
|
||||
context "normal service operation" do
|
||||
it "should notify" do
|
||||
NSCA::Client.ok(service).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "unstable service operation" do
|
||||
it "should notify" do
|
||||
NSCA::Client.warning(service).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "critical service state" do
|
||||
it "should notify" do
|
||||
NSCA::Client.critical(service).should be_true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue