From 41db3987827abfa9b69d3c8c2ca257c4e6c7e859 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Fri, 1 Jul 2022 19:05:18 +0200 Subject: [PATCH 1/2] add a fact to get the installed icinga2 version --- lib/facter/icinga2_version.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/facter/icinga2_version.rb diff --git a/lib/facter/icinga2_version.rb b/lib/facter/icinga2_version.rb new file mode 100644 index 000000000..a9593f907 --- /dev/null +++ b/lib/facter/icinga2_version.rb @@ -0,0 +1,7 @@ +Facter.add('icinga2_version') do + confine { Facter::Core::Execution.which('icinga2') } + 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 From b772facf46cc1ab3b9f7f0a9ae66456c68283948 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 5 Jul 2022 16:43:36 +0200 Subject: [PATCH 2/2] add icinga2_version fact for Windows --- lib/facter/icinga2_version.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/facter/icinga2_version.rb b/lib/facter/icinga2_version.rb index a9593f907..8bf072bcd 100644 --- a/lib/facter/icinga2_version.rb +++ b/lib/facter/icinga2_version.rb @@ -1,7 +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