-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Facter.add(:splunk_version) do | ||
setcode do | ||
value = nil | ||
cmd = if File.exist?('C:/Program Files/Splunk/bin/splunk.exe') | ||
'"C:/Program Files/Splunk/bin/splunk.exe" --version' | ||
elsif File.exist?('/opt/splunk/bin/splunk') | ||
'/opt/splunk/bin/splunk --version' | ||
end | ||
if cmd | ||
output = Facter::Util::Resolution.exec(cmd) | ||
if output =~ %r{^Splunk ([0-9\.]+) \(} # rubocop:disable Style/IfUnlessModifier | ||
value = Regexp.last_match(1) | ||
end | ||
end | ||
value | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
describe 'splunk_version Fact' do | ||
before do | ||
Facter.clear | ||
end | ||
|
||
it 'returns version for Windows' do | ||
allow(File).to receive(:exist?).with('C:/Program Files/Splunk/bin/splunk.exe').and_return(true) | ||
allow(Facter::Util::Resolution).to receive(:exec).with('"C:/Program Files/Splunk/bin/splunk.exe" --version').and_return('Splunk 6.6.8 (build 6c27a8439c1e)') | ||
expect(Facter.fact(:splunk_version).value).to eq('6.6.8') | ||
end | ||
|
||
it 'returns version for Linux' do | ||
allow(File).to receive(:exist?).with('C:/Program Files/Splunk/bin/splunk.exe').and_return(false) | ||
allow(File).to receive(:exist?).with('/opt/splunk/bin/splunk').and_return(true) | ||
allow(Facter::Util::Resolution).to receive(:exec).with('/opt/splunk/bin/splunk --version').and_return('Splunk 6.6.8 (build 6c27a8439c1e)') | ||
expect(Facter.fact(:splunk_version).value).to eq('6.6.8') | ||
end | ||
|
||
it 'returns nil' do | ||
allow(File).to receive(:exist?).with('C:/Program Files/Splunk/bin/splunk.exe').and_return(false) | ||
allow(File).to receive(:exist?).with('/opt/splunk/bin/splunk').and_return(false) | ||
expect(Facter.fact(:splunk_version).value).to be_nil | ||
end | ||
end |