diff --git a/bin/malpd b/bin/malpd index ae9024a..53ab682 100755 --- a/bin/malpd +++ b/bin/malpd @@ -166,6 +166,52 @@ def read_virtual_machines end end +def read_server_info + info = { "type" => "server" } + + if File.exist?("/etc/os-release") + File.readlines("/etc/os-release").each do |line| + if line =~ /^PRETTY_NAME="(.+)"$/ + info["os_name"] = $1 + break + end + end + end + + out = `stat -c %W / 2>/dev/null`.strip + if out =~ /^\d+$/ && out.to_i > 0 + info["install_date"] = Time.at(out.to_i).strftime("%Y-%m-%d") + elsif File.exist?("/etc/machine-id") + info["install_date"] = File.mtime("/etc/machine-id").strftime("%Y-%m-%d") + end + + if File.exist?("/proc/cpuinfo") + cpuinfo = File.read("/proc/cpuinfo") + if cpuinfo =~ /^model name\s*:\s*(.+)$/ + info["cpu_model"] = $1.strip + end + cores = cpuinfo.scan(/^processor\s*:/).size + info["cpu_cores"] = cores if cores > 0 + end + + if File.exist?("/proc/meminfo") + mem = {} + File.read("/proc/meminfo").each_line do |line| + if line =~ /^(\w+):\s+(\d+)/ + mem[$1] = $2.to_i * 1024 + end + end + if (total = mem["MemTotal"]) + available = mem["MemAvailable"] || + (mem["MemFree"].to_i + mem["Buffers"].to_i + mem["Cached"].to_i) + info["mem_total"] = total + info["mem_used"] = total - available + end + end + + info +end + def read_ups out = `apcaccess 2>/dev/null` return nil unless $?.success? && !out.empty? @@ -232,6 +278,8 @@ def handle_info(conn) info.concat(read_filesystems) info.concat(read_virtual_machines) + info << read_server_info + if (ups = read_ups) info << ups end diff --git a/cgi-bin/malp.rb b/cgi-bin/malp.rb index bb21251..52728b0 100755 --- a/cgi-bin/malp.rb +++ b/cgi-bin/malp.rb @@ -112,9 +112,67 @@ if cgi.params.key?("content") drives = info.select { |e| e["type"] == "drive" } filesystems = info.select { |e| e["type"] == "filesystem" } vms = info.select { |e| e["type"] == "vm" } + server = info.find { |e| e["type"] == "server" } html << %(