Skip to content

Commit

Permalink
Merge pull request jhoblitt#20 from jhoblitt/feature/smartmon_facts
Browse files Browse the repository at this point in the history
Feature/smartmon facts
  • Loading branch information
Joshua Hoblitt committed Apr 14, 2014
2 parents 0950ccb + 60a2988 commit 365a6ab
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/facter/smartd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Facter.add(:smartd) do
setcode do
Facter::Util::Resolution.which('smartd')
end
end
12 changes: 12 additions & 0 deletions lib/facter/smartmontools_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Facter.add(:smartmontools_version) do
smartd = Facter.value(:smartd)
setcode do
unless smartd.nil?
output = Facter::Util::Resolution.exec("#{smartd} --version")
next if output.nil?
m = output.match(/smartmontools release ([\d\.]+)/)
next unless m.size == 2
m[1]
end
end
end
14 changes: 14 additions & 0 deletions spec/fixtures/smartd/version-smartmontools-5.42-2.el5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
smartd 5.42 2011-10-20 r3458 [x86_64-linux-2.6.18-348.6.1.el5] (local build)
Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

smartd comes with ABSOLUTELY NO WARRANTY. This is free
software, and you are welcome to redistribute it under
the terms of the GNU General Public License Version 2.
See http://www.gnu.org for further details.

smartmontools release 5.42 dated 2011-10-20 at 19:19:34 UTC
smartmontools SVN rev 3458 dated 2011-10-20 at 19:20:23
smartmontools build host: x86_64-redhat-linux-gnu
smartmontools build configured: 2013-01-09 08:24:57 UTC
smartd compile dated Jan 9 2013 at 03:25:25
smartmontools configure arguments: '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-selinux' '--without-systemdsystemunitdir' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu'
15 changes: 15 additions & 0 deletions spec/fixtures/smartd/version-smartmontools-5.43-1.el6.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-431.5.1.el6.x86_64] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

smartctl comes with ABSOLUTELY NO WARRANTY. This is free
software, and you are welcome to redistribute it under
the terms of the GNU General Public License; either
version 2, or (at your option) any later version.
See http://www.gnu.org for further details.

smartmontools release 5.43 dated 2012-06-30 at 14:03:01 UTC
smartmontools SVN rev 3573 dated 2012-06-30 at 14:03:55
smartmontools build host: x86_64-redhat-linux-gnu
smartmontools build configured: 2012-09-25 16:04:33 UTC
smartctl compile dated Sep 25 2012 at 12:04:43
smartmontools configure arguments: '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-selinux' '--with-libcap-ng=yes' '-with-systemdsystemunitdir=no' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' 'PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/share/pkgconfig'
20 changes: 20 additions & 0 deletions spec/unit/facts/smartd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe 'smartd', :type => :fact do
before(:each) { Facter.clear }

context 'not in path' do
it do
Facter::Util::Resolution.stubs(:which).with('smartd').returns(nil)
Facter.fact(:smartd).value.should be_nil
end
end

context 'in path' do
it do
Facter::Util::Resolution.stubs(:which).with('smartd').returns('/usr/sbin/smartd')
Facter.fact(:smartd).value.should == '/usr/sbin/smartd'
end
end
end

39 changes: 39 additions & 0 deletions spec/unit/facts/smartmontools_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'

describe 'smartmontools_version', :type => :fact do
before(:each) { Facter.clear }

context 'smartd fact not set' do
it 'should return nil' do
Facter.fact(:smartd).stubs(:value).returns(nil)
Facter.fact(:smartmontools_version).value.should be_nil
end
end

context 'smartd fact is broken' do
it 'should return nil' do
Facter.fact(:smartd).stubs(:value).returns('foobar')
Facter.fact(:smartmontools_version).value.should be_nil
end
end

context 'smartd fact is working' do
it 'should get the version string' do
Facter.fact(:smartd).stubs(:value).returns('/usr/sbin/smartd')
Facter::Util::Resolution.stubs(:exec).
with('/usr/sbin/smartd --version').
returns(File.read(fixtures('smartd', 'version-smartmontools-5.42-2.el5')))
Facter.fact(:smartmontools_version).value.should == '5.42'
end

it 'should get the version string' do
Facter.fact(:smartd).stubs(:value).returns('/usr/sbin/smartd')
Facter::Util::Resolution.stubs(:exec).
with('/usr/sbin/smartd --version').
returns(File.read(fixtures('smartd', 'version-smartmontools-5.43-1.el6.x86_64')))
Facter.fact(:smartmontools_version).value.should == '5.43'
end
end

end

0 comments on commit 365a6ab

Please sign in to comment.