Class: Vijay::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/vijay/inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Inspector

Returns a new instance of Inspector.



8
9
10
11
12
# File 'lib/vijay/inspector.rb', line 8

def initialize(filename)
  config_data = YAML.load_file filename
  list_servers!(config_data["servers"])
  list_files!(config_data["files"])
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/vijay/inspector.rb', line 6

def files
  @files
end

#serversObject (readonly)

Returns the value of attribute servers.



6
7
8
# File 'lib/vijay/inspector.rb', line 6

def servers
  @servers
end

Instance Method Details

#inspect!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vijay/inspector.rb', line 14

def inspect!
  @altered_files = {}
  @start_time = Time.now
  @servers.each do |server|
    altered = []
    Net::SSH.start(server.host, server.user, password: server.password) do |ssh|
      @files.each do |file|
        digest = ssh.exec!("md5sum #{file.name}").split(' ').first
        altered << file.name if file.altered?(digest)
      end
    end
    @altered_files[server.host] = altered unless altered.empty?
  end
  @end_time = Time.now
end

#reportObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vijay/inspector.rb', line 30

def report
  puts "[Vijay] Inspection started at #{@start_time} and finished at #{@end_time}"
  puts "[Vijay] Inspection conducted in #{@servers.count} server(s) for #{@files.count} file(s)"
  if @altered_files.empty?
    puts "[Vijay] No altered files detected"
  else
    puts "[Vijay] Altered files detected!"
  end
  @altered_files.each do |k, v|
    puts "[Vijay] Files altered on host #{k}:"
    v.each do |f|
      puts "[Vijay] - #{f}"
    end
  end
end