Ruby library for sending heartbeat messages to a Nagios server.
This is a wrapper for kbedell's Ruby implementation of the Nagios send_nsca C libary.
gem install nagios_alerter
You can create a Nagios::Alerter and call #send_alert whenever you want to send a Nagios message. There are a couple ways you can set up the Alerter:
Option 0: Using the constructor
You can set up all of the details of your alerts when you create the Alerter:
@alerter = Nagios::Alerter.new(:hostname => "some.domain.com", :service_name => "my-alerter", :return_code => SendNsca::STATUS_OK, :status => "TEST") # ... @alerter.send_alert(:host => "nagios.domain.com", :port => 5667)
Option 1: Using the instance variables
You can also use Ruby's setter methods to set or tweak your Alerter details:
@alerter = Nagios::Alerter.new @alerter.hostname = "some.domain.com" @alerter.service_name = "my-alerter" @alerter.return_code = SendNsca::STATUS_OK @alerter.status = "TEST" # ... @alerter.send_alert(:host => "nagios.domain.com", :port => 5667)
Option 2: Using the class method
You don't have to create an Alerter if you don't want to, you can use the class method instead:
Nagios::Alerter.send_alert(:host => "nagios.domain.com", :port => 5667, :hostname => "some.domain.com", :service_name => "my-alerter", :return_code => SendNsca::STATUS_OK, :status => "TEST")
Most users have only one Nagios server, so having to explicitly pass the host and port information to every #send_alert call can be very redundant. Instead, you can use Nagios::Connection to set up a globally accessible Nagios server. For example:
Nagios::Connection.instance.host = "nagios.somedomain.com" Nagios::Connection.instance.port = 5667
Nagios::Connection is a Singleton class, so you need to use #instance when you access it. You can set it up in your project's environment and have all further calls to #send_alert use those settings (except when using the class method).
# add/remove files rake manifest # make changes and reinstall to local system rake install # update version number in Rakefile and rebuild gemspec rake build_gemspec
The MIT License
Copyright © 2010 Dana Merrick
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.