forked from renchap/nagios_notify_sms_ovh
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modified nagios script to alert under a threshold of remaining SMS …
…& add a script to only check remaining credits (for cron usage) Signed-off-by: Nicolas Szalay <nicolas.szalay@fotolia.com>
- Loading branch information
Nicolas Szalay
committed
Dec 17, 2010
1 parent
2a46532
commit a63d8bf
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Small utility to send Nagios alerts on a mobile phone using OVH SMS API | ||
|
||
nagios_notify_sms_ovh.rb => sends SMS | ||
single_checker.rb => only checks for remaining credit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ errorMail: | |
server: localhost | ||
to: errorMail@localhost | ||
from: errorMail@localhost | ||
credit: | ||
threshold: 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'yaml' | ||
require 'soap/wsdlDriver' | ||
require 'optparse' | ||
require 'optparse/time' | ||
require 'net/smtp' | ||
|
||
# Get rid of the SSL errors | ||
class Net::HTTP | ||
alias_method :old_initialize, :initialize | ||
def initialize(*args) | ||
old_initialize(*args) | ||
@ssl_context = OpenSSL::SSL::SSLContext.new | ||
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
end | ||
end | ||
|
||
# Parse the options | ||
options = Hash.new | ||
options[:config] = nil | ||
options[:dont_send_sms] = false | ||
|
||
opts = OptionParser.new do |opts| | ||
opts.banner = 'Usage: nagios_notify_sms_ovh.rb [options]' | ||
opts.separator '' | ||
opts.separator 'Options :' | ||
|
||
opts.on('-c', '--config=PATH', 'Path to the config file') do |config| | ||
options[:config] = config | ||
end | ||
|
||
opts.on('--dont-send-sms', 'Dont send the SMS') do |send| | ||
options[:dont_send_sms] = true | ||
end | ||
|
||
opts.on_tail('-h', '--help', 'Show this message') do | ||
puts opts | ||
exit | ||
end | ||
end | ||
|
||
begin | ||
opts.parse!(ARGV) | ||
rescue OptionParser::ParseError => e | ||
abort e.message+"\nTry --help for a list of options" | ||
end | ||
|
||
# Check if all arguments are here | ||
class MissingArg < Exception | ||
end | ||
begin | ||
raise MissingArg, 'You must specify a config file' if options[:config] == nil | ||
|
||
rescue MissingArg => e | ||
abort 'Error : '+e.message+"\nTry --help for a list of options" | ||
end | ||
|
||
# Load the config file | ||
config = YAML.load_file(options[:config]) | ||
|
||
begin | ||
wsdl = 'https://www.ovh.com/soapi/soapi-re-1.9.wsdl' | ||
soapi = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver | ||
|
||
session = soapi.login(config['ovhManager']['nicHandle'], config['ovhManager']['password'], 'en', false) | ||
|
||
#check the number of SMS left | ||
smsleft = soapi.telephonySmsCreditLeft(session, config['ovhManager']['smsAccount']).to_i | ||
if smsleft < config['credit']['threshold'] then | ||
msg = "only #{smsleft} credits left for the nagios SMS alert !" | ||
puts msg | ||
Net::SMTP.start(config['errorMail']['server']) do |smtp| | ||
smtp.send_message(msg, config['errorMail']['from'], config['errorMail']['to']) | ||
end | ||
end | ||
end | ||
# Logout | ||
soapi.logout(session) |