summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/custodian-enqueue2
-rw-r--r--lib/custodian/alerts/mauve.rb4
-rw-r--r--lib/custodian/alerts/redis-state.rb4
-rw-r--r--lib/custodian/parser.rb13
-rw-r--r--lib/custodian/protocoltest/dns.rb10
-rw-r--r--lib/custodian/protocoltest/dnsbl.rb2
-rw-r--r--lib/custodian/protocoltest/http.rb2
-rw-r--r--lib/custodian/protocoltest/mx.rb6
-rw-r--r--lib/custodian/protocoltest/ssl.rb4
-rw-r--r--lib/custodian/protocoltest/tcp.rb4
-rw-r--r--lib/custodian/queue.rb4
-rw-r--r--lib/custodian/settings.rb20
-rw-r--r--lib/custodian/util/ping.rb2
-rw-r--r--lib/custodian/util/timespan.rb8
-rw-r--r--lib/custodian/worker.rb10
-rwxr-xr-xt/test-custodian-parser.rb14
-rwxr-xr-xt/test-custodian-testfactory.rb10
-rwxr-xr-xt/test-custodian-util-ping.rb8
-rwxr-xr-xt/test-custodian-util-timespan.rb22
-rwxr-xr-xt/test-http-vs-https.rb4
-rwxr-xr-xt/test-ldap-probe.rb4
21 files changed, 78 insertions, 79 deletions
diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue
index 4d8b354..c92cb0e 100755
--- a/bin/custodian-enqueue
+++ b/bin/custodian-enqueue
@@ -131,7 +131,7 @@ if __FILE__ == $PROGRAM_NAME then
#
settings = Custodian::Settings.instance
queue = Custodian::QueueType.create(settings.queue_type)
- if ! queue
+ if !queue
puts "Failed to connect to the #{settings.queue_type} queue"
exit 1
end
diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb
index 947f019..47431d6 100644
--- a/lib/custodian/alerts/mauve.rb
+++ b/lib/custodian/alerts/mauve.rb
@@ -62,7 +62,7 @@ module Custodian
#
def raise
- return unless(@loaded)
+ return unless @loaded
#
# Get ready to send to mauve.
@@ -144,7 +144,7 @@ module Custodian
#
def clear
- return unless(@loaded)
+ return unless @loaded
#
# Get ready to send to mauve.
diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb
index bef0015..e486d9a 100644
--- a/lib/custodian/alerts/redis-state.rb
+++ b/lib/custodian/alerts/redis-state.rb
@@ -52,7 +52,7 @@ module Custodian
#
def raise
- return unless(@redis)
+ return unless @redis
tmp = {}
tmp['time'] = Time.now.to_i
@@ -75,7 +75,7 @@ module Custodian
#
def clear
- return unless(@redis)
+ return unless @redis
tmp = {}
diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb
index b0626f5..c7002e0 100644
--- a/lib/custodian/parser.rb
+++ b/lib/custodian/parser.rb
@@ -63,7 +63,7 @@ module Custodian
#
# Retrieve a HTTP/HTTPS page from the web, for macro-expansion.
#
- def get_url_contents (uri_str)
+ def get_url_contents(uri_str)
begin
uri_str = 'http://' + uri_str unless uri_str.match(/^http/)
url = URI.parse(uri_str)
@@ -96,8 +96,7 @@ module Custodian
case response
when Net::HTTPRedirection
then
- newURL = response['location'].match(/^http/)?
- response['Location']:uri_str+response['Location']
+ newURL = response['location'].match(/^http/) ? response['Location'] : uri_str + response['Location']
return(get_url_contents(newURL))
else
return response.body
@@ -215,8 +214,8 @@ module Custodian
r = []
if input =~ /^(\S+)\s+(.*)$/
- macro=$1.dup
- rest=$2.dup
+ macro = $1.dup
+ rest = $2.dup
end
@@ -237,7 +236,7 @@ module Custodian
#
def parse_line(line)
- raise ArgumentError, "Line is not a string: #{line}" unless(line.kind_of? String)
+ raise ArgumentError, "Line is not a string: #{line}" unless line.kind_of? String
line.chomp! if !line.nil?
@@ -275,7 +274,7 @@ module Custodian
if line =~ /except\s+between/i
return nil if inside
else
- return nil if ! inside
+ return nil if !inside
end
end
diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb
index add4a87..c65f90a 100644
--- a/lib/custodian/protocoltest/dns.rb
+++ b/lib/custodian/protocoltest/dns.rb
@@ -64,10 +64,10 @@ 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, "Uknown record type: #{@resolve_type}" unless(@resolve_type =~ /^(A|NS|MX|AAAA)$/)
+ 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)$/
#
# The host to query against
@@ -143,7 +143,7 @@ module Custodian
return nil
end
- Resolv::DNS.open(:nameserver=>[@server_ip]) do |dns|
+ Resolv::DNS.open(:nameserver => [@server_ip]) do |dns|
case ltype
when /^A$/ then
diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb
index 6d55260..2e51c5d 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.
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb
index 7bbc3e2..591abfb 100644
--- a/lib/custodian/protocoltest/http.rb
+++ b/lib/custodian/protocoltest/http.rb
@@ -223,7 +223,7 @@ module Custodian
#
if @cache_busting
u = URI.parse(test_url)
- if ! u.query
+ if !u.query
u.query = "ctime=#{Time.now.to_i}"
test_url = u.to_s
end
diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb
index a9cac62..c323af7 100644
--- a/lib/custodian/protocoltest/mx.rb
+++ b/lib/custodian/protocoltest/mx.rb
@@ -114,7 +114,7 @@ module Custodian
read = socket.sysread(1024)
# trim to a sane length & strip newlines.
- if ! read.nil?
+ if !read.nil?
read = read[0,255]
read.gsub!(/[\n\r]/, '')
end
@@ -126,13 +126,13 @@ module Custodian
end
rescue
# Failure to connect.
- failed +=1
+ failed += 1
error += "Error connecting to #{backend}:25. "
end
end
rescue Timeout::Error => ex
# Timeout
- failed +=1
+ failed += 1
error += "Timeout connecting to #{backend}:25. "
end
end
diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb
index dc62a77..e34e770 100644
--- a/lib/custodian/protocoltest/ssl.rb
+++ b/lib/custodian/protocoltest/ssl.rb
@@ -61,7 +61,7 @@ class SSLCheck
#
def domain=(d)
raise ArgumentError, 'domain must be a String' unless d.is_a?(String)
- @domain=d
+ @domain = d
end
#
@@ -277,7 +277,7 @@ class SSLCheck
return true
end
- days_until_expiry = (self.certificate.not_after.to_i - Time.now.to_i)/(24.0*3600).floor.to_i
+ days_until_expiry = (self.certificate.not_after.to_i - Time.now.to_i) / (24.0 * 3600).floor.to_i
if days_until_expiry > 14
verbose "The certificate for #{self.domain} is valid until #{self.certificate.not_after}."
diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb
index 0f7e2b5..eb00e99 100644
--- a/lib/custodian/protocoltest/tcp.rb
+++ b/lib/custodian/protocoltest/tcp.rb
@@ -232,7 +232,7 @@ module Custodian
# were given.
#
ips.each do |ip|
- if ! run_test_internal_real(ip, port, banner, do_read)
+ if !run_test_internal_real(ip, port, banner, do_read)
return false
#
@@ -278,7 +278,7 @@ module Custodian
read = socket.sysread(1024) if do_read
# trim to a sane length & strip newlines.
- if ! read.nil?
+ if !read.nil?
read = read[0,255]
read.gsub!(/[\n\r]/, '')
end
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb
index e9ba830..51d3a3c 100644
--- a/lib/custodian/queue.rb
+++ b/lib/custodian/queue.rb
@@ -94,7 +94,7 @@ end
def fetch(timeout = 1)
job = nil
- while(true)
+ loop do
foo, job = @redis.blpop('queue', :timeout => timeout)
@@ -191,7 +191,7 @@ end
# Flush the queue, discarding all pending jobs.
#
def flush!
- while(fetch(1))
+ while fetch(1)
# nop
end
end
diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb
index 5635ef3..318ecdc 100644
--- a/lib/custodian/settings.rb
+++ b/lib/custodian/settings.rb
@@ -43,7 +43,7 @@ module Custodian
#
# The global configuration file.
#
- return unless(File.exist?(file))
+ return unless File.exist?(file)
#
# Load and "parse" the key=value content.
@@ -84,7 +84,7 @@ module Custodian
# Retrieve an arbitrary key
#
def key(name)
- _load unless(_loaded?)
+ _load unless _loaded?
@settings[name]
end
@@ -93,7 +93,7 @@ module Custodian
# The timeout period for each individual test.
#
def timeout
- _load unless(_loaded?)
+ _load unless _loaded?
if @settings['timeout']
@settings['timeout'].to_i
@@ -109,7 +109,7 @@ module Custodian
# before raising an alert.
#
def retries
- _load unless(_loaded?)
+ _load unless _loaded?
if @settings['retries']
@settings['retries'].to_i
@@ -129,7 +129,7 @@ module Custodian
# A delay of zero is permissable.
#
def retry_delay
- _load unless(_loaded?)
+ _load unless _loaded?
if @settings['retry_delay']
@settings['retry_delay'].to_i
@@ -146,7 +146,7 @@ module Custodian
# environmental variable 'QUEUE_ADDRESS'.
#
def queue_type
- _load unless(_loaded?)
+ _load unless _loaded?
@settings['queue_type'] || 'redis'
end
@@ -157,7 +157,7 @@ module Custodian
# The filename for the logfile.
#
def log_file
- _load unless(_loaded?)
+ _load unless _loaded?
@settings['log_file'] || 'custodian-dequeue.log'
end
@@ -167,7 +167,7 @@ module Custodian
# The alerter to use
#
def alerter
- _load unless(_loaded?)
+ _load unless _loaded?
@settings['alerter'] || 'file'
end
@@ -177,7 +177,7 @@ module Custodian
# The alert-source we send. Only used when the notifier is set to mauve.
#
def alert_source
- _load unless(_loaded?)
+ _load unless _loaded?
@settings['alert_source'] || 'Custodian'
end
@@ -195,7 +195,7 @@ module Custodian
# When the alerter is "redis" the target is the redis-server address.
#
def alerter_target(alert)
- _load unless(_loaded?)
+ _load unless _loaded?
#
diff --git a/lib/custodian/util/ping.rb b/lib/custodian/util/ping.rb
index f8b7c75..3b3586e 100644
--- a/lib/custodian/util/ping.rb
+++ b/lib/custodian/util/ping.rb
@@ -78,7 +78,7 @@ module Custodian
if (system("ping6 -c 1 #{@resolved} 2>/dev/null >/dev/null") == true)
return true
end
- elsif(is_ipv4?)
+ elsif is_ipv4?
if (system("ping -c 1 #{@resolved} 2>/dev/null >/dev/null") == true)
return true
end
diff --git a/lib/custodian/util/timespan.rb b/lib/custodian/util/timespan.rb
index 9b79867..c0ca4eb 100644
--- a/lib/custodian/util/timespan.rb
+++ b/lib/custodian/util/timespan.rb
@@ -33,8 +33,8 @@ module Custodian
#
# Ensure within a valid range
#
- raise ArgumentError, 'Integer required for time' unless(desc.kind_of? Integer)
- raise ArgumentError, "Invalid time: #{desc}" unless((desc >= 0) && (desc <= 23))
+ raise ArgumentError, 'Integer required for time' unless desc.kind_of? Integer
+ raise ArgumentError, "Invalid time: #{desc}" unless (desc >= 0) && (desc <= 23)
#
@@ -67,12 +67,12 @@ module Custodian
# Iterate over the hours. Store in a hash.
#
hour = p_start
- while(hour != p_end)
+ while (hour != p_end)
valid[hour] = 1
hour += 1
hour = 0 if hour > 23
end
- valid[p_end]=1
+ valid[p_end] = 1
#
# Return the hash
diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb
index 746416f..701110e 100644
--- a/lib/custodian/worker.rb
+++ b/lib/custodian/worker.rb
@@ -79,7 +79,7 @@ module Custodian
@alerter = @settings.alerter
# How many times to repeat a failing test
- @retry_count=@settings.retries
+ @retry_count = @settings.retries
# Should we sleep between repeated tests?
@retry_delay = @settings.retry_delay
@@ -103,7 +103,7 @@ module Custodian
# Process jobs from the queue - never return.
#
def run!
- while(true)
+ loop do
log_message('Waiting for job..')
process_single_job
end
@@ -170,7 +170,7 @@ module Custodian
# Run the test - inverting the result if we should
#
result = test.run_test
- result = ! result if test.inverted
+ result = !result if test.inverted
if result
log_message('Test succeeed - clearing alert')
@@ -218,7 +218,7 @@ module Custodian
#
# If we didn't succeed on any of the attempts raise the alert.
#
- if ! result
+ if !result
#
# Raise the alert, passing the error message.
@@ -300,7 +300,7 @@ module Custodian
# Process jobs until we see a failure, then stop.
#
def process_until_fail
- while(process_single_job)
+ while process_single_job
# nop
end
end
diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb
index 514f2a4..6d612b1 100755
--- a/t/test-custodian-parser.rb
+++ b/t/test-custodian-parser.rb
@@ -109,7 +109,7 @@ class TestCustodianParser < Test::Unit::TestCase
#
parser = Custodian::Parser.new
# 3.a. Comment lines return nil.
- str =<<EOF
+ str = <<EOF
# This is a comment
# This is also a fine comment
EOF
@@ -139,7 +139,7 @@ EOF
#
# Input text
#
- text =<<EOF
+ text = <<EOF
FOO is kvm1.vm.bytemark.co.uk.
TEST is kvm2.vm.bytemark.co.uk.
EOF
@@ -154,7 +154,7 @@ EOF
# We should now have two macros.
#
macros = parser.macros
- assert(! macros.empty?)
+ assert(!macros.empty?)
assert(macros.size == 2)
end
@@ -185,7 +185,7 @@ EOF
# We should now have two macros.
#
macros = parser.macros
- assert(! macros.empty?)
+ assert(!macros.empty?)
assert(macros.size == 2)
end
@@ -218,7 +218,7 @@ EOF
# We should now have one macro.
#
macros = parser.macros
- assert(! macros.empty?)
+ assert(!macros.empty?)
assert(macros.size == 1)
end
@@ -308,7 +308,7 @@ EOF
if follow
assert(obj[0].follow_redirects?)
else
- assert(! obj[0].follow_redirects?)
+ assert(!obj[0].follow_redirects?)
end
end
end
@@ -347,7 +347,7 @@ EOF
if cb
assert(obj[0].cache_busting?)
else
- assert(! obj[0].cache_busting?)
+ assert(!obj[0].cache_busting?)
end
end
end
diff --git a/t/test-custodian-testfactory.rb b/t/test-custodian-testfactory.rb
index bde76f2..c50ad56 100755
--- a/t/test-custodian-testfactory.rb
+++ b/t/test-custodian-testfactory.rb
@@ -75,7 +75,7 @@ class TestTestFactory < Test::Unit::TestCase
obj = Custodian::TestFactory.create(str)
assert(obj.kind_of? Array)
- assert(! obj.empty?)
+ assert(!obj.empty?)
assert_equal(obj[0].get_type, 'ftp')
assert_equal(obj[0].port.to_s, prt)
@@ -108,7 +108,7 @@ class TestTestFactory < Test::Unit::TestCase
assert(obj)
assert(obj.kind_of? Array)
- assert(! obj.empty?)
+ assert(!obj.empty?)
assert(obj[0].port.to_s == prt , "'#{str}' gave expected port '#{prt}'.")
end
end
@@ -155,7 +155,7 @@ class TestTestFactory < Test::Unit::TestCase
obj = Custodian::TestFactory.create(str)
assert(obj.kind_of? Array)
- assert(! obj.empty?)
+ assert(!obj.empty?)
assert(obj[0].port.to_s == prt , "'#{str}' gave expected port '#{prt}'.")
end
end
@@ -231,7 +231,7 @@ class TestTestFactory < Test::Unit::TestCase
obj = Custodian::TestFactory.create(str)
assert(obj.kind_of? Array)
- assert(! obj.empty?)
+ assert(!obj.empty?)
#
# Ensure we got the object, and the port was correct.
@@ -305,7 +305,7 @@ class TestTestFactory < Test::Unit::TestCase
obj = Custodian::TestFactory.create(entry)
assert(obj)
assert(obj.kind_of? Array)
- assert(! obj.empty?)
+ assert(!obj.empty?)
assert_equal('test.host.example.com', obj[0].target)
end
end
diff --git a/t/test-custodian-util-ping.rb b/t/test-custodian-util-ping.rb
index 8de1cd5..bce21ff 100755
--- a/t/test-custodian-util-ping.rb
+++ b/t/test-custodian-util-ping.rb
@@ -66,7 +66,7 @@ class TestPingUtil < Test::Unit::TestCase
helper = Custodian::Util::Ping.new('ipv4.steve.org.uk')
assert(helper.is_ipv4?)
- assert(! helper.is_ipv6?)
+ assert(!helper.is_ipv6?)
end
@@ -78,7 +78,7 @@ class TestPingUtil < Test::Unit::TestCase
helper = Custodian::Util::Ping.new('ipv6.steve.org.uk')
assert(helper.is_ipv6?)
- assert(! helper.is_ipv4?)
+ assert(!helper.is_ipv4?)
end
@@ -90,8 +90,8 @@ class TestPingUtil < Test::Unit::TestCase
assert_nothing_raised do
helper = Custodian::Util::Ping.new(name)
- assert(! helper.is_ipv4?)
- assert(! helper.is_ipv6?)
+ assert(!helper.is_ipv4?)
+ assert(!helper.is_ipv6?)
end
end
diff --git a/t/test-custodian-util-timespan.rb b/t/test-custodian-util-timespan.rb
index 89dfbcd..72428be 100755
--- a/t/test-custodian-util-timespan.rb
+++ b/t/test-custodian-util-timespan.rb
@@ -59,7 +59,7 @@ class TestTimeSpanUtil < Test::Unit::TestCase
end
for hour in 0..11
- assert_equal(12 +hour, Custodian::Util::TimeSpan.to_hour("#{hour}pm"))
+ assert_equal(12 + hour, Custodian::Util::TimeSpan.to_hour("#{hour}pm"))
end
end
@@ -171,25 +171,25 @@ class TestTimeSpanUtil < Test::Unit::TestCase
#
# The preceeding + successive hours shouldn't be.
#
- assert(! Custodian::Util::TimeSpan.inside?(open, close, 15))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, 19))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, 15))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, 19))
#
# That is true for the string-versions too
#
- assert(! Custodian::Util::TimeSpan.inside?(open, close, '3pm'))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, '7pm'))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, '3pm'))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, '7pm'))
#
# Random hours should be outside too.
#
- assert(! Custodian::Util::TimeSpan.inside?(open, close, 3))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, '3am'))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, 7))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, '7am'))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, 9))
- assert(! Custodian::Util::TimeSpan.inside?(open, close, '9am'))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, 3))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, '3am'))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, 7))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, '7am'))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, 9))
+ assert(!Custodian::Util::TimeSpan.inside?(open, close, '9am'))
end
diff --git a/t/test-http-vs-https.rb b/t/test-http-vs-https.rb
index 8843683..1905b0c 100755
--- a/t/test-http-vs-https.rb
+++ b/t/test-http-vs-https.rb
@@ -47,7 +47,7 @@ class TestTestName < Test::Unit::TestCase
assert(test)
assert(test.kind_of? Array)
- assert(! test.empty?)
+ assert(!test.empty?)
assert_equal(test[0].get_type, 'http')
end
@@ -64,7 +64,7 @@ class TestTestName < Test::Unit::TestCase
assert(test)
assert(test.kind_of? Array)
- assert(! test.empty?)
+ assert(!test.empty?)
assert_equal(test[0].get_type, 'https')
end
diff --git a/t/test-ldap-probe.rb b/t/test-ldap-probe.rb
index 70b616b..9e537ac 100755
--- a/t/test-ldap-probe.rb
+++ b/t/test-ldap-probe.rb
@@ -33,7 +33,7 @@ class TestLDAPProbe < Test::Unit::TestCase
end
assert(test.kind_of? Array)
- assert(! test.empty?)
+ assert(!test.empty?)
assert_equal(test[0].get_type, 'ldap')
end
@@ -60,7 +60,7 @@ class TestLDAPProbe < Test::Unit::TestCase
test = Custodian::TestFactory.create(str)
assert(test.kind_of? Array)
- assert(! test.empty?)
+ assert(!test.empty?)
end
end