diff --git a/lib/nsca/client.rb b/lib/nsca/client.rb index e69de29..85c63f4 100644 --- a/lib/nsca/client.rb +++ b/lib/nsca/client.rb @@ -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 diff --git a/spec/nsca/client_spec.rb b/spec/nsca/client_spec.rb new file mode 100644 index 0000000..da24cdb --- /dev/null +++ b/spec/nsca/client_spec.rb @@ -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