informo 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +644 -0
- data/README.md +31 -0
- data/Rakefile +8 -0
- data/informo.gemspec +12 -0
- data/lib/informo.rb +31 -0
- data/lib/informo/bios.rb +30 -0
- data/lib/informo/dpkg.rb +81 -0
- data/lib/informo/memory.rb +77 -0
- data/lib/informo/network.rb +73 -0
- data/lib/informo/processor.rb +45 -0
- data/lib/informo/rpm.rb +85 -0
- data/lib/informo/storage.rb +88 -0
- data/lib/informo/system.rb +50 -0
- data/lib/informo/version.rb +5 -0
- data/test/test_bios.rb +27 -0
- data/test/test_dpkg.rb +70 -0
- data/test/test_memory.rb +32 -0
- data/test/test_network.rb +25 -0
- data/test/test_processor.rb +18 -0
- data/test/test_rpm.rb +70 -0
- data/test/test_storage.rb +28 -0
- data/test/test_system.rb +37 -0
- metadata +64 -0
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Informo
|
2
|
+
|
3
|
+
A ruby gem for retrieving info from linux systems.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
clone this repo
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem build informo.gemspec
|
11
|
+
$ gem install informo-1.0.gem
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```
|
17
|
+
require 'informo'
|
18
|
+
```
|
19
|
+
|
20
|
+
The following top level classes exist:
|
21
|
+
|
22
|
+
- Informo::Bios
|
23
|
+
- Informo::Dpkg
|
24
|
+
- Informo::Memory
|
25
|
+
- Informo::Network
|
26
|
+
- Informo::Processor
|
27
|
+
- Informo::Rpm
|
28
|
+
- Informo::Storage
|
29
|
+
- Informo::System
|
30
|
+
|
31
|
+
|
data/Rakefile
ADDED
data/informo.gemspec
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'informo/version'
|
3
|
+
|
4
|
+
Gem::Specification.new 'informo', Informo::VERSION do |s|
|
5
|
+
s.date = '2013-05-03'
|
6
|
+
s.summary = 'Linux info wrapped in a gem'
|
7
|
+
s.description = 'Informo is used to gather information from your linux system'
|
8
|
+
s.files = `git ls-files`.split("\n") - %w[]
|
9
|
+
s.author = 'Rick Briganti'
|
10
|
+
s.email = 'jeviolle@newaliases.org'
|
11
|
+
s.homepage = 'http://github.com/jeviolle/informo'
|
12
|
+
end
|
data/lib/informo.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'informo/bios.rb'
|
2
|
+
require 'informo/dpkg.rb'
|
3
|
+
require 'informo/memory.rb'
|
4
|
+
require 'informo/network.rb'
|
5
|
+
require 'informo/processor.rb'
|
6
|
+
require 'informo/rpm.rb'
|
7
|
+
require 'informo/storage.rb'
|
8
|
+
require 'informo/system.rb'
|
9
|
+
require 'informo/version.rb'
|
10
|
+
|
11
|
+
##
|
12
|
+
# Informo make's it easy to get system information
|
13
|
+
# for Linux systems from inside ruby scripts. Currently it is
|
14
|
+
# a glorified wrapper around existing native commands and
|
15
|
+
# tries to avoid reinventing wheels that already exist inside
|
16
|
+
# GNU/Linux.
|
17
|
+
#
|
18
|
+
# The following classes are available:
|
19
|
+
#
|
20
|
+
# - Informo::Bios
|
21
|
+
# - Informo::Dpkg
|
22
|
+
# - Informo::Memory
|
23
|
+
# - Informo::Network
|
24
|
+
# - Informo::Processor
|
25
|
+
# - Informo::Rpm
|
26
|
+
# - Informo::Storage
|
27
|
+
# - Informo::System
|
28
|
+
#
|
29
|
+
module Informo
|
30
|
+
|
31
|
+
end
|
data/lib/informo/bios.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Informo
|
2
|
+
##
|
3
|
+
# Allows for the retrieval of bios related information.
|
4
|
+
class Bios
|
5
|
+
##
|
6
|
+
# returns the serial number as a string
|
7
|
+
def serial
|
8
|
+
serial = `dmidecode -s system-serial-number`.chomp
|
9
|
+
return serial
|
10
|
+
end
|
11
|
+
##
|
12
|
+
# returns the bios vendor as a string
|
13
|
+
def vendor
|
14
|
+
vendor = `dmidecode -s system-product-name`.chomp
|
15
|
+
return vendor
|
16
|
+
end
|
17
|
+
##
|
18
|
+
# returns the bios version as a string
|
19
|
+
def version
|
20
|
+
version = `dmidecode -s bios-version`.chomp
|
21
|
+
return version
|
22
|
+
end
|
23
|
+
##
|
24
|
+
# returns the release date of the installed bios version as a string
|
25
|
+
def date
|
26
|
+
date = `dmidecode -s bios-release-date`.chomp
|
27
|
+
return date
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/informo/dpkg.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Informo
|
4
|
+
##
|
5
|
+
# This class is used to return information about installed packages
|
6
|
+
# for systems utilizing debian/ubuntu package formats
|
7
|
+
class Dpkg
|
8
|
+
def initialize()
|
9
|
+
@@dpkgquery = "dpkg-query"
|
10
|
+
@@pkginfo = "/var/lib/dpkg/info"
|
11
|
+
end
|
12
|
+
##
|
13
|
+
# returns an array of package names that are/were installed
|
14
|
+
# as show via +dpkg-query+ command
|
15
|
+
def get_packages
|
16
|
+
packages = Array.new
|
17
|
+
packages = `#{@@dpkgquery} -W -f='${Package}\n'`.split("\n")
|
18
|
+
return packages
|
19
|
+
end
|
20
|
+
##
|
21
|
+
# returns the version of the package specified as a string
|
22
|
+
def get_version(name)
|
23
|
+
package_version = `#{@@dpkgquery} -W -f='${Version}' #{name}`
|
24
|
+
return package_version
|
25
|
+
end
|
26
|
+
##
|
27
|
+
# returns the architecture of the package specified as a string
|
28
|
+
def get_architecture(name)
|
29
|
+
package_architecture = `#{@@dpkgquery} -W -f='${Architecture}' #{name}`
|
30
|
+
return package_architecture
|
31
|
+
end
|
32
|
+
##
|
33
|
+
# returns the package maintainer for the given package as a string
|
34
|
+
def get_maintainer(name)
|
35
|
+
package_maintainer = `#{@@dpkgquery} -W -f='${Maintainer}' #{name}`
|
36
|
+
return package_maintainer
|
37
|
+
end
|
38
|
+
##
|
39
|
+
# returns a brief description of a given package as a string
|
40
|
+
def get_short_description(name)
|
41
|
+
package_description = `#{@@dpkgquery} -W -f='${Description}' #{name}`.split("\n")
|
42
|
+
return package_description[0]
|
43
|
+
end
|
44
|
+
##
|
45
|
+
# returns the full, possibly lengthy, description for the specified package as a string
|
46
|
+
def get_description(name)
|
47
|
+
package_description = `#{@@dpkgquery} -W -f='${Description}' #{name}`
|
48
|
+
return package_description
|
49
|
+
end
|
50
|
+
##
|
51
|
+
# returns the status for the package specified as a string
|
52
|
+
def get_status(name)
|
53
|
+
package_status = `#{@@dpkgquery} -W -f='${Status}' #{name}`
|
54
|
+
return package_status
|
55
|
+
end
|
56
|
+
##
|
57
|
+
# returns the installation date of the given package
|
58
|
+
def get_installdate(name)
|
59
|
+
create_time = Time.at(File.stat(@@pkginfo + "/#{name}.list")).ctime.utc
|
60
|
+
return create_time
|
61
|
+
end
|
62
|
+
##
|
63
|
+
# returns the following information for a given package name as a hash
|
64
|
+
#
|
65
|
+
# - version
|
66
|
+
# - architecture
|
67
|
+
# - maintainer
|
68
|
+
# - description
|
69
|
+
# - status
|
70
|
+
def get_all(name)
|
71
|
+
results = `#{@@dpkgquery} -W -f='${Version}|||${Architecture}|||${Maintainer}|||${Description}|||${Status}' #{name}`.split('|||')
|
72
|
+
|
73
|
+
# return results as an array and map
|
74
|
+
hresults = {'name' => name, 'version' => results[0],
|
75
|
+
'architecture' => results[1], 'maintainer' => results[2],
|
76
|
+
'description' => results[3], 'status' => results[4]}
|
77
|
+
|
78
|
+
return hresults
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Informo
|
2
|
+
##
|
3
|
+
# This class is used to return various physical memory related information. For
|
4
|
+
# example: how many modules are installed, module size, etc
|
5
|
+
#
|
6
|
+
# For virtualized systems some of these might not be applicable
|
7
|
+
class Memory
|
8
|
+
##
|
9
|
+
# returns the maximum size for memory modules
|
10
|
+
def max_module_size
|
11
|
+
`dmidecode -t 5`.each_line do |line|
|
12
|
+
if line =~ /Maximum Memory Module Size.+?(\d+)\s+/
|
13
|
+
max_module_size = $1
|
14
|
+
return max_module_size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
##
|
19
|
+
# returns the maximum amount of memory slots.
|
20
|
+
def max_modules
|
21
|
+
`dmidecode -t 5`.each_line do |line|
|
22
|
+
if line =~ /Associated Memory Slots.+?(\d+)\s+/
|
23
|
+
max_modules = $1
|
24
|
+
return max_modules
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
##
|
29
|
+
# returns the maximum amount of memory supported by the bios/system
|
30
|
+
def max_capacity
|
31
|
+
`dmidecode -t 5`.each_line do |line|
|
32
|
+
if line =~ /Maximum Total Memory Size.+?(\d+)\s+/
|
33
|
+
max_capacity = $1
|
34
|
+
return max_capacity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
##
|
39
|
+
# returns the amount of physical memory installed
|
40
|
+
def installed
|
41
|
+
`free -m`.each_line do |line|
|
42
|
+
if line =~ /^Mem.+?(\d+)\s+/
|
43
|
+
installed_memory = $1
|
44
|
+
return installed_memory
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# returns details for memory installed in each memory slot
|
51
|
+
#
|
52
|
+
# - size
|
53
|
+
# - location on board
|
54
|
+
# - speed
|
55
|
+
# - form factor
|
56
|
+
def slots
|
57
|
+
count = -1
|
58
|
+
modules = Array.new
|
59
|
+
|
60
|
+
`dmidecode -t 17`.each_line do |line|
|
61
|
+
if line =~ /\cI(Array Handle|Size|Locator|Speed|Form Factor):\s*(.*)$/
|
62
|
+
key, value = $1, $2
|
63
|
+
if key =~ /Array Handle/
|
64
|
+
count += 1
|
65
|
+
modules[count] = Hash.new
|
66
|
+
else
|
67
|
+
key = "type" if key =~ /Form Factor/
|
68
|
+
modules[count][key.downcase] = value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
return modules
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Informo
|
2
|
+
##
|
3
|
+
# This class is used to provide information about the network configuration of the system
|
4
|
+
# and physical networking hardware available to the system.
|
5
|
+
class Network
|
6
|
+
##
|
7
|
+
# returns an array of available network interfaces
|
8
|
+
def interfaces
|
9
|
+
interfaces = Array.new
|
10
|
+
if File.exists?("/sbin/ip")
|
11
|
+
`ip a`.each_line do |line|
|
12
|
+
interfaces.push($1) if line =~ /scope.+?\s(\w+\d+(:.+?)?)$/
|
13
|
+
end
|
14
|
+
else
|
15
|
+
`ifconfig -a`.each_line do |line|
|
16
|
+
interfaces.push($1) if line =~ /^(\w+\d+(:.+?)?)\s+Link/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
return interfaces
|
21
|
+
end
|
22
|
+
##
|
23
|
+
# returns hash of the following info for a given network interface
|
24
|
+
#
|
25
|
+
# - ip address
|
26
|
+
# - subnet mask
|
27
|
+
# - broadcast address
|
28
|
+
# - mtu
|
29
|
+
def interface_details(dev)
|
30
|
+
details = Hash.new
|
31
|
+
details["ip6"] = Array.new
|
32
|
+
count = -1
|
33
|
+
|
34
|
+
if File.exists?("/sbin/ip")
|
35
|
+
`ip addr show #{dev}`.each_line do |line|
|
36
|
+
details["mtu"] = $1 if line =~ /mtu (\d+)/
|
37
|
+
|
38
|
+
if line =~ /inet\s(\d+\.\d+\.\d+\.\d+)\/(\d+)\s+brd\s(\d+\.\d+\.\d+\.\d+)\sscope.+#{dev}$/
|
39
|
+
details["ipaddr"],details["prefix"],details["broadcast"] = $1, $2, $3
|
40
|
+
end
|
41
|
+
|
42
|
+
if dev != /:/
|
43
|
+
if line =~ /inet6\s(.+?)\/(\d+)\sscope/
|
44
|
+
count += 1
|
45
|
+
details["ip6"][count] = Hash.new
|
46
|
+
details["ip6"][count]["ipaddr"],details["ip6"][count]["prefix"] = $1, $2
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
`ifconfig #{dev}`.each_line do |line|
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
return details
|
56
|
+
end
|
57
|
+
##
|
58
|
+
# returns an array of installed HBAs
|
59
|
+
def host_bus_adapters
|
60
|
+
list = Array.new
|
61
|
+
|
62
|
+
`lspci`.each_line do |line|
|
63
|
+
if line =~ /fib|hba/i
|
64
|
+
|
65
|
+
list.push($1) if line =~ /.+?:\s+(.+)/
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
return list
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Informo
|
2
|
+
##
|
3
|
+
# This class is used to retrieve information about the processors available
|
4
|
+
# to the system.
|
5
|
+
class Processor
|
6
|
+
##
|
7
|
+
# returns the total number of processors on the system
|
8
|
+
def count
|
9
|
+
total = 0
|
10
|
+
File.open("/proc/cpuinfo").each_line do |line|
|
11
|
+
total += 1 if line =~ /^processor/
|
12
|
+
end
|
13
|
+
|
14
|
+
return total
|
15
|
+
end
|
16
|
+
##
|
17
|
+
# returns the details of the processor(s) as an array with the following
|
18
|
+
# information
|
19
|
+
#
|
20
|
+
# - vendor (amd, intel, etc)
|
21
|
+
# - model (xeon, k9, etc)
|
22
|
+
# - speed (2000 Mhz, etc)
|
23
|
+
# - cache size (512k, etc)
|
24
|
+
def details
|
25
|
+
count = -1
|
26
|
+
processors = Array.new
|
27
|
+
|
28
|
+
File.open("/proc/cpuinfo").each_line do |line|
|
29
|
+
|
30
|
+
if line =~ /(processor|vendor_id|model name|cpu MHz|cache size)\s+:\s+(.+)/
|
31
|
+
key, value = $1, $2
|
32
|
+
if key =~ /processor/
|
33
|
+
count += 1
|
34
|
+
processors[count] = Hash.new
|
35
|
+
else
|
36
|
+
key = key.gsub(/\s+/,"_")
|
37
|
+
processors[count][key] = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
return processors
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/informo/rpm.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Informo
|
4
|
+
##
|
5
|
+
# This class is used to get information about installed RPMs
|
6
|
+
class Rpm
|
7
|
+
def initialize()
|
8
|
+
@@rpmquery = "rpm"
|
9
|
+
end
|
10
|
+
##
|
11
|
+
# returns an array of installed package names
|
12
|
+
def get_packages
|
13
|
+
packages = Array.new
|
14
|
+
packages = `#{@@rpmquery} -qa --qf='%{NAME}\n'`.split("\n")
|
15
|
+
return packages
|
16
|
+
end
|
17
|
+
##
|
18
|
+
# returns the version of the given package
|
19
|
+
def get_version(name)
|
20
|
+
package_version = `#{@@rpmquery} -q --qf='%{VERSION}' #{name}`
|
21
|
+
return package_version
|
22
|
+
end
|
23
|
+
##
|
24
|
+
# returns the release of the given package
|
25
|
+
def get_release(name)
|
26
|
+
package_release = `#{@@rpmquery} -q --qf='%{RELEASE}' #{name}`
|
27
|
+
return package_release
|
28
|
+
end
|
29
|
+
##
|
30
|
+
# returns the architecture of the given package
|
31
|
+
def get_architecture(name)
|
32
|
+
package_architecture = `#{@@rpmquery} -q --qf='%{ARCH}' #{name}`
|
33
|
+
return package_architecture
|
34
|
+
end
|
35
|
+
##
|
36
|
+
# returns the maintainer of the given package
|
37
|
+
def get_maintainer(name)
|
38
|
+
package_maintainer = `#{@@rpmquery} -q --qf='%{VENDOR}' #{name}`
|
39
|
+
return package_maintainer
|
40
|
+
end
|
41
|
+
##
|
42
|
+
# returns the +short+ description (ie: rpm summary field) of the given package
|
43
|
+
def get_short_description(name)
|
44
|
+
package_description = `#{@@rpmquery} -q --qf='%{SUMMARY}' #{name}`.split("\n")
|
45
|
+
return package_description[0]
|
46
|
+
end
|
47
|
+
##
|
48
|
+
# returns the +full+ description of the given package
|
49
|
+
def get_description(name)
|
50
|
+
package_description = `#{@@rpmquery} -q --qf='%{DESCRIPTION}' #{name}`
|
51
|
+
return package_description
|
52
|
+
end
|
53
|
+
##
|
54
|
+
# returns the installed date of the given package
|
55
|
+
def get_installdate(name)
|
56
|
+
package_status = Time.at(Time.parse(`#{@@rpmquery} -q --qf='%{INSTALLTIME:date}' #{name}`)).utc
|
57
|
+
return package_status
|
58
|
+
end
|
59
|
+
##
|
60
|
+
# returns the status of the installed package (ie. nothing for RPM), kind of a placeholder I guess...
|
61
|
+
def get_status(name)
|
62
|
+
return
|
63
|
+
end
|
64
|
+
##
|
65
|
+
# returns a hash of details for the given package
|
66
|
+
#
|
67
|
+
# - version
|
68
|
+
# - release
|
69
|
+
# - architecture
|
70
|
+
# - maintainer
|
71
|
+
# - summary
|
72
|
+
# - description
|
73
|
+
# - install date
|
74
|
+
def get_all(name)
|
75
|
+
results = `#{@@rpmquery} -q --queryformat "%{VERSION}|||%{RELEASE}|||%{ARCH}|||%{VENDOR}|||%{SUMMARY}|||%{DESCRIPTION}|||%{INSTALLTIME:date}" #{name}`.split('|||')
|
76
|
+
|
77
|
+
# return results as an array and map
|
78
|
+
hresults = {'name' => name, 'version' => results[0], 'release' => results[1],
|
79
|
+
'architecture' => results[2], 'maintainer' => results[3], 'summary' => results[4],
|
80
|
+
'description' => results[5], 'installdate' => results[6]}
|
81
|
+
|
82
|
+
return hresults
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|