diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-03-09 13:21:36 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-03-09 13:21:36 +0000 |
commit | d07ac8ecbedb4831e5aa677b8878f0e8eb37e363 (patch) | |
tree | f7bc6a6fdd381ffa7d73f487d3f10f6e65a798e4 /lib/custodian | |
parent | 16b766cff0984494c7b81c1efc08e6386ae819f8 (diff) |
Whitespace fixups.
These were all identified and suggested by rubocop.
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/alerts/mauve.rb | 4 | ||||
-rw-r--r-- | lib/custodian/alerts/redis-state.rb | 4 | ||||
-rw-r--r-- | lib/custodian/parser.rb | 13 | ||||
-rw-r--r-- | lib/custodian/protocoltest/dns.rb | 10 | ||||
-rw-r--r-- | lib/custodian/protocoltest/dnsbl.rb | 2 | ||||
-rw-r--r-- | lib/custodian/protocoltest/http.rb | 2 | ||||
-rw-r--r-- | lib/custodian/protocoltest/mx.rb | 6 | ||||
-rw-r--r-- | lib/custodian/protocoltest/ssl.rb | 4 | ||||
-rw-r--r-- | lib/custodian/protocoltest/tcp.rb | 4 | ||||
-rw-r--r-- | lib/custodian/queue.rb | 4 | ||||
-rw-r--r-- | lib/custodian/settings.rb | 20 | ||||
-rw-r--r-- | lib/custodian/util/ping.rb | 2 | ||||
-rw-r--r-- | lib/custodian/util/timespan.rb | 8 | ||||
-rw-r--r-- | lib/custodian/worker.rb | 10 |
14 files changed, 46 insertions, 47 deletions
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 |