summaryrefslogtreecommitdiff
path: root/lib/custodian
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-03-09 13:19:15 +0000
committerSteve Kemp <steve@steve.org.uk>2015-03-09 13:19:15 +0000
commita22b8e96ead33b0f97ed5243dbad7f7b6cd5135d (patch)
tree3fe30365cc9d793c752653a59614b52009ef9336 /lib/custodian
parent7782df6020704f51ee2d6194d8d3b74f28a53401 (diff)
Prefer single-quotes when you don't need interpolation.
So "foo" is less good than 'foo'.
Diffstat (limited to 'lib/custodian')
-rw-r--r--lib/custodian/alertfactory.rb8
-rw-r--r--lib/custodian/alerts/file.rb4
-rw-r--r--lib/custodian/alerts/graphite.rb4
-rw-r--r--lib/custodian/alerts/mauve.rb14
-rw-r--r--lib/custodian/alerts/redis-state.rb42
-rw-r--r--lib/custodian/alerts/smtp.rb4
-rw-r--r--lib/custodian/parser.rb14
-rw-r--r--lib/custodian/protocoltest/dns.rb8
-rw-r--r--lib/custodian/protocoltest/dnsbl.rb8
-rw-r--r--lib/custodian/protocoltest/ftp.rb2
-rw-r--r--lib/custodian/protocoltest/http.rb18
-rw-r--r--lib/custodian/protocoltest/imap.rb2
-rw-r--r--lib/custodian/protocoltest/jabber.rb2
-rw-r--r--lib/custodian/protocoltest/ldap.rb4
-rw-r--r--lib/custodian/protocoltest/mx.rb6
-rw-r--r--lib/custodian/protocoltest/mysql.rb2
-rw-r--r--lib/custodian/protocoltest/named.rb2
-rw-r--r--lib/custodian/protocoltest/openproxy.rb12
-rw-r--r--lib/custodian/protocoltest/ping.rb6
-rw-r--r--lib/custodian/protocoltest/pop3.rb4
-rw-r--r--lib/custodian/protocoltest/postgresql.rb2
-rw-r--r--lib/custodian/protocoltest/redis.rb2
-rw-r--r--lib/custodian/protocoltest/rsync.rb2
-rw-r--r--lib/custodian/protocoltest/smtp.rb2
-rw-r--r--lib/custodian/protocoltest/smtprelay.rb20
-rw-r--r--lib/custodian/protocoltest/ssh.rb2
-rw-r--r--lib/custodian/protocoltest/ssl.rb16
-rw-r--r--lib/custodian/protocoltest/tcp.rb8
-rw-r--r--lib/custodian/protocoltest/telnet.rb2
-rw-r--r--lib/custodian/queue.rb28
-rw-r--r--lib/custodian/settings.rb28
-rw-r--r--lib/custodian/testfactory.rb6
-rw-r--r--lib/custodian/util/ping.rb6
-rw-r--r--lib/custodian/util/timespan.rb2
-rw-r--r--lib/custodian/worker.rb18
35 files changed, 155 insertions, 155 deletions
diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb
index 1cb4751..78ad9cf 100644
--- a/lib/custodian/alertfactory.rb
+++ b/lib/custodian/alertfactory.rb
@@ -46,8 +46,8 @@ module Custodian
#
def self.create( alert_type, obj )
- raise ArgumentError, "The type of notifier to create cannot be nil" if alert_type.nil?
- raise ArgumentError, "The type of notifier to create must be a string" unless alert_type.kind_of? String
+ raise ArgumentError, 'The type of notifier to create cannot be nil' if alert_type.nil?
+ raise ArgumentError, 'The type of notifier to create must be a string' unless alert_type.kind_of? String
c = @@subclasses[alert_type]
if c
@@ -112,7 +112,7 @@ module Custodian
# Raise an alert.
#
def raise
- puts "NOP"
+ puts 'NOP'
end
@@ -121,7 +121,7 @@ module Custodian
# Clear an alert.
#
def clear
- puts "NOP"
+ puts 'NOP'
end
diff --git a/lib/custodian/alerts/file.rb b/lib/custodian/alerts/file.rb
index 5874136..cb04084 100644
--- a/lib/custodian/alerts/file.rb
+++ b/lib/custodian/alerts/file.rb
@@ -55,7 +55,7 @@ module Custodian
# Write the actual message to our target.
#
def write_message( msg )
- file = File.open(@target, "a")
+ file = File.open(@target, 'a')
file.puts( "#{Time.now} #{msg}" )
file.close
@@ -64,7 +64,7 @@ module Custodian
- register_alert_type "file"
+ register_alert_type 'file'
diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb
index 778b36b..c98f6bf 100644
--- a/lib/custodian/alerts/graphite.rb
+++ b/lib/custodian/alerts/graphite.rb
@@ -52,7 +52,7 @@ module Custodian
#
# hostname + test-type
#
- host = @test.target.gsub(/[\/\\.]/, "_")
+ host = @test.target.gsub(/[\/\\.]/, '_')
test = @test.get_type
#
@@ -69,7 +69,7 @@ module Custodian
end
- register_alert_type "graphite"
+ register_alert_type 'graphite'
end
diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb
index 92c38ee..4c20b08 100644
--- a/lib/custodian/alerts/mauve.rb
+++ b/lib/custodian/alerts/mauve.rb
@@ -49,7 +49,7 @@ module Custodian
require 'mauve/proto'
@loaded = true
rescue
- puts "ERROR Loading mauve libraries!"
+ puts 'ERROR Loading mauve libraries!'
@loaded = false
end
end
@@ -96,14 +96,14 @@ module Custodian
#
# Lookup the start of the day.
#
- day_start = @settings.key( "day_start" ).to_i || 10
- day_end = @settings.key( "day_end" ).to_i || 18
+ day_start = @settings.key( 'day_start' ).to_i || 10
+ day_end = @settings.key( 'day_end' ).to_i || 18
#
# In hour suppress
#
- working_suppress = @settings.key( "working_suppress" ).to_i || 4
- oncall_suppress = @settings.key( "oncall_suppress" ).to_i || 10
+ working_suppress = @settings.key( 'working_suppress' ).to_i || 4
+ oncall_suppress = @settings.key( 'oncall_suppress' ).to_i || 10
#
# If we're Monday-Friday, between the start & end time, then
@@ -307,7 +307,7 @@ module Custodian
#
# Did we get an error?
#
- return "" unless !resolved.nil?
+ return '' unless !resolved.nil?
#
@@ -330,7 +330,7 @@ module Custodian
end
- register_alert_type "mauve"
+ register_alert_type 'mauve'
diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb
index f37cef2..27bb2c4 100644
--- a/lib/custodian/alerts/redis-state.rb
+++ b/lib/custodian/alerts/redis-state.rb
@@ -39,7 +39,7 @@ module Custodian
@redis = Redis.new(:host => @target )
rescue
- puts "ERROR Loading redis rubygem!"
+ puts 'ERROR Loading redis rubygem!'
end
@test = obj
@@ -55,16 +55,16 @@ module Custodian
return unless( @redis )
tmp = {}
- tmp["time"] = Time.now.to_i
- tmp["type"] = @test.get_type
- tmp["target"] = @test.target
- tmp["result"] = "RAISE"
- tmp["reason"] = @test.error
- tmp["test" ] = @test.to_s
- tmp["class" ] = @test.class
+ tmp['time'] = Time.now.to_i
+ tmp['type'] = @test.get_type
+ tmp['target'] = @test.target
+ tmp['result'] = 'RAISE'
+ tmp['reason'] = @test.error
+ tmp['test' ] = @test.to_s
+ tmp['class' ] = @test.class
- @redis.lpush( "recent-tests", tmp.to_json)
- @redis.ltrim( "recent-tests", 0, 100 )
+ @redis.lpush( 'recent-tests', tmp.to_json)
+ @redis.ltrim( 'recent-tests', 0, 100 )
end
@@ -79,19 +79,19 @@ module Custodian
tmp = {}
- tmp["time"] = Time.now.to_i
- tmp["type"] = @test.get_type
- tmp["target"] = @test.target
- tmp["result"] = "OK"
- tmp["reason"] = ""
- tmp["test" ] = @test.to_s
- tmp["class" ] = @test.class
-
- @redis.lpush( "recent-tests", tmp.to_json)
- @redis.ltrim( "recent-tests", 0, 100 )
+ tmp['time'] = Time.now.to_i
+ tmp['type'] = @test.get_type
+ tmp['target'] = @test.target
+ tmp['result'] = 'OK'
+ tmp['reason'] = ''
+ tmp['test' ] = @test.to_s
+ tmp['class' ] = @test.class
+
+ @redis.lpush( 'recent-tests', tmp.to_json)
+ @redis.ltrim( 'recent-tests', 0, 100 )
end
- register_alert_type "redis"
+ register_alert_type 'redis'
end
end
diff --git a/lib/custodian/alerts/smtp.rb b/lib/custodian/alerts/smtp.rb
index e418031..38ef29e 100644
--- a/lib/custodian/alerts/smtp.rb
+++ b/lib/custodian/alerts/smtp.rb
@@ -62,14 +62,14 @@ Subject: #{subject}
#{body}
END_OF_MESSAGE
- Net::SMTP.start("127.0.0.1") do |smtp|
+ Net::SMTP.start('127.0.0.1') do |smtp|
smtp.send_message( msg, to, to)
end
end
- register_alert_type "smtp"
+ register_alert_type 'smtp'
diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb
index c75a050..6942da8 100644
--- a/lib/custodian/parser.rb
+++ b/lib/custodian/parser.rb
@@ -73,7 +73,7 @@ module Custodian
http.open_timeout = 60
http.read_timeout = 60
- if (url.scheme == "https")
+ if (url.scheme == 'https')
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@@ -89,7 +89,7 @@ module Custodian
if ( response.code.to_i != 200 )
puts "Status code of #{uri_str} was #{response.code}"
- puts "ABORTING"
+ puts 'ABORTING'
exit( 0 )
end
@@ -104,11 +104,11 @@ module Custodian
end
rescue Errno::EHOSTUNREACH => ex
- raise ex, "no route to host"
+ raise ex, 'no route to host'
rescue Timeout::Error => ex
- raise ex, "timeout"
+ raise ex, 'timeout'
rescue Errno::ECONNREFUSED => ex
- raise ex, "connection refused"
+ raise ex, 'connection refused'
end
end
@@ -135,7 +135,7 @@ module Custodian
#
# HTTP-fetch
#
- uri = $1.dup.chomp(".")
+ uri = $1.dup.chomp('.')
text = get_url_contents(uri)
text.split( /[\r\n]/ ).each do |line|
@@ -411,7 +411,7 @@ module Custodian
#
def parse_file( filename )
- raise ArgumentError, "Missing configuration file!" if filename.nil?
+ raise ArgumentError, 'Missing configuration file!' if filename.nil?
raise ArgumentError, "File not found: #{@file}" unless File.exist?( filename)
#
diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb
index 8d47e14..7f4b997 100644
--- a/lib/custodian/protocoltest/dns.rb
+++ b/lib/custodian/protocoltest/dns.rb
@@ -64,9 +64,9 @@ module Custodian
#
# Ensure we had all the data.
#
- raise ArgumentError, "Missing host to resolve" unless( @resolve_name )
- raise ArgumentError, "Missing type of record to lookup" unless( @resolve_type )
- raise ArgumentError, "Missing expected results" unless( @resolve_expected )
+ raise ArgumentError, 'Missing host to resolve' unless( @resolve_name )
+ raise ArgumentError, 'Missing type of record to lookup' unless( @resolve_type )
+ raise ArgumentError, 'Missing expected results' unless( @resolve_expected )
raise ArgumentError, "Uknown record type: #{@resolve_type}" unless( @resolve_type =~ /^(A|NS|MX|AAAA)$/ )
#
@@ -193,7 +193,7 @@ module Custodian
- register_test_type "dns"
+ register_test_type 'dns'
diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb
index 50a3b7b..d307470 100644
--- a/lib/custodian/protocoltest/dnsbl.rb
+++ b/lib/custodian/protocoltest/dnsbl.rb
@@ -31,7 +31,7 @@ module Custodian
#
# Ensure the host is an IP address.
#
- raise ArgumentError, "The target must be an IP address" unless( @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ )
+ raise ArgumentError, 'The target must be an IP address' unless( @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ )
#
# See which blacklist(s) we're testing against.
@@ -39,7 +39,7 @@ module Custodian
if line =~ /via\s+([^\s]+)\s+/
@zones = $1.dup
else
- @zones = "zen.spamhaus.org"
+ @zones = 'zen.spamhaus.org'
end
#
@@ -73,7 +73,7 @@ module Custodian
# The error is empty.
@error = nil
- @zones.split( "," ).each do |zone|
+ @zones.split( ',' ).each do |zone|
#
# Convert the IP to be looked up.
@@ -110,7 +110,7 @@ module Custodian
end
# register ourselves with the class-factory
- register_test_type "dnsbl"
+ register_test_type 'dnsbl'
end
end
end
diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb
index bbed744..921de62 100644
--- a/lib/custodian/protocoltest/ftp.rb
+++ b/lib/custodian/protocoltest/ftp.rb
@@ -92,7 +92,7 @@ module Custodian
- register_test_type "ftp"
+ register_test_type 'ftp'
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb
index c43aee3..6ed3c5b 100644
--- a/lib/custodian/protocoltest/http.rb
+++ b/lib/custodian/protocoltest/http.rb
@@ -79,10 +79,10 @@ module Custodian
case line
when /\s+must\s(not\s+)?run\s+http(\s+|\.|$)/i
then
- test_type = "http"
+ test_type = 'http'
when /\s+must\s+(not\s+)?run\s+https(\s+|\.|$)/i
then
- test_type = "https"
+ test_type = 'https'
else
raise ArgumentError, "URL has invalid scheme: #{@line}"
end
@@ -111,7 +111,7 @@ module Custodian
if line =~ /with status ([0-9]+)/
@expected_status = $1.dup
else
- @expected_status = "200"
+ @expected_status = '200'
end
if line =~ /with (IPv[46])/i
@@ -158,9 +158,9 @@ module Custodian
#
def get_type
if @url =~ /^https:/
- "https"
+ 'https'
elsif @url =~ /^http:/
- "http"
+ 'http'
else
raise ArgumentError, "URL isn't http/https: #{@url}"
end
@@ -255,7 +255,7 @@ module Custodian
end
unless @host_override.nil?
- c.headers["Host"] = @host_override
+ c.headers['Host'] = @host_override
end
c.ssl_verify_host = false
@@ -265,7 +265,7 @@ module Custodian
#
# Set a basic protocol message, for use later.
#
- protocol_msg = (resolve_mode == :ipv4 ? "IPv4" : "IPv6")
+ protocol_msg = (resolve_mode == :ipv4 ? 'IPv4' : 'IPv6')
begin
timeout( period ) do
@@ -342,8 +342,8 @@ module Custodian
end
- register_test_type "http"
- register_test_type "https"
+ register_test_type 'http'
+ register_test_type 'https'
end
end
diff --git a/lib/custodian/protocoltest/imap.rb b/lib/custodian/protocoltest/imap.rb
index 3f338b2..fb80305 100644
--- a/lib/custodian/protocoltest/imap.rb
+++ b/lib/custodian/protocoltest/imap.rb
@@ -92,7 +92,7 @@ module Custodian
- register_test_type "imap"
+ register_test_type 'imap'
diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb
index 1431139..916f15f 100644
--- a/lib/custodian/protocoltest/jabber.rb
+++ b/lib/custodian/protocoltest/jabber.rb
@@ -90,7 +90,7 @@ module Custodian
- register_test_type "jabber"
+ register_test_type 'jabber'
diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb
index aee09e0..a5f6605 100644
--- a/lib/custodian/protocoltest/ldap.rb
+++ b/lib/custodian/protocoltest/ldap.rb
@@ -92,7 +92,7 @@ module Custodian
begin
require 'ldap'
rescue LoadError
- @error = "LDAP library not available - test disabled"
+ @error = 'LDAP library not available - test disabled'
return false
end
@@ -147,7 +147,7 @@ module Custodian
- register_test_type "ldap"
+ register_test_type 'ldap'
end
diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb
index 0df1b5d..61e838c 100644
--- a/lib/custodian/protocoltest/mx.rb
+++ b/lib/custodian/protocoltest/mx.rb
@@ -103,7 +103,7 @@ module Custodian
#
failed = 0
passed = 0
- error = ""
+ error = ''
mx.each do |backend|
@@ -116,7 +116,7 @@ module Custodian
# trim to a sane length & strip newlines.
if ! read.nil?
read = read[0,255]
- read.gsub!(/[\n\r]/, "")
+ read.gsub!(/[\n\r]/, '')
end
if read =~ /^220/
@@ -161,7 +161,7 @@ module Custodian
- register_test_type "mx"
+ register_test_type 'mx'
diff --git a/lib/custodian/protocoltest/mysql.rb b/lib/custodian/protocoltest/mysql.rb
index 135dc38..7abc28f 100644
--- a/lib/custodian/protocoltest/mysql.rb
+++ b/lib/custodian/protocoltest/mysql.rb
@@ -92,7 +92,7 @@ module Custodian
- register_test_type "mysql"
+ register_test_type 'mysql'
diff --git a/lib/custodian/protocoltest/named.rb b/lib/custodian/protocoltest/named.rb
index c4e5e8a..4c1b134 100644
--- a/lib/custodian/protocoltest/named.rb
+++ b/lib/custodian/protocoltest/named.rb
@@ -90,7 +90,7 @@ module Custodian
- register_test_type "named"
+ register_test_type 'named'
diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb
index da432f0..04fe833 100644
--- a/lib/custodian/protocoltest/openproxy.rb
+++ b/lib/custodian/protocoltest/openproxy.rb
@@ -92,20 +92,20 @@ module Custodian
c.ssl_verify_host = false
c.proxy_url = @host
c.proxy_tunnel = true
- c.url = "http://google.com/"
+ c.url = 'http://google.com/'
c.ssl_verify_peer = false
c.timeout = period
c.perform
@status = c.response_code
@content = c.body_str
rescue Curl::Err::SSLCACertificateError => x
- @error = "SSL-Validation error"
+ @error = 'SSL-Validation error'
return false
rescue Curl::Err::TimeoutError
- @error = "Timed out fetching page."
+ @error = 'Timed out fetching page.'
return false
rescue Curl::Err::TooManyRedirectsError
- @error = "Too many redirections (more than 10)"
+ @error = 'Too many redirections (more than 10)'
return false
rescue => x
@error = "Exception: #{x}"
@@ -113,7 +113,7 @@ module Custodian
end
end
rescue Timeout::Error => e
- @error = "Timed out during fetch."
+ @error = 'Timed out during fetch.'
return false
end
@@ -141,7 +141,7 @@ module Custodian
- register_test_type "openproxy"
+ register_test_type 'openproxy'
diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb
index 5a9bf0a..7d3d802 100644
--- a/lib/custodian/protocoltest/ping.rb
+++ b/lib/custodian/protocoltest/ping.rb
@@ -70,8 +70,8 @@ module Custodian
# Find the binary we're going to invoke.
#
binary = nil
- binary = "./bin/multi-ping"
- binary = "/usr/bin/multi-ping" if File.exist?( "/usr/bin/multi-ping" )
+ binary = './bin/multi-ping'
+ binary = '/usr/bin/multi-ping' if File.exist?( '/usr/bin/multi-ping' )
if binary.nil?
@error = "Failed to find '/usr/bin/multi-ping'"
@@ -200,7 +200,7 @@ module Custodian
- register_test_type "ping"
+ register_test_type 'ping'
diff --git a/lib/custodian/protocoltest/pop3.rb b/lib/custodian/protocoltest/pop3.rb
index 48b2d37..3be34b3 100644
--- a/lib/custodian/protocoltest/pop3.rb
+++ b/lib/custodian/protocoltest/pop3.rb
@@ -92,8 +92,8 @@ module Custodian
- register_test_type "pop3"
- register_test_type "pop"
+ register_test_type 'pop3'
+ register_test_type 'pop'
diff --git a/lib/custodian/protocoltest/postgresql.rb b/lib/custodian/protocoltest/postgresql.rb
index 7ce4d70..2dad5cd 100644
--- a/lib/custodian/protocoltest/postgresql.rb
+++ b/lib/custodian/protocoltest/postgresql.rb
@@ -92,7 +92,7 @@ module Custodian
- register_test_type "postgresql"
+ register_test_type 'postgresql'
end
diff --git a/lib/custodian/protocoltest/redis.rb b/lib/custodian/protocoltest/redis.rb
index 1d732a0..d1815aa 100644
--- a/lib/custodian/protocoltest/redis.rb
+++ b/lib/custodian/protocoltest/redis.rb
@@ -92,7 +92,7 @@ module Custodian
- register_test_type "redis"
+ register_test_type 'redis'
diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb
index 75c27ae..0f3c288 100644
--- a/lib/custodian/protocoltest/rsync.rb
+++ b/lib/custodian/protocoltest/rsync.rb
@@ -94,7 +94,7 @@ module Custodian
- register_test_type "rsync"
+ register_test_type 'rsync'
diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb
index 1d98dca..6a8cd65 100644
--- a/lib/custodian/protocoltest/smtp.rb
+++ b/lib/custodian/protocoltest/smtp.rb
@@ -90,7 +90,7 @@ module Custodian
- register_test_type "smtp"
+ register_test_type 'smtp'
diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb
index 397c5cb..ef07f82 100644
--- a/lib/custodian/protocoltest/smtprelay.rb
+++ b/lib/custodian/protocoltest/smtprelay.rb
@@ -61,10 +61,10 @@ module Custodian
# Read the hostname for usage in the SMTP-transaction.
#
def get_hostname
- hostname = "localhost.localdomain"
+ hostname = 'localhost.localdomain'
- if File.exist?( "/etc/hostname" )
- File.readlines("/etc/hostname" ).each do |line|
+ if File.exist?( '/etc/hostname' )
+ File.readlines('/etc/hostname' ).each do |line|
hostname = line if !line.nil?
hostname.chomp!
end
@@ -87,10 +87,10 @@ module Custodian
begin
Net::SMTP.start(@host,@port, get_hostname ) do |smtp|
- sent = smtp.send_message message, "noreply@bytemark.co.uk", "noreply@bytemark.co.uk"
+ sent = smtp.send_message message, 'noreply@bytemark.co.uk', 'noreply@bytemark.co.uk'
@status = sent.status.to_s
- if @status === "250"
+ if @status === '250'
@error = "NOT OK: message sent on #{@host} with status #{@status}"
else
@error = "OK: message not sent on #{@host} with status #{@status}"
@@ -101,10 +101,10 @@ module Custodian
# and whether or not we're inverting the test. (eg, 'must not')
#
- return @inverted if @status == "250" and @inverted
- return !@inverted if @status == "250" and !@inverted
- return @inverted if @status != "250" and !@inverted
- return !@inverted if @status != "250" and @inverted
+ return @inverted if @status == '250' and @inverted
+ return !@inverted if @status == '250' and !@inverted
+ return @inverted if @status != '250' and !@inverted
+ return !@inverted if @status != '250' and @inverted
end # Net SMTP
@@ -128,7 +128,7 @@ module Custodian
end
# register ourselves with the class-factory
- register_test_type "smtprelay"
+ register_test_type 'smtprelay'
end
end
end
diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb
index 9b5a608..3d5e9fb 100644
--- a/lib/custodian/protocoltest/ssh.rb
+++ b/lib/custodian/protocoltest/ssh.rb
@@ -93,7 +93,7 @@ module Custodian
- register_test_type "ssh"
+ register_test_type 'ssh'
diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb
index 86acb34..39a962d 100644
--- a/lib/custodian/protocoltest/ssl.rb
+++ b/lib/custodian/protocoltest/ssl.rb
@@ -26,7 +26,7 @@ class SSLCheck
# Takes one parameter -- the URL.
#
def initialize(uri)
- raise ArgumentError, "URI must be a string" unless uri.is_a?(String)
+ raise ArgumentError, 'URI must be a string' unless uri.is_a?(String)
@uri = URI.parse(uri)
@domain = @uri.host
@@ -60,7 +60,7 @@ class SSLCheck
# Allows the domain to be set manually.
#
def domain=(d)
- raise ArgumentError, "domain must be a String" unless d.is_a?(String)
+ raise ArgumentError, 'domain must be a String' unless d.is_a?(String)
@domain=d
end
@@ -76,7 +76,7 @@ class SSLCheck
# ones from ALL_TESTS are taken. Anything else is ignored.
#
def tests=(ts)
- raise ArgumentError, "tests must be an Array" unless ts.is_a?(Array)
+ raise ArgumentError, 'tests must be an Array' unless ts.is_a?(Array)
@tests = ts.collect{|t| t.to_sym}.select{|t| ALL_TESTS.include?(t)}
@tests
@@ -94,7 +94,7 @@ class SSLCheck
# Probably not much use here.
#
def key=(k)
- raise ArgumentError, "key must be a String" unless k.is_a?(String)
+ raise ArgumentError, 'key must be a String' unless k.is_a?(String)
if k =~ /-----BEGIN/
@key = OpenSSL::PKey::RSA.new(k)
else
@@ -127,7 +127,7 @@ class SSLCheck
elsif b.is_a?(OpenSSL::X509::Certificate)
self.certificate_store.add_cert(b)
else
- raise ArgumentError, "bundle must be a String, an Array, or an OpenSSL::X509::Certificate"
+ raise ArgumentError, 'bundle must be a String, an Array, or an OpenSSL::X509::Certificate'
end
b
end
@@ -140,7 +140,7 @@ class SSLCheck
@certificate_store = OpenSSL::X509::Store.new
@certificate_store.set_default_paths
- @certificate_store.add_path("/etc/ssl/certs")
+ @certificate_store.add_path('/etc/ssl/certs')
@certificate_store
end
@@ -412,7 +412,7 @@ module Custodian
# Double-check we've got an SSL host
#
if ! @host =~ /^https:\/\//
- puts( "Not an SSL URL" )
+ puts( 'Not an SSL URL' )
return true
end
@@ -442,7 +442,7 @@ module Custodian
@error
end
- register_test_type "https"
+ register_test_type 'https'
end
end
diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb
index 60c7be7..ca622bb 100644
--- a/lib/custodian/protocoltest/tcp.rb
+++ b/lib/custodian/protocoltest/tcp.rb
@@ -102,7 +102,7 @@ module Custodian
@error = nil
if @port.nil?
- raise ArgumentError, "Missing port to test against"
+ raise ArgumentError, 'Missing port to test against'
end
end
@@ -280,7 +280,7 @@ module Custodian
# trim to a sane length & strip newlines.
if ! read.nil?
read = read[0,255]
- read.gsub!(/[\n\r]/, "")
+ read.gsub!(/[\n\r]/, '')
end
socket.close
@@ -317,7 +317,7 @@ module Custodian
@error = "TIMEOUT: #{e}"
return false
end
- @error = "Misc failure"
+ @error = 'Misc failure'
false
end
@@ -334,7 +334,7 @@ module Custodian
- register_test_type "tcp"
+ register_test_type 'tcp'
diff --git a/lib/custodian/protocoltest/telnet.rb b/lib/custodian/protocoltest/telnet.rb
index b5e0cde..f485191 100644
--- a/lib/custodian/protocoltest/telnet.rb
+++ b/lib/custodian/protocoltest/telnet.rb
@@ -90,7 +90,7 @@ module Custodian
- register_test_type "telnet"
+ register_test_type 'telnet'
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb
index b635c1f..12db68d 100644
--- a/lib/custodian/queue.rb
+++ b/lib/custodian/queue.rb
@@ -6,7 +6,7 @@
begin
require library
rescue LoadError
- ENV["DEBUG"] && puts( "Failed to load the library: #{library}" )
+ ENV['DEBUG'] && puts( "Failed to load the library: #{library}" )
end
end
@@ -25,9 +25,9 @@ module Custodian
#
def self.create type
case type
- when "redis"
+ when 'redis'
RedisQueueType.new
- when "beanstalk"
+ when 'beanstalk'
BeanstalkQueueType.new
else
raise "Bad queue-type: #{type}"
@@ -39,7 +39,7 @@ module Custodian
# Retrieve a job from the queue.
#
def fetch(_timeout)
- raise "Subclasses must implement this method!"
+ raise 'Subclasses must implement this method!'
end
@@ -47,7 +47,7 @@ module Custodian
# Add a new job to the queue.
#
def add(_job_string)
- raise "Subclasses must implement this method!"
+ raise 'Subclasses must implement this method!'
end
@@ -55,7 +55,7 @@ module Custodian
# Get the size of the queue
#
def size?
- raise "Subclasses must implement this method!"
+ raise 'Subclasses must implement this method!'
end
@@ -63,7 +63,7 @@ module Custodian
# Empty the queue
#
def flush!
- raise "Subclasses must implement this method!"
+ raise 'Subclasses must implement this method!'
end
end
@@ -80,7 +80,7 @@ end
# Connect to the server on localhost, unless QUEUE_ADDRESS is set.
#
def initialize
- host = ENV["QUEUE_ADDRESS"] || "127.0.0.1"
+ host = ENV['QUEUE_ADDRESS'] || '127.0.0.1'
@redis = Redis.new( :host => host )
end
@@ -96,7 +96,7 @@ end
while( true )
- foo, job = @redis.blpop( "queue", :timeout => timeout )
+ foo, job = @redis.blpop( 'queue', :timeout => timeout )
if job
return job
@@ -112,7 +112,7 @@ end
# Add a new job to the queue.
#
def add(job_string)
- @redis.rpush( "queue", job_string )
+ @redis.rpush( 'queue', job_string )
end
@@ -120,7 +120,7 @@ end
# How many jobs in the queue?
#
def size?
- @redis.llen( "queue" )
+ @redis.llen( 'queue' )
end
@@ -128,7 +128,7 @@ end
# Empty the queue, discarding all pending jobs.
#
def flush!
- @redis.del( "queue" )
+ @redis.del( 'queue' )
end
end
@@ -144,7 +144,7 @@ end
# Connect to the server on localhost, unless QUEUE_ADDRESS is set.
#
def initialize
- host = ENV["QUEUE_ADDRESS"] || "127.0.0.1"
+ host = ENV['QUEUE_ADDRESS'] || '127.0.0.1'
@queue = Beanstalk::Pool.new( ["#{host}:11300" ] )
end
@@ -162,7 +162,7 @@ end
j.delete
return b
else
- raise "ERRROR"
+ raise 'ERRROR'
end
rescue Beanstalk::TimedOut => ex
return nil
diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb
index 1739495..c4b11cb 100644
--- a/lib/custodian/settings.rb
+++ b/lib/custodian/settings.rb
@@ -35,7 +35,7 @@ module Custodian
#
# Load the configuration file; called only once.
#
- def _load( file = "/etc/custodian/custodian.cfg" )
+ def _load( file = '/etc/custodian/custodian.cfg' )
@parsed = true
@settings = {}
@@ -48,7 +48,7 @@ module Custodian
#
# Load and "parse" the key=value content.
#
- File.open( file, "r" ).each_line do |line|
+ File.open( file, 'r' ).each_line do |line|
next if line.nil? || line =~ /^#/
if line =~ /^(.*)=(.*)$/
key = $1.dup
@@ -148,7 +148,7 @@ module Custodian
def queue_type
_load unless( _loaded? )
- @settings['queue_type'] || "redis"
+ @settings['queue_type'] || 'redis'
end
@@ -159,7 +159,7 @@ module Custodian
def log_file
_load unless( _loaded? )
- @settings['log_file'] || "custodian-dequeue.log"
+ @settings['log_file'] || 'custodian-dequeue.log'
end
@@ -169,7 +169,7 @@ module Custodian
def alerter
_load unless( _loaded? )
- @settings['alerter'] || "file"
+ @settings['alerter'] || 'file'
end
@@ -179,7 +179,7 @@ module Custodian
def alert_source
_load unless( _loaded? )
- @settings['alert_source'] || "Custodian"
+ @settings['alert_source'] || 'Custodian'
end
@@ -208,14 +208,14 @@ module Custodian
# otherwise per-test defaults.
case alert
- when "smtp"
- "root"
- when "mauve"
- "alert.bytemark.co.uk"
- when "file"
- "alerts.log"
- when "redis"
- "127.0.0.1:6379"
+ when 'smtp'
+ 'root'
+ when 'mauve'
+ 'alert.bytemark.co.uk'
+ when 'file'
+ 'alerts.log'
+ when 'redis'
+ '127.0.0.1:6379'
else
nil
end
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb
index 748e114..7383ca2 100644
--- a/lib/custodian/testfactory.rb
+++ b/lib/custodian/testfactory.rb
@@ -31,8 +31,8 @@ module Custodian
def self.create( line )
- raise ArgumentError, "The type of test to create cannot be nil" if line.nil?
- raise ArgumentError, "The type of test to create must be a string" unless line.kind_of? String
+ raise ArgumentError, 'The type of test to create cannot be nil' if line.nil?
+ raise ArgumentError, 'The type of test to create must be a string' unless line.kind_of? String
#
# The array we return.
@@ -46,7 +46,7 @@ module Custodian
if line =~ /must\s+(not\s+)?run\s+(\S+)(\s+|\.|$)/
test_type = $2.dup
- test_type.chomp!( "." )
+ test_type.chomp!( '.' )
if @@subclasses[test_type].nil?
raise ArgumentError, "There is no handler registered for the '#{test_type}' test-type"
diff --git a/lib/custodian/util/ping.rb b/lib/custodian/util/ping.rb
index 771cfd6..cf79754 100644
--- a/lib/custodian/util/ping.rb
+++ b/lib/custodian/util/ping.rb
@@ -26,8 +26,8 @@ module Custodian
#
def initialize( hostname )
- raise ArgumentError, "Hostname must not be nil" if hostname.nil?
- raise ArgumentError, "Hostname must be a String" unless hostname.kind_of?( String )
+ raise ArgumentError, 'Hostname must not be nil' if hostname.nil?
+ raise ArgumentError, 'Hostname must be a String' unless hostname.kind_of?( String )
@hostname = hostname
@resolved = Custodian::Util::DNS.hostname_to_ip( hostname )
@@ -83,7 +83,7 @@ module Custodian
return true
end
else
- puts "ERROR: Resolved to neither an IPv6 or IPv4 address."
+ puts 'ERROR: Resolved to neither an IPv6 or IPv4 address.'
end
false
end
diff --git a/lib/custodian/util/timespan.rb b/lib/custodian/util/timespan.rb
index 36e8d9e..a033675 100644
--- a/lib/custodian/util/timespan.rb
+++ b/lib/custodian/util/timespan.rb
@@ -33,7 +33,7 @@ module Custodian
#
# Ensure within a valid range
#
- raise ArgumentError, "Integer required for time" unless( desc.kind_of? Integer )
+ raise ArgumentError, 'Integer required for time' unless( desc.kind_of? Integer )
raise ArgumentError, "Invalid time: #{desc}" unless( ( desc >= 0 ) && ( desc <= 23 ) )
diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb
index 9f66e4a..e5df5e5 100644
--- a/lib/custodian/worker.rb
+++ b/lib/custodian/worker.rb
@@ -93,7 +93,7 @@ module Custodian
# Show a message on STDOUT if "--verbose" was specified.
#
def log_message( msg )
- puts msg if ENV["VERBOSE" ]
+ puts msg if ENV['VERBOSE' ]
end
@@ -104,7 +104,7 @@ module Custodian
#
def run!
while( true )
- log_message( "Waiting for job.." )
+ log_message( 'Waiting for job..' )
process_single_job
end
end
@@ -125,8 +125,8 @@ module Custodian
#
# Ensure that the job is sane.
#
- raise ArgumentError, "Job was empty" if job.nil?
- raise ArgumentError, "Job was not a string" unless job.kind_of?(String)
+ raise ArgumentError, 'Job was empty' if job.nil?
+ raise ArgumentError, 'Job was not a string' unless job.kind_of?(String)
#
# Create test-objects from our class-factory, and process them.
@@ -173,7 +173,7 @@ module Custodian
result = ! result if test.inverted
if result
- log_message( "Test succeeed - clearing alert" )
+ log_message( 'Test succeeed - clearing alert' )
do_clear( test )
end
@@ -240,7 +240,7 @@ module Custodian
# Raise an alert, with each registered alerter.
#
def do_raise( test )
- @alerter.split( "," ).each do |alerter|
+ @alerter.split( ',' ).each do |alerter|
log_message( "Creating alerter: #{alerter}" )
alert = Custodian::AlertFactory.create( alerter, test )
@@ -261,7 +261,7 @@ module Custodian
# Clear an alert, with each registered alerter.
#
def do_clear( test )
- @alerter.split( "," ).each do |alerter|
+ @alerter.split( ',' ).each do |alerter|
log_message( "Creating alerter: #{alerter}" )
alert = Custodian::AlertFactory.create( alerter, test )
@@ -280,7 +280,7 @@ module Custodian
# Log the test duration with each registered alerter.
#
def do_duration( test, duration )
- @alerter.split( "," ).each do |alerter|
+ @alerter.split( ',' ).each do |alerter|
log_message( "Creating alerter: #{alerter}" )
alert = Custodian::AlertFactory.create( alerter, test )
@@ -291,7 +291,7 @@ module Custodian
# give the alerter a reference to the settings object.
alert.set_settings( @settings )
- alert.duration( duration ) if alert.respond_to? "duration"
+ alert.duration( duration ) if alert.respond_to? 'duration'
end
end