Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fact to get the installed icinga2 version #705

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/facter/icinga2_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Facter.add('icinga2_version') do
confine { Facter::Core::Execution.which('icinga2') }
confine kernel: 'linux'
setcode do
icinga2_ver = Facter::Core::Execution.execute("icinga2 -V|grep 'version: r'")
icinga2_ver.match(%r{\d+\.\d+\.\d+})[0] if icinga2_ver
end
end

Facter.add('icinga2_version') do
confine kernel: 'windows'
setcode do
tmp = Facter::Core::Execution.which('icinga2.exe')
file = if tmp
tmp
else
'C:/Program Files/ICINGA2/sbin/icinga2.exe'
end
cmd = "#{file.split(':').first}:\"#{file.split(':').last.tr('/', '\\')}\" -V 2>&1"
Facter::Core::Execution.execute("cmd /C #{cmd}").lines.grep(%r{version: (r|v)?\d+\.\d+\d+}).first.split(':').last.delete('vr)').strip if File.executable?(file)
end
end