Skip to content

Commit

Permalink
Merge pull request #705 from Icinga/enhancement/version_fact
Browse files Browse the repository at this point in the history
Add a fact to get the installed icinga2 version
  • Loading branch information
lbetz authored Dec 12, 2022
2 parents 94c96f3 + b772fac commit aae419e
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit aae419e

Please sign in to comment.