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.
@@ -0,0 +1,88 @@
1
+ module Informo
2
+ ##
3
+ # This class is used to get info for the available and configured storage. For
4
+ # example: number of disks, partition info, etc...
5
+ class Storage
6
+ ##
7
+ # returns the total number of disks
8
+ def drive_count
9
+ count = 0
10
+ `fdisk -l 2>/dev/null`.each_line do |line|
11
+ if line =~ /^Disk \/dev\/[^mapper]/
12
+ count += 1
13
+ end
14
+ end
15
+
16
+ return count
17
+ end
18
+ ##
19
+ # returns the details for a given disk
20
+ #
21
+ # - size
22
+ # - model
23
+ # - interface (scsi, sas, ide)
24
+ def drive_details(disk)
25
+ details = Hash.new
26
+
27
+ `fdisk -l #{disk} 2>/dev/null`.each_line do |i|
28
+ details["size"] = $1 if i =~ /^Disk \/\w+\/\w+\:\s+(\d+.+\w+)\,/
29
+ end
30
+
31
+ `hdparm -i #{disk} 2>/dev/null`.each_line do |i|
32
+ details["model"] = $1 if i =~ /Model=(.+?)\,/
33
+ end
34
+
35
+ File.exists?("/sbin/udevadm") ? cmd = "udevadm info" : cmd = "udevinfo"
36
+
37
+ `#{cmd} -q symlink -n #{disk}`.each_line do |i|
38
+ details["interface"] = $1 if i =~ /disk\/by-path\/\w+-\d+:\d+:\d+\.\d+-(\w+)-\d+:\d+/
39
+ end
40
+
41
+ return details
42
+ end
43
+ ##
44
+ # returns an array of disks present
45
+ def drives
46
+ drives = Array.new
47
+ `fdisk -l 2>/dev/null`.each_line do |line|
48
+ if line =~ /^Disk (\/\w+\/\w+)\:/
49
+ drives.push($1)
50
+ end
51
+ end
52
+
53
+ return drives
54
+ end
55
+ ##
56
+ # returns a hash of details for a given mount
57
+ #
58
+ # - device (/dev/sda? etc)
59
+ # - mount (/foo)
60
+ # - fstype (ext4)
61
+ # - options (mount options; eg: ro)
62
+ def mount_details(mountpoint)
63
+ details = Hash.new
64
+ File.open("/proc/mounts").each_line do |line|
65
+ entry = line.split(/\s/)
66
+ if line != /rootfs/ and entry[1] == mountpoint
67
+ details["device"] = entry[0]
68
+ details["mount"] = entry[1]
69
+ details["fstype"] = entry[2]
70
+ details["options"] = entry[3]
71
+ end
72
+ end
73
+
74
+ return details
75
+ end
76
+ ##
77
+ # returns an array of mounts that are mounted
78
+ def mounts(type=".+")
79
+ mounts = Array.new
80
+ File.open("/proc/mounts").each_line do |line|
81
+ mounts.push(line.split(/\s/)[1]) if line != /rootfs/ and line.split(/\s/)[2] =~ /#{type}/
82
+ end
83
+
84
+ return mounts
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,50 @@
1
+ require 'socket'
2
+
3
+ module Informo
4
+ ##
5
+ # This class is used to get some generic information of the
6
+ # host in question; ie: distro name, version, etc
7
+ class System
8
+ ##
9
+ # returns the linux distro
10
+ def distro
11
+ `lsb_release -i`.each_line do |line|
12
+ distro = $1 if line =~ /.+:\s(.+)$/
13
+ return distro
14
+ end
15
+ end
16
+ ##
17
+ # returns the version of the linux distro
18
+ def version
19
+ `lsb_release -r`.each_line do |line|
20
+ version = $1 if line =~ /.+:\s(.+)$/
21
+ return version
22
+ end
23
+ end
24
+ ##
25
+ # returns a boolean for wether or not numa is being used
26
+ def numa?
27
+ enabled = system("numactl","-s") ? true : false
28
+ return enabled
29
+ end
30
+ ##
31
+ # returns the running kernel version
32
+ def kernel
33
+ File.open("/proc/version").each_line do |line|
34
+ kernel = $1 if line =~ /version (.+?) /
35
+ return kernel
36
+ end
37
+ end
38
+ ##
39
+ # returns the architecture of the system (i386, x86_64, etc)
40
+ def arch
41
+ arch = `uname -m`.chomp
42
+ return arch
43
+ end
44
+ ##
45
+ # returns the hostname of the system
46
+ def hostname
47
+ return Socket.gethostname
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ module Informo
2
+ ##
3
+ # returns the version of this module
4
+ VERSION = '1.0'
5
+ end
data/test/test_bios.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/bios") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/bios' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class BiosTest < Test::Unit::TestCase
6
+
7
+ def test_version
8
+ b = Informo::Bios.new
9
+ assert_match /^\d/, b.version
10
+ end
11
+
12
+ def test_serial
13
+ b = Informo::Bios.new
14
+ assert_match /.+?/, b.serial
15
+ end
16
+
17
+ def test_vendor
18
+ b = Informo::Bios.new
19
+ assert_match /.+?/, b.vendor
20
+ end
21
+
22
+ def test_date
23
+ b = Informo::Bios.new
24
+ assert_match /\d+\/\d+\/\d+/, b.date
25
+ end
26
+
27
+ end
data/test/test_dpkg.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/dpkg") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/dpkg' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class DpkgTest < Test::Unit::TestCase
6
+ ##
7
+ # required package for test. this package is requried on every debian/ubuntu system
8
+ R_PKG = 'glibc'
9
+
10
+ def test_get_packages
11
+ dpkg = Informo::Dpkg.new
12
+ packages = dpkg.get_packages
13
+ assert_not_nil packages[0]
14
+ end
15
+
16
+ def test_get_version
17
+ dpkg = Informo::Dpkg.new
18
+ version = dpkg.get_version(R_PKG)
19
+ assert_match '/^\d/', version
20
+ end
21
+
22
+ def test_get_architecture
23
+ dpkg = Informo::Dpkg.new
24
+ arch = dpkg.get_architecture(R_PKG)
25
+ assert_match '/\w+(\d*)?/', arch
26
+ end
27
+
28
+ def test_get_maintainer
29
+ dpkg = Informo::Dpkg.new
30
+ maintainer = dpkg.get_maintainer(R_PKG)
31
+ assert_match '/\w+/', maintainer
32
+ end
33
+
34
+ def test_get_short_desc
35
+ dpkg = Informo::Dpkg.new
36
+ desc = dpkg.get_short_description(R_PKG)
37
+ assert_match '/\w+/', desc
38
+ end
39
+
40
+ def test_get_desc
41
+ dpkg = Informo::Dpkg.new
42
+ desc = dpkg.get_description(R_PKG)
43
+ assert_match '/\w+/', desc
44
+ end
45
+
46
+ def test_get_status
47
+ dpkg = Informo::Dpkg.new
48
+ status = dpkg.get_status(R_PKG)
49
+ assert_match 'ii', status
50
+ end
51
+
52
+ def test_get_installdate
53
+ dpkg = Informo::Dpkg.new
54
+ installdate = dpkg.get_installdate(R_PKG)
55
+ assert_match '/\d+/', installdate
56
+ end
57
+
58
+ def test_get_all
59
+ dpkg = Informo::Dpkg.new
60
+ pkg_details = dpkg.get_all(R_PKG)
61
+ assert_kind_of Hash, pkg_details
62
+ assert_match '/\w+/', pkg_details['name']
63
+ assert_match '/^\d/', pkg_details['version']
64
+ assert_match '/\w+(\d*)?/', pkg_details['achitecture']
65
+ assert_match '/\w+/', pkg_details['maintainer']
66
+ assert_match '/\w+/', pkg_details['description']
67
+ assert_match 'ii', pkg_details['status']
68
+ end
69
+
70
+ end
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/memory") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/memory' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class MemoryTest < Test::Unit::TestCase
6
+
7
+ def test_max_module_size
8
+ m = Informo::Memory.new
9
+ assert_match /\d+/, m.max_module_size
10
+ end
11
+
12
+ def test_max_modules
13
+ m = Informo::Memory.new
14
+ assert_match /\d+/, m.max_modules
15
+ end
16
+
17
+ def test_max_capacity
18
+ m = Informo::Memory.new
19
+ assert_match /\d+/, m.max_capacity
20
+ end
21
+
22
+ def test_installed
23
+ m = Informo::Memory.new
24
+ assert_match /\d+/, m.installed
25
+ end
26
+
27
+ def test_slots
28
+ m = Informo::Memory.new
29
+ assert_match /\d+/, m.slots[0]['speed']
30
+ end
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/network") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/network' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class NetworkTest < Test::Unit::TestCase
6
+
7
+ def test_interfaces
8
+ n = Informo::Network.new
9
+ interfaces = n.interfaces
10
+ assert_match /\w+\d+/, interfaces[0]
11
+ end
12
+
13
+ def test_inteface_details
14
+ n = Informo::Network.new
15
+ details = n.interface_details('lo')
16
+ assert_equal '127.0.0.1', details['addr']
17
+ end
18
+
19
+ def test_host_bus_adapters
20
+ n = Informo::Network.new
21
+ hbas = n.host_bus_adapters
22
+ assert_not_nil hbas
23
+ end
24
+
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/processor") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/processor' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class ProcessorTest < Test::Unit::TestCase
6
+
7
+ def test_count
8
+ p = Informo::Processor.new
9
+ assert_match /\d+/, p.count
10
+ end
11
+
12
+ def test_details
13
+ p = Informo::Processor.new
14
+ details = p.details
15
+ assert_match /\d+\.\d+/, details[0]['cpu_MHz']
16
+ end
17
+
18
+ end
data/test/test_rpm.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/processor") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/processor' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class RPMTest < Test::Unit::TestCase
6
+ ##
7
+ ## required package for test.
8
+ R_PKG = 'glibc'
9
+
10
+ def test_get_packages
11
+ rpm = Informo::Rpm.new
12
+ packages = rpm_obj.get_packages
13
+ assert_not_nil packages[0]
14
+ end
15
+
16
+ def test_get_version
17
+ rpm = Informo::Rpm.new
18
+ version = rpm.get_version(R_PKG)
19
+ assert_match '/^\d/', version
20
+ end
21
+
22
+ def test_get_architecture
23
+ rpm = Informo::Rpm.new
24
+ arch = rpm.get_architecture(R_PKG)
25
+ assert_match '/\w+(\d*)?/', arch
26
+ end
27
+
28
+ def test_get_maintainer
29
+ rpm = Informo::Rpm.new
30
+ maintainer = rpm.get_maintainer(R_PKG)
31
+ assert_match '/\w+/', maintainer
32
+ end
33
+
34
+ def test_get_short_desc
35
+ rpm = Informo::Rpm.new
36
+ desc = rpm.get_short_description(R_PKG)
37
+ assert_match '/\w+/', desc
38
+ end
39
+
40
+ def test_get_desc
41
+ rpm = Informo::Rpm.new
42
+ desc = rpm.get_description(R_PKG)
43
+ assert_match '/\w+/', desc
44
+ end
45
+
46
+ def test_get_status
47
+ rpm = Informo::Rpm.new
48
+ status = rpm.get_status(R_PKG)
49
+ assert_match 'ii', status
50
+ end
51
+
52
+ def test_get_installdate
53
+ rpm = Informo::Rpm.new
54
+ installdate = rpm.get_installdate(R_PKG)
55
+ assert_match '/\d+/', installdate
56
+ end
57
+
58
+ def test_get_all
59
+ rpm = Informo::Rpm.new
60
+ pkg_details = rpm.get_all(R_PKG)
61
+ assert_kind_of Hash, pkg_details
62
+ assert_match '/\w+/', pkg_details['name']
63
+ assert_match '/^\d/', pkg_details['version']
64
+ assert_match '/\w+(\d*)?/', pkg_details['achitecture']
65
+ assert_match '/\w+/', pkg_details['maintainer']
66
+ assert_match '/\w+/', pkg_details['description']
67
+ assert_match 'ii', pkg_details['status']
68
+ end
69
+
70
+ end
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/storage") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/storage' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class StorageTest < Test::Unit::TestCase
6
+
7
+ def test_drive_count
8
+ s = Informo::Storage.new
9
+ assert_kind_of Integer s.drive_count
10
+ end
11
+
12
+ def test_drive_details
13
+ s = Informo::Storage.new
14
+ drives = s.drives
15
+ assert_match /^\d/, s.drive_details(drives[0]['size'])
16
+ end
17
+
18
+ def test_mount_details
19
+ s = Informo::Storage.new
20
+ assert_not_nil s.mount_details('/')
21
+ end
22
+
23
+ def test_mounts
24
+ s = Informo::Storage.new
25
+ assert_not_nil s.mounts
26
+ end
27
+
28
+ end
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__),"../lib/informo/system") if RUBY_VERSION.to_f < 1.9
3
+ require 'informo/system' if RUBY_VERSION.to_f >= 1.9
4
+
5
+ class SystemTest < Test::Unit::TestCase
6
+
7
+ def test_distro
8
+ s = Informo::System.new
9
+ assert_not_nil s.distro
10
+ end
11
+
12
+ def test_version
13
+ s = Informo::System.new
14
+ assert_match /^\d/, s.version
15
+ end
16
+
17
+ def test_numa
18
+ s = Informo::System.new
19
+ assert_instance_of TrueClass s.numa?
20
+ end
21
+
22
+ def test_kernel
23
+ s = Informo::System.new
24
+ assert_not_nil s.kernel
25
+ end
26
+
27
+ def test_arch
28
+ s = Informo::System.new
29
+ assert_not_nil s.arch
30
+ end
31
+
32
+ def test_hostname
33
+ s = Informo::System.new
34
+ assert_not_nil s.hostname
35
+ end
36
+
37
+ end