Last active
August 29, 2015 14:03
-
-
Save benlemasurier/baecbb7f666b8d750b85 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# check-smtp | |
# === | |
# | |
# This is a simple SMTP check script for Sensu | |
# | |
require 'rubygems' if RUBY_VERSION < '1.9.0' | |
require 'net/smtp' | |
require 'sensu-plugin/check/cli' | |
require 'timeout' | |
class CheckSMTP < Sensu::Plugin::Check::CLI | |
option :host, | |
:description => 'Mail server host. Default: localhost', | |
:short => '-h HOST', | |
:long => '--host HOST', | |
:default => 'localhost' | |
option :port, | |
:description => 'Mail server port. Default: 25', | |
:short => '-p PORT', | |
:long => '--port PORT', | |
:default => '25' | |
option :user, | |
:description => 'Username. Default: test', | |
:short => '-u USER', | |
:long => '--user USER', | |
:default => 'test' | |
option :password, | |
:description => 'Password. Default: test', | |
:short => '-P PASSWORD', | |
:long => '--password PASSWORD', | |
:default => 'test' | |
option :domain, | |
:description => 'Mail from domain. Default: example.com', | |
:short => '-d DOMAIN', | |
:long => '--domain DOMAIN', | |
:default => 'example.com' | |
option :tls, | |
:description => 'Enable SSL/TLS. Default: false', | |
:short => '-t', | |
:long => '--tls', | |
:default => false, | |
:boolean => true | |
def run | |
p config | |
begin | |
Timeout.timeout(15) do | |
smtp = Net::SMTP.new(config[:host], config[:port]) | |
smtp.enable_starttls unless !config[:tls] | |
smtp.start(config[:domain], config[:user], config[:password], :login) | |
end | |
ok | |
rescue Timeout::Error | |
critical "SMTP connection timed out" | |
rescue OpenSSL::SSL::SSLError => e | |
critical "SSL Error: #{e.message}" | |
rescue => e | |
critical "Error: #{e.message}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment