-
-
Save anonymous/a4dac4dffa4b97ddab6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def software | |
@seen_software = Array.new | |
@inventory = Array.new | |
package_filter = Regexp.new(/(.*)\-([\d\.]+)\W([a-z]*.*)/, Regexp::IGNORECASE); | |
sbms = Sbm.where(role: "cloud") | |
sbms.each do |sbm| | |
if sbm.packages | |
software = JSON.parse(sbm.packages) | |
else | |
software = [] | |
end | |
packages = Array.new | |
software.each do |raw| | |
match = package_filter.match(raw) | |
if match | |
@seen_software.push(match[1]) | |
packages.push({"name" => match[1], "version" => match[2], "revision" => match[3]}) | |
end | |
end | |
packages.sort_by!{ |hash| hash[:name].to_s } | |
@inventory.push({"name" => sbm.hostname, "id" => sbm.id, "software" => packages}) | |
end | |
@seen_software.uniq!.sort_by! {|name| name.to_s } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment