Вот мой код:
#!/usr/bin/env ruby
require 'net/ping'
require 'net/smtp'
# check if host is up
def up?(host)
check = Net::Ping::External.new(host)
check.ping?
end
# list of switches to check
switch_list = [
['A ', '192.168.1.1'],
['B ', '192.168.1.2'],
['C ', '192.168.1.3']
]
failed_switches =[]
switch_list.each do |switch, ip|
puts "#{switch}" + up?(ip).to_s
failed_switches << [switch, ip] unless up?(ip)
end
failed_switches.each do |ip| unless failed_switches.empty?
puts "#{failed_switches}" + up?(ip).to_s + "\n"
end
#email the list of checked and failed swithces
message = <<MESSAGE_END
From: abc@gmail.com
To: xyz@gmail.com
Subject: device down!
checked devices:
#{switch_list.map { |switches, ips| 'Device:' + switch + 'IP:' + ip }.join("\n") }
failed devices:
#{failed_switches.map { |switches, ips| 'Device:' + switch + 'IP:' + ip }.join("\n") }
MESSAGE_END
puts "#{message}"
next unless failed_switches.empty?
Net::SMTP.start('your mail server') do |smtp|
smtp.send_message message, 'xyz@gmail.com'
end
end
ОШИБКИ:
Inconsistent indentation detected:
message = <<MESSAGE_END
Unused block argument - line 36 line 39
**|switches**, **ips|**
Inconsistent indentation detected: line 44
next unless failed_switches.empty?
Inconsistent indentation detected: line 45
Net::SMTP.start('your mail server') do |smtp|
Может кто-нибудь помочь мне исправить эти ошибки?