From e716a49dabe2c086a97e2d8b3cffe5cf369ad026 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 9 Mar 2015 13:19:47 +0000 Subject: Removed spaces inside parenthesis. --- lib/custodian/alertfactory.rb | 10 ++-- lib/custodian/alerts/file.rb | 14 ++--- lib/custodian/alerts/graphite.rb | 6 +-- lib/custodian/alerts/mauve.rb | 52 +++++++++--------- lib/custodian/alerts/redis-state.rb | 16 +++--- lib/custodian/alerts/smtp.rb | 10 ++-- lib/custodian/parser.rb | 74 ++++++++++++------------- lib/custodian/protocoltest/dns.rb | 26 ++++----- lib/custodian/protocoltest/dnsbl.rb | 12 ++--- lib/custodian/protocoltest/ftp.rb | 6 +-- lib/custodian/protocoltest/http.rb | 12 ++--- lib/custodian/protocoltest/imap.rb | 6 +-- lib/custodian/protocoltest/jabber.rb | 6 +-- lib/custodian/protocoltest/ldap.rb | 8 +-- lib/custodian/protocoltest/mx.rb | 8 +-- lib/custodian/protocoltest/mysql.rb | 6 +-- lib/custodian/protocoltest/named.rb | 6 +-- lib/custodian/protocoltest/openproxy.rb | 8 +-- lib/custodian/protocoltest/ping.rb | 18 +++---- lib/custodian/protocoltest/pop3.rb | 6 +-- lib/custodian/protocoltest/postgresql.rb | 6 +-- lib/custodian/protocoltest/redis.rb | 6 +-- lib/custodian/protocoltest/rsync.rb | 6 +-- lib/custodian/protocoltest/smtp.rb | 6 +-- lib/custodian/protocoltest/smtprelay.rb | 10 ++-- lib/custodian/protocoltest/ssh.rb | 6 +-- lib/custodian/protocoltest/ssl.rb | 16 +++--- lib/custodian/protocoltest/tcp.rb | 28 +++++----- lib/custodian/protocoltest/telnet.rb | 6 +-- lib/custodian/queue.rb | 22 ++++---- lib/custodian/settings.rb | 32 +++++------ lib/custodian/testfactory.rb | 14 ++--- lib/custodian/util/bytemark.rb | 2 +- lib/custodian/util/dns.rb | 10 ++-- lib/custodian/util/ping.rb | 16 +++--- lib/custodian/util/timespan.rb | 22 ++++---- lib/custodian/worker.rb | 92 ++++++++++++++++---------------- 37 files changed, 305 insertions(+), 305 deletions(-) (limited to 'lib') diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb index 78ad9cf..1baa0e3 100644 --- a/lib/custodian/alertfactory.rb +++ b/lib/custodian/alertfactory.rb @@ -44,14 +44,14 @@ module Custodian # The "obj" here is the test-case that will be generating the # raise/clear event. # - def self.create( alert_type, obj ) + 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 c = @@subclasses[alert_type] if c - c.new( obj ) + c.new(obj) else raise ArgumentError, "Bad alert type: '#{alert_type}'" end @@ -81,7 +81,7 @@ module Custodian # def get_type @@subclasses.each do |name,value| - if ( value == self.class ) + if (value == self.class) return name end end @@ -93,7 +93,7 @@ module Custodian # # Set the target for this alert. # - def set_target( target ) + def set_target(target) @target = target end @@ -102,7 +102,7 @@ module Custodian # # Store a reference to the settings # - def set_settings( obj ) + def set_settings(obj) @settings = obj end diff --git a/lib/custodian/alerts/file.rb b/lib/custodian/alerts/file.rb index cb04084..06a704e 100644 --- a/lib/custodian/alerts/file.rb +++ b/lib/custodian/alerts/file.rb @@ -21,7 +21,7 @@ module Custodian # # Constructor - save the test-object away. # - def initialize( obj ) + def initialize(obj) @test = obj end @@ -31,15 +31,15 @@ module Custodian # Record a raise event for the given test. # def raise - write_message( "RAISE: #{test.target} failed #{test.get_type}-test - #{test.error}" ) + write_message("RAISE: #{test.target} failed #{test.get_type}-test - #{test.error}") end # # Record the duration of the given test. # - def duration( seconds ) - write_message( "#{test.get_type}-test against #{test.target} took #{seconds}ms to complete" ) + def duration(seconds) + write_message("#{test.get_type}-test against #{test.target} took #{seconds}ms to complete") end @@ -47,16 +47,16 @@ module Custodian # Record a clear event for the given test. # def clear - write_message( "CLEAR: #{test.target} failed #{test.get_type}-test" ) + write_message("CLEAR: #{test.target} failed #{test.get_type}-test") end # # Write the actual message to our target. # - def write_message( msg ) + def write_message(msg) file = File.open(@target, 'a') - file.puts( "#{Time.now} #{msg}" ) + file.puts("#{Time.now} #{msg}") file.close end diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb index c98f6bf..9d69c28 100644 --- a/lib/custodian/alerts/graphite.rb +++ b/lib/custodian/alerts/graphite.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor - save the test-object away. # - def initialize( obj ) + def initialize(obj) @test = obj end @@ -47,7 +47,7 @@ module Custodian # # Send the test test-duration to graphite/carbon # - def duration( ms ) + def duration(ms) # # hostname + test-type @@ -64,7 +64,7 @@ module Custodian # Send via UDP. # socket = UDPSocket.new - socket.send( payload, 0, @target, 2003 ) + socket.send(payload, 0, @target, 2003) socket.close end diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb index 4c20b08..947f019 100644 --- a/lib/custodian/alerts/mauve.rb +++ b/lib/custodian/alerts/mauve.rb @@ -41,7 +41,7 @@ module Custodian # # Constructor # - def initialize( obj ) + def initialize(obj) @test = obj begin @@ -62,7 +62,7 @@ module Custodian # def raise - return unless( @loaded ) + return unless(@loaded) # # Get ready to send to mauve. @@ -75,7 +75,7 @@ module Custodian # # Construct a new alert structure. # - alert = _get_alert( true ) + alert = _get_alert(true) # # We're raising this alert. @@ -96,21 +96,21 @@ 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 # we're in the working day. # - if ( ( wday != 0 ) && ( wday != 6 ) ) && - ( hour >= day_start && hour < day_end ) + if ((wday != 0) && (wday != 6)) && + (hour >= day_start && hour < day_end) working = true end @@ -127,13 +127,13 @@ module Custodian # # We're going to suppress this alert now # - alert.suppress_until = Time.now.to_i + ( period * 60 ) + alert.suppress_until = Time.now.to_i + (period * 60) # # Update it and send it # update.alert << alert - Mauve::Sender.new( @target ).send(update) + Mauve::Sender.new(@target).send(update) end @@ -144,7 +144,7 @@ module Custodian # def clear - return unless( @loaded ) + return unless(@loaded) # # Get ready to send to mauve. @@ -157,7 +157,7 @@ module Custodian # # Construct a new alert structure. # - alert = _get_alert( false ) + alert = _get_alert(false) # # We're clearing this alert. @@ -168,7 +168,7 @@ module Custodian # Update it and send it # update.alert << alert - Mauve::Sender.new( @target ).send(update) + Mauve::Sender.new(@target).send(update) end @@ -184,7 +184,7 @@ module Custodian # Most of the mess of this method is ensuring there is some # "helpful" data in the detail-field of the alert. # - def _get_alert( failure ) + def _get_alert(failure) # # The subject of an alert MUST be one of: @@ -198,9 +198,9 @@ module Custodian # subject = @test.target - if ( subject =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || - ( subject =~ /^([0-9a-f:]+)$/ ) - res = Custodian::Util::DNS.ip_to_hostname( subject ) + if (subject =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || + (subject =~ /^([0-9a-f:]+)$/) + res = Custodian::Util::DNS.ip_to_hostname(subject) if res subject = res end @@ -256,7 +256,7 @@ module Custodian # # Determine if this is inside/outside the bytemark network # - location = expand_inside_bytemark( test_host ) + location = expand_inside_bytemark(test_host) if !location.nil? && location.length alert.detail = "#{alert.detail}\n#{location}" end @@ -274,7 +274,7 @@ module Custodian # or not. # # - def expand_inside_bytemark( host ) + def expand_inside_bytemark(host) # # If the host is a URL then we need to work with the hostname component alone. @@ -296,11 +296,11 @@ module Custodian # # Resolve the target to an IP, unless it is already an address. # - if ( target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || - ( target =~ /^([0-9a-f:]+)$/ ) + if (target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || + (target =~ /^([0-9a-f:]+)$/) resolved = target else - resolved = Custodian::Util::DNS.hostname_to_ip( target ) + resolved = Custodian::Util::DNS.hostname_to_ip(target) end @@ -313,14 +313,14 @@ module Custodian # # Return the formatted message # - if Custodian::Util::Bytemark.inside?( resolved.to_s ) - if ( resolved == target ) + if Custodian::Util::Bytemark.inside?(resolved.to_s) + if (resolved == target) return "

#{host} is inside the Bytemark network.

" else return "

#{host} resolves to #{resolved} which is inside the Bytemark network.

" end else - if ( resolved == target ) + if (resolved == target) return "

#{host} is OUTSIDE the Bytemark network.

" else return "

#{host} resolves to #{resolved} which is OUTSIDE the Bytemark network.

" diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb index 27bb2c4..bef0015 100644 --- a/lib/custodian/alerts/redis-state.rb +++ b/lib/custodian/alerts/redis-state.rb @@ -29,14 +29,14 @@ module Custodian # Constructor - save the test-object away & instantiate # the redis connection. # - def initialize( obj ) + def initialize(obj) begin require 'rubygems' require 'redis' require 'json' - @redis = Redis.new(:host => @target ) + @redis = Redis.new(:host => @target) rescue puts 'ERROR Loading redis rubygem!' @@ -52,7 +52,7 @@ module Custodian # def raise - return unless( @redis ) + return unless(@redis) tmp = {} tmp['time'] = Time.now.to_i @@ -63,8 +63,8 @@ module Custodian 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 @@ -75,7 +75,7 @@ module Custodian # def clear - return unless( @redis ) + return unless(@redis) tmp = {} @@ -87,8 +87,8 @@ module Custodian 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 register_alert_type 'redis' diff --git a/lib/custodian/alerts/smtp.rb b/lib/custodian/alerts/smtp.rb index 38ef29e..e6cfef0 100644 --- a/lib/custodian/alerts/smtp.rb +++ b/lib/custodian/alerts/smtp.rb @@ -20,7 +20,7 @@ module Custodian # # Constructor - save the test-object away. # - def initialize( obj ) + def initialize(obj) @test = obj end @@ -33,7 +33,7 @@ module Custodian subject = "#{test.target} alert #{test.get_type}-test - #{test.error}" body = "The alert has raised, with the following details:\n#{test.error}\nRegards\n" - _send_mail( @target, subject, body ) + _send_mail(@target, subject, body) end @@ -45,7 +45,7 @@ module Custodian subject = "#{test.target} cleared #{test.get_type}-test" body = "The alert has cleared\nRegards\n" - _send_mail( @target, subject, body ) + _send_mail(@target, subject, body) end @@ -53,7 +53,7 @@ module Custodian # # Send an email # - def _send_mail( to, subject, body ) + def _send_mail(to, subject, body) msg = < 0 + text.split(/[\r\n]/).each do |line| + val.push(line) if line.length > 0 end elsif line =~ /\s(is|are)\s+(.*)\.+$/ @@ -153,19 +153,19 @@ module Custodian # If there is " and " then tokenize # if hosts =~ /\s+and\s+/ - tmp = hosts.split( /\s+and\s+/ ) + tmp = hosts.split(/\s+and\s+/) tmp.each do |entry| - val.push( entry ) + val.push(entry) end else # # Otherwise a single host # - val.push( hosts ) + val.push(hosts) end end - if is_macro?( name ) + if is_macro?(name) raise ArgumentError, "The macro #{name} is already defined" end @@ -192,7 +192,7 @@ module Custodian # # Is the given string of text a macro? # - def is_macro?( name ) + def is_macro?(name) !(@MACROS[name]).nil? end @@ -201,7 +201,7 @@ module Custodian # # Return an array of hosts if the given string was a macro identifier. # - def get_macro_targets( name ) + def get_macro_targets(name) @MACROS[name] end @@ -210,7 +210,7 @@ module Custodian # # Return multiple copies of a line for each macro-target # - def expand_macro( input ) + def expand_macro(input) r = [] @@ -220,12 +220,12 @@ module Custodian end - if is_macro?( macro ) + if is_macro?(macro) get_macro_targets(macro).each do |host| - r.push( "#{host} #{rest}" ) + r.push("#{host} #{rest}") end else - r.push( input ) + r.push(input) end r @@ -235,9 +235,9 @@ module Custodian # # Parse a single line from the configuration file. # - def parse_line( line ) + 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? @@ -246,7 +246,7 @@ module Custodian # # A blank line, or a comment may be skipped. # - return nil if ( line.nil? ) || ( line =~ /^#/ ) || ( line.length < 1 ) + return nil if (line.nil?) || (line =~ /^#/) || (line.length < 1) # # Look for a time period. @@ -267,7 +267,7 @@ module Custodian # # Does the hour match the period? # - inside = Custodian::Util::TimeSpan.inside?( p_start, p_end, hour ) + inside = Custodian::Util::TimeSpan.inside?(p_start, p_end, hour) # # Should we exclude the test? @@ -283,10 +283,10 @@ module Custodian # Look for macro definitions, inline # if line =~ /^([0-9A-Z]_+)\s+are\s+fetched\s+from\s+([^\s]+)\.?/ - define_macro( line ) + define_macro(line) elsif line =~ /^([0-9A-Z_]+)\s+(is|are)\s+/ - define_macro( line ) + define_macro(line) elsif line =~ /^(\S+)\s+must\s+ping(.*)/ # @@ -308,14 +308,14 @@ module Custodian pre = $1.dup post = $2.dup new_line = "#{pre} must run ping #{post}" - return( parse_line( new_line ) ) + return(parse_line(new_line)) elsif line =~ /^\S+\s+must(\s+not)?\s+run\s+([^\s]+)(\s+|\.|$)/i # # Expand the macro if we should # - tests = expand_macro( line ) + tests = expand_macro(line) # # The array of objects we will return to the caller. @@ -342,10 +342,10 @@ module Custodian # if there are multiple handlers and we should always have one - # or an unknown job-type of course! # - job = Custodian::TestFactory.create( macro_expanded ) + job = Custodian::TestFactory.create(macro_expanded) - if job && ( job.kind_of? Array ) - ret.push( job[0].to_s ) + if job && (job.kind_of? Array) + ret.push(job[0].to_s) end rescue => ex raise ArgumentError, "Parsing a line to a protocol test gave the error: #{ex}" @@ -363,13 +363,13 @@ module Custodian # # Parse a text-snippet, with multiple lines. # - def parse_lines( text ) + def parse_lines(text) # # If we're given a string then split it on newline # - if text.kind_of?( String ) - a = text.split( /[\r\n]/ ) + if text.kind_of?(String) + a = text.split(/[\r\n]/) text = a end @@ -379,7 +379,7 @@ module Custodian # Split on newline # text.each do |line| - ret = parse_line( line ) + ret = parse_line(line) # # The return value from the parse_line method @@ -392,9 +392,9 @@ module Custodian # The line was a comment. # # - if ret.kind_of?( Array ) + if ret.kind_of?(Array) ret.each do |probe| - @jobs.push( probe ) + @jobs.push(probe) end end end @@ -409,20 +409,20 @@ module Custodian # # This updates our @jobs array with the tests. # - def parse_file( filename ) + def parse_file(filename) raise ArgumentError, 'Missing configuration file!' if filename.nil? - raise ArgumentError, "File not found: #{@file}" unless File.exist?( filename) + raise ArgumentError, "File not found: #{@file}" unless File.exist?(filename) # # Read the configuration file. # - out = File.open( filename, 'r') {|file| file.readlines.collect} + out = File.open(filename, 'r') {|file| file.readlines.collect} # # Parse it # - parse_lines( out ) + parse_lines(out) end diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb index 7f4b997..add4a87 100644 --- a/lib/custodian/protocoltest/dns.rb +++ b/lib/custodian/protocoltest/dns.rb @@ -37,7 +37,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -64,15 +64,15 @@ 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 # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] end @@ -106,7 +106,7 @@ module Custodian # # Do the lookup # - results = resolve_via( @host, resolve_type, resolve_name, period ) + results = resolve_via(@host, resolve_type, resolve_name, period) return false if results.nil? # @@ -126,12 +126,12 @@ module Custodian # # Resolve an IP # - def resolve_via( server, ltype, name, period ) + def resolve_via(server, ltype, name, period) results = [] begin - timeout( period ) do + timeout(period) do begin # @@ -147,16 +147,16 @@ module Custodian case ltype when /^A$/ then - dns.getresources(name, Resolv::DNS::Resource::IN::A).map{ |r| results.push( r.address.to_s ) } + dns.getresources(name, Resolv::DNS::Resource::IN::A).map{ |r| results.push(r.address.to_s) } when /^AAAA$/ then - dns.getresources(name, Resolv::DNS::Resource::IN::AAAA).map{ |r| results.push( r.address.to_s ) } + dns.getresources(name, Resolv::DNS::Resource::IN::AAAA).map{ |r| results.push(r.address.to_s) } when /^NS$/ then - dns.getresources(name, Resolv::DNS::Resource::IN::NS).map{ |r| results.push( Resolv.getaddresses( r.name.to_s ) ) } + dns.getresources(name, Resolv::DNS::Resource::IN::NS).map{ |r| results.push(Resolv.getaddresses(r.name.to_s)) } when /^MX$/ then - dns.getresources(name, Resolv::DNS::Resource::IN::MX).map{ |r| results.push( Resolv.getaddresses( r.exchange.to_s ) ) } + dns.getresources(name, Resolv::DNS::Resource::IN::MX).map{ |r| results.push(Resolv.getaddresses(r.exchange.to_s)) } else @error = "Unknown record type to resolve: '#{ltype}'" diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb index d307470..6d55260 100644 --- a/lib/custodian/protocoltest/dnsbl.rb +++ b/lib/custodian/protocoltest/dnsbl.rb @@ -24,14 +24,14 @@ module Custodian # # Save away state from the configuration line. # - def initialize( line ) + def initialize(line) @line = line - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # 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. @@ -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. @@ -85,9 +85,9 @@ module Custodian name = "#{$4}.#{$3}.#{$2}.#{$1}.#{zone}" - result = Custodian::Util::DNS.hostname_to_ip( name ) + result = Custodian::Util::DNS.hostname_to_ip(name) - if ( !result.nil? ) && ( result.length > 0 ) + if (!result.nil?) && (result.length > 0) @error = "IP #{@host} listed in blacklist #{zone}. Lookup of #{name} lead to result: #{result}" return true end diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb index 921de62..ddefe45 100644 --- a/lib/custodian/protocoltest/ftp.rb +++ b/lib/custodian/protocoltest/ftp.rb @@ -21,7 +21,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -31,7 +31,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] if @host =~ /^ftp:\/\/([^\/]+)\/?/ @host = $1.dup end @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /^220/, true ) + run_test_internal(@host, @port, /^220/, true) end diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 6ed3c5b..7bbc3e2 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -38,7 +38,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -48,7 +48,7 @@ module Custodian # # Save the URL # - @url = line.split( /\s+/)[0] + @url = line.split(/\s+/)[0] @host = @url # @@ -90,8 +90,8 @@ module Custodian # # Get the schema of the URL # - u = URI.parse( @url ) - if ( u.scheme != test_type ) + u = URI.parse(@url) + if (u.scheme != test_type) raise ArgumentError, "The test case has a different protocol in the URI than that which we're testing: #{@line} - \"#{test_type} != #{u.scheme}\"" end @@ -222,7 +222,7 @@ module Custodian # running with cache-busting. # if @cache_busting - u = URI.parse( test_url ) + u = URI.parse(test_url) if ! u.query u.query = "ctime=#{Time.now.to_i}" test_url = u.to_s @@ -268,7 +268,7 @@ module Custodian protocol_msg = (resolve_mode == :ipv4 ? 'IPv4' : 'IPv6') begin - timeout( period ) do + timeout(period) do c.perform status = c.response_code content = c.body_str diff --git a/lib/custodian/protocoltest/imap.rb b/lib/custodian/protocoltest/imap.rb index fb80305..3512cd5 100644 --- a/lib/custodian/protocoltest/imap.rb +++ b/lib/custodian/protocoltest/imap.rb @@ -22,7 +22,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /OK/i, true ) + run_test_internal(@host, @port, /OK/i, true) end diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb index 916f15f..ba94499 100644 --- a/lib/custodian/protocoltest/jabber.rb +++ b/lib/custodian/protocoltest/jabber.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -74,7 +74,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, nil, false ) + run_test_internal(@host, @port, nil, false) end diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb index a5f6605..ed75ae7 100644 --- a/lib/custodian/protocoltest/ldap.rb +++ b/lib/custodian/protocoltest/ldap.rb @@ -21,7 +21,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line. @@ -31,7 +31,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # The username/password @@ -101,7 +101,7 @@ module Custodian begin # Connect. - ldap = LDAP::Conn.new( @host, @port ) + ldap = LDAP::Conn.new(@host, @port) ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) # Hardwired search is bad.. @@ -111,7 +111,7 @@ module Custodian attrs = ['sn', 'cn'] # Bind. - ldap.bind( @ldap_user, @ldap_pass ) + ldap.bind(@ldap_user, @ldap_pass) if ldap.bound? # diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb index 61e838c..a9cac62 100644 --- a/lib/custodian/protocoltest/mx.rb +++ b/lib/custodian/protocoltest/mx.rb @@ -20,7 +20,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # Save the line away @line = line @@ -69,11 +69,11 @@ module Custodian # Lookup the MX record # begin - timeout( period ) do + timeout(period) do Resolv::DNS.open do |dns| ress = dns.getresources(@host, Resolv::DNS::Resource::IN::MX) - ress.map { |r| mx.push( IPSocket.getaddress(r.exchange.to_s) ) } + ress.map { |r| mx.push(IPSocket.getaddress(r.exchange.to_s)) } end end rescue Timeout::Error => e @@ -110,7 +110,7 @@ module Custodian begin timeout(period) do begin - socket = TCPSocket.new( backend, 25 ) + socket = TCPSocket.new(backend, 25) read = socket.sysread(1024) # trim to a sane length & strip newlines. diff --git a/lib/custodian/protocoltest/mysql.rb b/lib/custodian/protocoltest/mysql.rb index 7abc28f..ce63639 100644 --- a/lib/custodian/protocoltest/mysql.rb +++ b/lib/custodian/protocoltest/mysql.rb @@ -22,7 +22,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port ) + run_test_internal(@host, @port) end diff --git a/lib/custodian/protocoltest/named.rb b/lib/custodian/protocoltest/named.rb index 4c1b134..321c9d5 100644 --- a/lib/custodian/protocoltest/named.rb +++ b/lib/custodian/protocoltest/named.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -74,7 +74,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, nil, false ) + run_test_internal(@host, @port, nil, false) end diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb index 04fe833..4beaaca 100644 --- a/lib/custodian/protocoltest/openproxy.rb +++ b/lib/custodian/protocoltest/openproxy.rb @@ -29,7 +29,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -39,7 +39,7 @@ module Custodian # # Save the target # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -84,7 +84,7 @@ module Custodian period = settings.timeout begin - timeout( period ) do + timeout(period) do begin c = Curl::Easy.new c.follow_location = true @@ -121,7 +121,7 @@ module Custodian # A this point we've either had an exception, or we've # got a result. # - if ( @status.to_i == 200 ) + if (@status.to_i == 200) return true else @error = "Proxy fetch of http://google.com/ via #{@host} failed" diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb index 7d3d802..c2c9a04 100644 --- a/lib/custodian/protocoltest/ping.rb +++ b/lib/custodian/protocoltest/ping.rb @@ -26,7 +26,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -36,7 +36,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -71,7 +71,7 @@ module Custodian # binary = nil binary = './bin/multi-ping' - binary = '/usr/bin/multi-ping' if File.exist?( '/usr/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'" @@ -108,9 +108,9 @@ module Custodian # Does the name look like an IP? # begin - x = IPAddr.new( @host ) + x = IPAddr.new(@host) if x.ipv4? or x.ipv6? - ips.push( @host ) + ips.push(@host) end rescue ArgumentError end @@ -137,16 +137,16 @@ module Custodian # look it up, as both IPv4 and IPv6. # begin - timeout( period ) do + timeout(period) do Resolv::DNS.open do |dns| if do_ipv4 ress = dns.getresources(@host, Resolv::DNS::Resource::IN::A) - ress.map { |r| ips.push( r.address.to_s ) } + ress.map { |r| ips.push(r.address.to_s) } end if do_ipv6 ress = dns.getresources(@host, Resolv::DNS::Resource::IN::AAAA) - ress.map { |r| ips.push( r.address.to_s ) } + ress.map { |r| ips.push(r.address.to_s) } end end end @@ -171,7 +171,7 @@ module Custodian # were given. # ips.each do |ip| - if ( system( binary, ip ) != true ) + if (system(binary, ip) != true) @error = "Ping failed for #{ip} - from #{@host} " return false end diff --git a/lib/custodian/protocoltest/pop3.rb b/lib/custodian/protocoltest/pop3.rb index 3be34b3..eeb1e60 100644 --- a/lib/custodian/protocoltest/pop3.rb +++ b/lib/custodian/protocoltest/pop3.rb @@ -22,7 +22,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /\+OK/i, true ) + run_test_internal(@host, @port, /\+OK/i, true) end diff --git a/lib/custodian/protocoltest/postgresql.rb b/lib/custodian/protocoltest/postgresql.rb index 2dad5cd..f97776c 100644 --- a/lib/custodian/protocoltest/postgresql.rb +++ b/lib/custodian/protocoltest/postgresql.rb @@ -22,7 +22,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port ) + run_test_internal(@host, @port) end diff --git a/lib/custodian/protocoltest/redis.rb b/lib/custodian/protocoltest/redis.rb index d1815aa..1293cc9 100644 --- a/lib/custodian/protocoltest/redis.rb +++ b/lib/custodian/protocoltest/redis.rb @@ -22,7 +22,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -76,7 +76,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port ) + run_test_internal(@host, @port) end diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb index 0f3c288..89f4e65 100644 --- a/lib/custodian/protocoltest/rsync.rb +++ b/lib/custodian/protocoltest/rsync.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line. @@ -32,7 +32,7 @@ module Custodian # # If the target is an URL then strip to the hostname. # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] if @host =~ /^rsync:\/\/([^\/]+)\/?/ @host = $1.dup end @@ -78,7 +78,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /^@RSYNCD/, true ) + run_test_internal(@host, @port, /^@RSYNCD/, true) end diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb index 6a8cd65..b27901d 100644 --- a/lib/custodian/protocoltest/smtp.rb +++ b/lib/custodian/protocoltest/smtp.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line. @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -74,7 +74,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /^220/, true ) + run_test_internal(@host, @port, /^220/, true) end diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb index ef07f82..0a98a9d 100644 --- a/lib/custodian/protocoltest/smtprelay.rb +++ b/lib/custodian/protocoltest/smtprelay.rb @@ -24,9 +24,9 @@ module Custodian # # Save away state from the configuration line. # - def initialize( line ) + def initialize(line) @line = line - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Save the port @@ -63,8 +63,8 @@ module Custodian def get_hostname 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 @@ -86,7 +86,7 @@ module Custodian begin - Net::SMTP.start(@host,@port, get_hostname ) do |smtp| + Net::SMTP.start(@host,@port, get_hostname) do |smtp| sent = smtp.send_message message, 'noreply@bytemark.co.uk', 'noreply@bytemark.co.uk' @status = sent.status.to_s diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb index 3d5e9fb..324f87d 100644 --- a/lib/custodian/protocoltest/ssh.rb +++ b/lib/custodian/protocoltest/ssh.rb @@ -23,7 +23,7 @@ module Custodian # # Ensure we received a port to run the test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -33,7 +33,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # @@ -77,7 +77,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, /SSH/i, true ) + run_test_internal(@host, @port, /SSH/i, true) end diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb index 39a962d..dc62a77 100644 --- a/lib/custodian/protocoltest/ssl.rb +++ b/lib/custodian/protocoltest/ssl.rb @@ -18,7 +18,7 @@ class SSLCheck attr_reader :errors # This is a helper for console-debugging. - def verbose( msg ) + def verbose(msg) (msg) end @@ -350,7 +350,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line @@ -360,7 +360,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] end @@ -404,7 +404,7 @@ module Custodian # If outside 10AM-5PM we don't run the test. # if hour < 10 || hour > 17 - puts( "Outside office hours - Not running SSL-Verification of #{@host}" ) + puts("Outside office hours - Not running SSL-Verification of #{@host}") return true 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 @@ -420,13 +420,13 @@ module Custodian result = s.verify if true == result - puts( "SSL Verification succeeded for #{@host}" ) + puts("SSL Verification succeeded for #{@host}") return true elsif result.nil? - puts( "SSL Verification returned no result (timeout?) #{@host}" ) + puts("SSL Verification returned no result (timeout?) #{@host}") return true else - puts( "SSL Verification for #{@host} has failed." ) + puts("SSL Verification for #{@host} has failed.") @error = "SSL Verification for #{@host} failed: " @error += s.errors.join("\n") return false diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb index ca622bb..0f7e2b5 100644 --- a/lib/custodian/protocoltest/tcp.rb +++ b/lib/custodian/protocoltest/tcp.rb @@ -60,7 +60,7 @@ module Custodian # # Ensure we received a port to run the TCP-test against. # - def initialize( line ) + def initialize(line) # # Save the line @@ -70,7 +70,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -126,7 +126,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - ( run_test_internal( @host, @port, @banner, ( ! @banner.nil? ) ) ) + (run_test_internal(@host, @port, @banner, (! @banner.nil?))) end @@ -148,7 +148,7 @@ module Custodian # # A failure in either version will result in a failure. # - def run_test_internal( host, port, banner = nil, do_read = false ) + def run_test_internal(host, port, banner = nil, do_read = false) # # Get the timeout period. @@ -165,9 +165,9 @@ module Custodian # Does the name look like an IP? # begin - x = IPAddr.new( host ) + x = IPAddr.new(host) if x.ipv4? or x.ipv6? - ips.push( host ) + ips.push(host) end rescue ArgumentError # @@ -197,17 +197,17 @@ module Custodian # look it up, as both IPv4 and IPv6. # begin - timeout( period ) do + timeout(period) do Resolv::DNS.open do |dns| if do_ipv4 ress = dns.getresources(host, Resolv::DNS::Resource::IN::A) - ress.map { |r| ips.push( r.address.to_s ) } + ress.map { |r| ips.push(r.address.to_s) } end if do_ipv6 ress = dns.getresources(host, Resolv::DNS::Resource::IN::AAAA) - ress.map { |r| ips.push( r.address.to_s ) } + ress.map { |r| ips.push(r.address.to_s) } end end end @@ -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 # @@ -260,7 +260,7 @@ module Custodian # This method will ONLY ever be invoked with an IP-address for a # destination. # - def run_test_internal_real( host, port, banner = nil, do_read = false ) + def run_test_internal_real(host, port, banner = nil, do_read = false) # # Get the timeout period for this test. @@ -271,7 +271,7 @@ module Custodian begin timeout(period) do begin - socket = TCPSocket.new( host, port ) + socket = TCPSocket.new(host, port) # read a banner from the remote server, if we're supposed to. read = nil @@ -293,14 +293,14 @@ module Custodian # regexp. if banner.kind_of? Regexp - if ( !read.nil? ) && ( banner.match(read) ) + if (!read.nil?) && (banner.match(read)) return true end end # string. if banner.kind_of? String - if ( !read.nil? ) && ( read =~ /#{banner}/i ) + if (!read.nil?) && (read =~ /#{banner}/i) return true end end diff --git a/lib/custodian/protocoltest/telnet.rb b/lib/custodian/protocoltest/telnet.rb index f485191..a73b35c 100644 --- a/lib/custodian/protocoltest/telnet.rb +++ b/lib/custodian/protocoltest/telnet.rb @@ -22,7 +22,7 @@ module Custodian # # Constructor # - def initialize( line ) + def initialize(line) # # Save the line. @@ -32,7 +32,7 @@ module Custodian # # Save the host # - @host = line.split( /\s+/)[0] + @host = line.split(/\s+/)[0] # # Is this test inverted? @@ -74,7 +74,7 @@ module Custodian # reset the error, in case we were previously executed. @error = nil - run_test_internal( @host, @port, nil, false ) + run_test_internal(@host, @port, nil, false) end diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb index 12db68d..4517c61 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 @@ -81,7 +81,7 @@ end # def initialize host = ENV['QUEUE_ADDRESS'] || '127.0.0.1' - @redis = Redis.new( :host => host ) + @redis = Redis.new(:host => host) end @@ -94,14 +94,14 @@ end def fetch(timeout = 1) job = nil - while( true ) + while(true) - foo, job = @redis.blpop( 'queue', :timeout => timeout ) + foo, job = @redis.blpop('queue', :timeout => timeout) if job return job else - sleep( timeout ) + sleep(timeout) end end @@ -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 @@ -145,7 +145,7 @@ end # def initialize host = ENV['QUEUE_ADDRESS'] || '127.0.0.1' - @queue = Beanstalk::Pool.new( ["#{host}:11300" ] ) + @queue = Beanstalk::Pool.new(["#{host}:11300" ]) end @@ -183,7 +183,7 @@ end # def size? stats = @queue.stats - ( stats['current-jobs-ready'] || 0 ) + (stats['current-jobs-ready'] || 0) end @@ -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 c4b11cb..5635ef3 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 = {} @@ -43,12 +43,12 @@ module Custodian # # The global configuration file. # - return unless( File.exist?( file ) ) + return unless(File.exist?(file)) # # 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 @@ -66,7 +66,7 @@ module Custodian # # Used by the test-suite. # - def _store( key, val ) + def _store(key, val) @settings[key] = val @parsed = true end @@ -83,8 +83,8 @@ module Custodian # # Retrieve an arbitrary key # - def key( name ) - _load unless( _loaded? ) + def key(name) + _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 @@ -194,8 +194,8 @@ module Custodian # # When the alerter is "redis" the target is the redis-server address. # - def alerter_target( alert ) - _load unless( _loaded? ) + def alerter_target(alert) + _load unless(_loaded?) # @@ -203,7 +203,7 @@ module Custodian # # if we have something setup then use it. if @settings["#{alert}_target"] - return( @settings["#{alert}_target"] ) + return(@settings["#{alert}_target"]) end # otherwise per-test defaults. diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index 7383ca2..b28d30a 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -28,7 +28,7 @@ module Custodian # # The line will be like "target must run tcp|ssh|ftp|smtp .." # - def self.create( line ) + def self.create(line) raise ArgumentError, 'The type of test to create cannot be nil' if line.nil? @@ -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" @@ -59,7 +59,7 @@ module Custodian @@subclasses[test_type].each do |impl| if impl - obj = impl.new( line ) + obj = impl.new(line) # # Get the notification text, which is not specific to the test-type @@ -67,7 +67,7 @@ module Custodian # We do this only after we've instantiated the test. # if line =~ /\s+otherwise\s+'([^']+)'/ - obj.set_notification_text( $1.dup ) + obj.set_notification_text($1.dup) end result.push(obj) @@ -77,7 +77,7 @@ module Custodian end # return the test-types. - return( result ) + return(result) else raise "Failed to instantiate a suitable protocol-test for '#{line}'" @@ -113,7 +113,7 @@ module Custodian # for each handler .. @@subclasses[name].each do |impl| - if ( impl == self.class ) + if (impl == self.class) return name end end @@ -145,7 +145,7 @@ module Custodian # # Set the user-text which is returned on error. # - def set_notification_text( str ) + def set_notification_text(str) @notification_text = str end diff --git a/lib/custodian/util/bytemark.rb b/lib/custodian/util/bytemark.rb index 07e5684..db3304d 100644 --- a/lib/custodian/util/bytemark.rb +++ b/lib/custodian/util/bytemark.rb @@ -26,7 +26,7 @@ module Custodian # # Is the named target inside the Bytemark IP-range? # - def self.inside?( target ) + def self.inside?(target) inside = false if BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(target))} diff --git a/lib/custodian/util/dns.rb b/lib/custodian/util/dns.rb index 2a0c705..b93fef5 100644 --- a/lib/custodian/util/dns.rb +++ b/lib/custodian/util/dns.rb @@ -20,7 +20,7 @@ module Custodian # # Return the reverse DNS for the specified IP address, nil on failure. # - def DNS.ip_to_hostname( ip ) + def DNS.ip_to_hostname(ip) resolved = nil # @@ -30,9 +30,9 @@ module Custodian period = settings.timeout begin - timeout( period ) do + timeout(period) do begin - resolved = Socket.getnameinfo(Socket.sockaddr_in(80, ip) ).first + resolved = Socket.getnameinfo(Socket.sockaddr_in(80, ip)).first rescue SocketError resolved = nil end @@ -47,7 +47,7 @@ module Custodian # # Convert a hostname to an IP address, return nil on failure. # - def DNS.hostname_to_ip( hostname ) + def DNS.hostname_to_ip(hostname) resolved = nil @@ -58,7 +58,7 @@ module Custodian period = settings.timeout begin - timeout( period ) do + timeout(period) do begin Socket.getaddrinfo(hostname, 'echo').each do |a| resolved = a[3] if a diff --git a/lib/custodian/util/ping.rb b/lib/custodian/util/ping.rb index cf79754..f8b7c75 100644 --- a/lib/custodian/util/ping.rb +++ b/lib/custodian/util/ping.rb @@ -24,13 +24,13 @@ module Custodian # # Save the hostname away, resolve it if possible. # - def initialize( hostname ) + 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 be a String' unless hostname.kind_of?(String) @hostname = hostname - @resolved = Custodian::Util::DNS.hostname_to_ip( hostname ) + @resolved = Custodian::Util::DNS.hostname_to_ip(hostname) end @@ -47,7 +47,7 @@ module Custodian # Does the hostname resolve to an IPv4 address? # def is_ipv4? - if ( ! @resolved.nil? ) && ( @resolved =~ /^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/ ) + if (! @resolved.nil?) && (@resolved =~ /^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/) true else false @@ -59,7 +59,7 @@ module Custodian # Does the hostname resolve to an IPv6 address? # def is_ipv6? - if ( ! @resolved.nil? ) && ( @resolved =~ /^([a-f0-9:]+)$/i ) + if (! @resolved.nil?) && (@resolved =~ /^([a-f0-9:]+)$/i) true else false @@ -75,11 +75,11 @@ module Custodian # def run_ping if is_ipv6? - if ( system( "ping6 -c 1 #{@resolved} 2>/dev/null >/dev/null" ) == true ) + if (system("ping6 -c 1 #{@resolved} 2>/dev/null >/dev/null") == true) return true end - elsif( is_ipv4? ) - if ( system( "ping -c 1 #{@resolved} 2>/dev/null >/dev/null" ) == true ) + elsif(is_ipv4?) + if (system("ping -c 1 #{@resolved} 2>/dev/null >/dev/null") == true) return true end else diff --git a/lib/custodian/util/timespan.rb b/lib/custodian/util/timespan.rb index a033675..9b79867 100644 --- a/lib/custodian/util/timespan.rb +++ b/lib/custodian/util/timespan.rb @@ -12,13 +12,13 @@ module Custodian # # Convert an hour-string into a sane integer. # - def TimeSpan.to_hour( desc ) + def TimeSpan.to_hour(desc) # # Handle PM times. # - if ( desc.kind_of? String ) && - ( desc =~ /([0-9]+)pm$/i ) + if (desc.kind_of? String) && + (desc =~ /([0-9]+)pm$/i) desc = $1.dup.to_i + 12 end @@ -26,15 +26,15 @@ module Custodian # Handle AM times. # if desc.kind_of? String - desc = desc.sub( /am$/, '' ) + desc = desc.sub(/am$/, '') desc = desc.to_i end # # 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)) # @@ -51,7 +51,7 @@ module Custodian # to a hash of hours which are inside the # range - inclusively. # - def TimeSpan.to_hours( p_start, p_end ) + def TimeSpan.to_hours(p_start, p_end) p_start = Custodian::Util::TimeSpan.to_hour(p_start) p_end = Custodian::Util::TimeSpan.to_hour(p_end) @@ -67,7 +67,7 @@ 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 @@ -87,7 +87,7 @@ module Custodian # Given a starting hour, such as 10pm, and an ending hour, # such as 4am, test whether a time is within that period. # - def TimeSpan.inside?( p_start, p_end, cur_hour = nil) + def TimeSpan.inside?(p_start, p_end, cur_hour = nil) # # Default to the current hour, if not specified. @@ -107,13 +107,13 @@ module Custodian # Get the expanded hours # valid = - Custodian::Util::TimeSpan.to_hours( p_start, p_end ) + Custodian::Util::TimeSpan.to_hours(p_start, p_end) # # Lookup to see if the specified hour is within the # hours between the range. # - ( valid[cur_hour] == 1 ) + (valid[cur_hour] == 1) end end diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb index e5df5e5..746416f 100644 --- a/lib/custodian/worker.rb +++ b/lib/custodian/worker.rb @@ -67,13 +67,13 @@ module Custodian # # Connect to the queue, and record interesting settings away. # - def initialize( settings ) + def initialize(settings) # Save the settings @settings = settings # Connect to the queue - @queue = QueueType.create( @settings.queue_type ) + @queue = QueueType.create(@settings.queue_type) # Get the alerter-type(s) to instantiate @alerter = @settings.alerter @@ -92,7 +92,7 @@ module Custodian # # Show a message on STDOUT if "--verbose" was specified. # - def log_message( msg ) + def log_message(msg) puts msg if ENV['VERBOSE' ] end @@ -103,8 +103,8 @@ module Custodian # Process jobs from the queue - never return. # def run! - while( true ) - log_message( 'Waiting for job..' ) + while(true) + log_message('Waiting for job..') process_single_job end end @@ -131,8 +131,8 @@ module Custodian # # Create test-objects from our class-factory, and process them. # - Custodian::TestFactory.create( job ).each do |test| - process_single_test( test ) + Custodian::TestFactory.create(job).each do |test| + process_single_test(test) end end @@ -144,11 +144,11 @@ module Custodian # # Any test which fails for N-times in a row will raise an alert. # - def process_single_test( test ) + def process_single_test(test) begin - log_message( "Acquired job: #{test}" ) + log_message("Acquired job: #{test}") # # The count of times this test has run, the result, and the start-time @@ -162,9 +162,9 @@ module Custodian # # We exit here if we receive a single success. # - while ( count < ( @retry_count + 1 ) ) && ( result == false ) + while (count < (@retry_count + 1)) && (result == false) - log_message( "Running test - [#{count}/#{@retry_count}]" ) + log_message("Running test - [#{count}/#{@retry_count}]") # # Run the test - inverting the result if we should @@ -173,8 +173,8 @@ module Custodian result = ! result if test.inverted if result - log_message( 'Test succeeed - clearing alert' ) - do_clear( test ) + log_message('Test succeeed - clearing alert') + do_clear(test) end # @@ -186,9 +186,9 @@ module Custodian # The intention here is that if the test passes then there will # be no delay. If the test fails then we'll sleep. # - if ( result == false ) && ( @retry_delay > 0 ) && ( count < @retry_count ) - log_message( "Sleeping for #{@retry_delay} seconds to allow cool-down" ) - sleep( @retry_delay ) + if (result == false) && (@retry_delay > 0) && (count < @retry_count) + log_message("Sleeping for #{@retry_delay} seconds to allow cool-down") + sleep(@retry_delay) end # @@ -205,14 +205,14 @@ module Custodian # # Duration of the test-run, in milliseconds # - duration = (( end_time - start_time ) * 1000.0).to_i + duration = ((end_time - start_time) * 1000.0).to_i # # Record that, if we have any alerters that are interested # in run-times. # - do_duration( test, duration ) + do_duration(test, duration) # @@ -223,12 +223,12 @@ module Custodian # # Raise the alert, passing the error message. # - log_message( "Test failed - alerting with #{test.error}" ) - do_raise( test ) + log_message("Test failed - alerting with #{test.error}") + do_raise(test) end rescue => ex - log_message( "Exception raised processing job: #{ex}" ) + log_message("Exception raised processing job: #{ex}") end @@ -239,18 +239,18 @@ module Custodian # # Raise an alert, with each registered alerter. # - def do_raise( test ) - @alerter.split( ',' ).each do |alerter| + def do_raise(test) + @alerter.split(',').each do |alerter| - log_message( "Creating alerter: #{alerter}" ) - alert = Custodian::AlertFactory.create( alerter, test ) + log_message("Creating alerter: #{alerter}") + alert = Custodian::AlertFactory.create(alerter, test) - target = @settings.alerter_target( alerter ) - alert.set_target( target ) + target = @settings.alerter_target(alerter) + alert.set_target(target) log_message("Target for alert is #{target}") # give the alerter a reference to the settings object. - alert.set_settings( @settings ) + alert.set_settings(@settings) alert.raise end @@ -260,17 +260,17 @@ module Custodian # # Clear an alert, with each registered alerter. # - def do_clear( test ) - @alerter.split( ',' ).each do |alerter| - log_message( "Creating alerter: #{alerter}" ) - alert = Custodian::AlertFactory.create( alerter, test ) + def do_clear(test) + @alerter.split(',').each do |alerter| + log_message("Creating alerter: #{alerter}") + alert = Custodian::AlertFactory.create(alerter, test) - target = @settings.alerter_target( alerter ) - alert.set_target( target ) - log_message( "Target for alert is #{target}" ) + target = @settings.alerter_target(alerter) + alert.set_target(target) + log_message("Target for alert is #{target}") # give the alerter a reference to the settings object. - alert.set_settings( @settings ) + alert.set_settings(@settings) alert.clear end @@ -279,19 +279,19 @@ module Custodian # # Log the test duration with each registered alerter. # - def do_duration( test, duration ) - @alerter.split( ',' ).each do |alerter| - log_message( "Creating alerter: #{alerter}" ) - alert = Custodian::AlertFactory.create( alerter, test ) + def do_duration(test, duration) + @alerter.split(',').each do |alerter| + log_message("Creating alerter: #{alerter}") + alert = Custodian::AlertFactory.create(alerter, test) - target = @settings.alerter_target( alerter ) - alert.set_target( target ) - log_message( "Target for alert is #{target}" ) + target = @settings.alerter_target(alerter) + alert.set_target(target) + log_message("Target for alert is #{target}") # give the alerter a reference to the settings object. - alert.set_settings( @settings ) + alert.set_settings(@settings) - alert.duration( duration ) if alert.respond_to? 'duration' + alert.duration(duration) if alert.respond_to? 'duration' end end @@ -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 -- cgit v1.2.1