class Host
Individual Host
Helper
Public Instance Methods
archive_name()
click to toggle source
def load(file)
@file = file self.files = Archive.load(file) save!
end
# File lib/greenhat/host.rb, line 16 def archive_name File.basename archive end
cpu_speed()
click to toggle source
# File lib/greenhat/host.rb, line 93 def cpu_speed file = find_file 'lscpu' return nil unless file details = file.raw.find { |x| x.include? 'MHz' } details.reverse.split(' ', 2).map(&:reverse).reverse end
cpuinfo()
click to toggle source
# File lib/greenhat/host.rb, line 81 def cpuinfo file = find_file 'cpuinfo' return nil unless file file.raw.join("\n").split("\n\n").map do |cpu| all = cpu.split("\n").map do |row| row.delete("\t").split(': ') end { details: all[1..], order: all[0].last } end end
df_h()
click to toggle source
# File lib/greenhat/host.rb, line 116 def df_h file = find_file 'df_h' return nil unless file file.raw end
find_file(file_name)
click to toggle source
# File lib/greenhat/host.rb, line 20 def find_file(file_name) files.find { |x| x.name == file_name } end
free_m()
click to toggle source
# File lib/greenhat/host.rb, line 109 def free_m file = find_file 'free_m' return nil unless file file.raw end
icon()
click to toggle source
# File lib/greenhat/host.rb, line 24 def icon release_file = find_file files.map(&:name).grep(/_release/).first release = release_file.raw.join if release.include? 'ubuntu' 'fa-ubuntu' elsif release.include? 'suse' 'fa-suse' elsif release.include? 'redhat' 'fa-redhat' elsif release.include? 'centos' 'fa-centos' else 'fa-linux' end end
manifest()
click to toggle source
# File lib/greenhat/host.rb, line 60 def manifest file = find_file 'gitlab_version_manifest_json' return nil unless file Oj.load file.raw.join end
netstat()
click to toggle source
# File lib/greenhat/host.rb, line 123 def netstat file = find_file 'netstat' return nil unless file file.raw end
percent(value, total)
click to toggle source
Helpers
# File lib/greenhat/host.rb, line 45 def percent(value, total) (value.to_i / total.to_f).round(2) * 100 end
processes()
click to toggle source
# File lib/greenhat/host.rb, line 144 def processes file = find_file 'ps' return nil unless file headers = file.raw.first.split(' ', 11) list = file.raw[1..].each.map do |row| row.split(' ', 11).each_with_index.each_with_object({}) do |(v, i), obj| obj[headers[i]] = v end end { headers: headers, list: list } end
systemctl_color(entry)
click to toggle source
# File lib/greenhat/host.rb, line 49 def systemctl_color(entry) case entry.status when 'enabled' then :green when 'static' then :orange when 'disabled' then :red else :grey end end
systemctl_unit_files()
click to toggle source
# File lib/greenhat/host.rb, line 157 def systemctl_unit_files file = find_file 'systemctl_unit_files' return nil unless file all = file.raw[1..-2].map do |x| unit, status = x.split { unit: unit, status: status } end all.reject! { |x| x[:unit].nil? } all.sort_by(&:unit) end
total_memory()
click to toggle source
# File lib/greenhat/host.rb, line 101 def total_memory file = find_file 'free_m' return nil unless file value = file.raw.dig(1, 1).to_i number_to_human_size(value * 1024 * 1024) end
ulimit()
click to toggle source
# File lib/greenhat/host.rb, line 130 def ulimit file = find_file 'ulimit' return nil unless file results = file.raw.map do |entry| { value: entry.split[-1], details: entry.split(' ').first } end results.sort_by { |x| x[:details].downcase } end
uname()
click to toggle source
# File lib/greenhat/host.rb, line 74 def uname file = find_file 'uname' return nil unless file file.raw.join end
uptime()
click to toggle source
# File lib/greenhat/host.rb, line 67 def uptime file = find_file 'uptime' return nil unless file file.raw end