Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dmytro/Uliska
base: 2e577a27b3
...
head fork: dmytro/Uliska
compare: 208519dd9d
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
5 parser/lib/uliska_parser.rb
@@ -97,7 +97,7 @@ def stage_1_parsers
end
private
-
+
# Process colon-separated (or anything-separated) file
# (/etc/passwd, groups etc) and return parsed data as array of
# hashes.
@@ -116,7 +116,8 @@ def colon_separated file, fields, delimiter=':'
arr = line.split(delimiter)
hsh={ }
fields.each do |a|
- hsh[a.to_sym] = arr.shift
+
+ hsh[a.to_sym] = arr.shift.to_num
end
hsh
}
View
4 parser/lib/uliska_parser/common_parsers/bsd_linux.rb
@@ -14,7 +14,8 @@ def mount_parser
# '/dev/sda1 on / type ext3 (rw,errors=remount-ro)'
# FreeBSD (Darwin including) does not have 'type' part
@raw.mount.each do |line|
- if line.strip =~ /^([^ ]+) on [^ ]+( type ([^ ]+) )?\((.*)\)$/
+
+ if line.strip =~ /^([^ ]+) on [^ ]+( type ([^ ]+))? \((.*)\)$/
fs_type = $3
out.push( { :filesystem => $1,
:mount_options => $4.split(/,\s*/),
@@ -22,7 +23,6 @@ def mount_parser
)
end
end
-
out
end
View
16 parser/lib/uliska_parser/extensions.rb
@@ -32,3 +32,19 @@ def merge_by array, column
end
end
+
+class Object
+
+ # Convert to one of integer, float etc depending on format. If it
+ # does not look like number, return self unmodified.
+ def to_num
+ if self.class != String
+ return self
+ end
+ case self
+ when /^-?\s*\d+$/ then self.to_i
+ when /^-?\s*\d+\.\d*$/ then self.to_f
+ else self
+ end
+ end
+end
View
13 parser/lib/uliska_parser/freebsd.rb
@@ -18,6 +18,19 @@ def parse_swap
:free => (total - fields.sum_by(:used).to_i) * block_size
}
end
+
+ include Uliska::Common::Bsd_Linux
+
+ def parse_filesystems
+ #
+ # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted on
+ # /dev/wd0a 806766 57518 708910 8% 2543 100367 2% /
+ fss = space_separated @raw.df[1..-1], %w{ filesystem fs_type blocks used available use iused ifree iuse mounted_on }
+ fss.map { |x| x[:inodes] = x[:iused] + x[:ifree]}
+ fss.merge_by(mount_parser, :filesystem)
+ fss
+ end
+
end
end
View
7 parser/lib/uliska_parser/generic.rb
@@ -15,7 +15,7 @@ def parse_uptime
return unless @raw.respond_to? :uptime
if @raw.uptime.strip =~ /^.*\s+up\s+(.*)\s*(\d+)\susers?,\s*load averages?:(.*)$/
- uptime, @data[:users], @data[:load_average] = $1, $2, $3.strip.split(/\s*,\s*/).map(&:to_f)
+ uptime, @data[:users], @data[:load_average] = $1, $2.to_i, $3.strip.split(/\s*,\s*/).map(&:to_f)
end
uptime.gsub(/[ ,]*$/,'')
end
@@ -47,6 +47,11 @@ def parse_kernel
@raw.kernel.inject({ }) { |memo,(k,v)| memo[k.to_sym] = v; memo}
end
+ # Just dmesg without any parsing
+ def parse_dmesg
+ @raw.dmesg
+ end
+
end
end
View
61 parser/spec/any_unix.rb
@@ -1,26 +1,77 @@
shared_examples_for "any unix" do
+ require 'ostruct'
context "any UNIX" do
let(:os) { Uliska::Parser.new("#{DATA_ROOT}/#{$data_file}")}
- before do
+ data = nil
+
+ before do
os.try_file(os.raw.uname_name).parse
+ data = OpenStruct.new os.data
end
it "should have hostname" do
- os.data[:hostname].should_not be_empty
+ data.hostname.should_not be_empty
+ end
+
+ it "hostname should be a String" do
+ data.hostname.should be_a_kind_of String
+ end
+
+ it "uptime should have load averages" do
+ data.load_average.should_not be_empty
end
+ it "load avarages should be 3 element array of Floats" do
+ data.load_average.should be_a_kind_of Array
+ data.load_average.count.should be 3
+ data.load_average.each do |num|
+ num.should be_a_kind_of Numeric
+ end
+ end
+
+ it "Logged in users should be a number" do # TODO
+ data.users.should be_a_kind_of Numeric
+ end
+ it "should have dmesg" do
+
+ data.dmesg.should_not be_empty
+ data.dmesg.should be_a_kind_of Array
+ data.dmesg.first.should be_a_kind_of String
+ end
+
+ it "should have /etc/group" do # TODO
+ data.local_groups.should_not be_empty
+ data.local_groups.should be_a_kind_of Array
+ end
+
+ it "group ID should be numeric" do
+ data.local_groups.first[:gid].should be_a_kind_of Fixnum
+ end
+
it "should have /etc/passwd" do
- os.data[:local_users].should_not be_empty
- os.data[:local_users].should be_a_kind_of Array
+ data.local_users.should_not be_empty
+ data.local_users.should be_a_kind_of Array
end
+# it "user ID in /etc/passwd should be nuneric" do
+# fail
+# end
+
+# it "root UID in /etc/passwd should be O" do
+# fail
+# end
+
+# it "user environment should not be empty" do # TODO
+# fail
+# end
+
it "should have root user" do
os.data[:local_users].find { |x| x[:name] == 'root'}.should_not be_empty
- end
+ end
it "kernel should have minor and major versions" do
kern = os.data[:kernel]
kern[:name].should be_a_kind_of String
View
4 parser/spec/filesystems.rb
@@ -36,9 +36,9 @@
end
end
- it "numeric fields should have proper format" do
+ it "numeric fields should be numeric" do
%w{ blocks used available inodes iused ifree }.each do |field|
- root_fs[field.to_sym].should match /^\d+$/
+ root_fs[field.to_sym].should be_a_kind_of Numeric
end
end
View
23 parser/spec/object_spec.rb
@@ -0,0 +1,23 @@
+$: << File.dirname(File.dirname(__FILE__)) + "/lib"
+require "uliska_parser/extensions"
+
+describe String do
+
+ it "should convert int" do
+ "123".to_num.should be_a_kind_of Fixnum
+ "1243".to_num.should be 1243
+ end
+
+ it "should convert neint" do
+ "- 1233".to_num.should be_a_kind_of Fixnum
+ "-1233".to_num.should be_a_kind_of Fixnum
+ "- 1233".to_num.should be_a_kind_of Fixnum
+ "-1".to_num.should be -1
+ end
+
+ it "should return self for not number" do
+ "qwerwqerr".to_num.should be_a_kind_of String
+ end
+
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.