Module: DpkgInv

Defined in:
lib/dpkginv/base.rb

Class Method Summary collapse

Class Method Details

.inventoryObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dpkginv/base.rb', line 14

def self.inventory
    o = Ohai::System.new

    # ohai has dozens of plugins; let's only load the ones we need...
    o.require_plugin('linux/lsb')
    o.require_plugin('linux/hostname')
    o.require_plugin('kernel')
    o.require_plugin('dpkg')

    json = {
        :fqdn   =>  o[:fqdn],
        :lsb     =>  {
            :id             =>  o[:lsb][:id],
            :release        =>  o[:lsb][:release],
            :codename       =>  o[:lsb][:codename],
            :description    =>  o[:lsb][:description]
        },
        :kernel =>  {
            :release    =>  o[:kernel][:release],
            :machine    =>  o[:kernel][:machine]
        },
        :dpkg   =>  o[:dpkg],
        :created_at => Time.now.iso8601
    }

    #
    # load system_id from external file,  but it's not required if you
    # just want a JSON representation of your packages.  it can be set by
    # config management, etc.
    #
    config_file = '/etc/dpkginv.conf'
    if File.exists?(config_file)
        config = YAML.load_file(config_file)
        unless config == false || config['system_id'].nil?
            json[:system_id] = config['system_id']
        end
    end

    return json
end

.runObject



10
11
12
# File 'lib/dpkginv/base.rb', line 10

def self.run
    puts JSON.pretty_generate(inventory)
end