Add package update count and reboot pending to host server info card
This commit is contained in:
1 parent
a21bf2c215
commit
2c0da87fac
2 files changed
+74
-2
No files matched your search
@@ -169,6 +169,49 @@ def read_virtual_machines
|
||||
end
|
||||
end
|
||||
|
||||
def read_os_id
|
||||
return nil unless File.exist?("/etc/os-release")
|
||||
File.readlines("/etc/os-release").each do |line|
|
||||
if line =~ /^ID=(.+)$/
|
||||
return $1.strip.delete('"').downcase
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def apt_updates
|
||||
out = `apt-get -s -o Debug::NoLocking=true upgrade 2>/dev/null`
|
||||
count = 0
|
||||
out.each_line do |line|
|
||||
count += 1 if line.start_with?("Inst ")
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def apt_reboot_pending
|
||||
File.exist?("/var/run/reboot-required")
|
||||
end
|
||||
|
||||
def dnf_updates
|
||||
out = `dnf -q check-update 2>/dev/null`
|
||||
status = $?.exitstatus
|
||||
return 0 if status == 0
|
||||
return nil unless status == 100
|
||||
count = 0
|
||||
out.each_line do |line|
|
||||
line = line.strip
|
||||
next if line.empty?
|
||||
next if line.start_with?("Obsoleting", "Last metadata")
|
||||
count += 1 if line.split(/\s+/).size >= 3
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def dnf_reboot_pending
|
||||
`dnf needs-restarting -r >/dev/null 2>&1`
|
||||
$?.exitstatus == 1
|
||||
end
|
||||
|
||||
def read_server_info
|
||||
info = { "type" => "server" }
|
||||
|
||||
@@ -181,6 +224,15 @@ def read_server_info
|
||||
end
|
||||
end
|
||||
|
||||
case read_os_id
|
||||
when "ubuntu", "debian"
|
||||
info["updates"] = apt_updates
|
||||
info["reboot_pending"] = apt_reboot_pending
|
||||
when "almalinux", "rocky", "rhel", "centos", "fedora"
|
||||
info["updates"] = dnf_updates
|
||||
info["reboot_pending"] = dnf_reboot_pending
|
||||
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")
|
||||
|
||||
Reference in new issue
Block a user